mailbox 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/daemon_thread_factory.rb +9 -0
- data/lib/mailbox.rb +16 -4
- data/mailbox.gemspec +3 -2
- data/mailbox.ipr +12 -0
- data/test/mailbox_test.rb +21 -0
- metadata +4 -3
data/VERSION.yml
CHANGED
data/lib/mailbox.rb
CHANGED
@@ -11,6 +11,7 @@ require 'rubygems'
|
|
11
11
|
require 'jretlang'
|
12
12
|
|
13
13
|
require File.dirname(__FILE__) + '/synchronized'
|
14
|
+
require File.dirname(__FILE__) + '/daemon_thread_factory'
|
14
15
|
|
15
16
|
module Mailbox
|
16
17
|
include Synchronized
|
@@ -24,7 +25,7 @@ module Mailbox
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def verbose_output_to method_name
|
27
|
-
@
|
28
|
+
@__verbose_target__ = method_name
|
28
29
|
end
|
29
30
|
|
30
31
|
class << self
|
@@ -33,6 +34,7 @@ module Mailbox
|
|
33
34
|
#
|
34
35
|
# <b>*** Intended for synchronous unit testing of concurrent apps***</b>
|
35
36
|
attr_accessor :synchronous
|
37
|
+
|
36
38
|
end
|
37
39
|
|
38
40
|
private
|
@@ -54,10 +56,11 @@ module Mailbox
|
|
54
56
|
|
55
57
|
def __synchronous_fiber__
|
56
58
|
executor = JRL::SynchronousDisposingExecutor.new
|
57
|
-
|
59
|
+
JRL::Fibers::ThreadFiber.new executor, "#{self.class.name} #{self.object_id} Mailbox synchronous", true
|
58
60
|
end
|
59
61
|
|
60
62
|
def __create_fiber__
|
63
|
+
return self.class.__fiber_factory__.create if self.class.__fiber_factory__
|
61
64
|
JRL::Fibers::ThreadFiber.new( JRL::RunnableExecutorImpl.new, "#{self.class.name} #{self.object_id} Mailbox", true )
|
62
65
|
end
|
63
66
|
|
@@ -90,8 +93,17 @@ module Mailbox
|
|
90
93
|
@replyable = params[:replyable]
|
91
94
|
@timeout = params[:timeout].nil? ? -1 : params[:timeout] * 1000
|
92
95
|
@exception = params[:exception]
|
96
|
+
|
93
97
|
@mailslot = true
|
94
98
|
end
|
99
|
+
|
100
|
+
def mailbox_thread_pool_size(count)
|
101
|
+
@__fiber_factory__ = JRL::Fibers::PoolFiberFactory.new(JRL::Concurrent::Executors.new_fixed_thread_pool(count, DaemonThreadFactory.new))
|
102
|
+
end
|
103
|
+
|
104
|
+
def __fiber_factory__
|
105
|
+
@__fiber_factory__ ||= nil
|
106
|
+
end
|
95
107
|
|
96
108
|
private
|
97
109
|
|
@@ -118,14 +130,14 @@ module Mailbox
|
|
118
130
|
exception_method, @exception = @exception, nil
|
119
131
|
define_method method_name do |*args|
|
120
132
|
|
121
|
-
self.send(@
|
133
|
+
self.send(@__verbose_target__, "enqueued #{method_name}") if defined? @__verbose_target__
|
122
134
|
|
123
135
|
result = nil
|
124
136
|
latch = JRL::Concurrent::CountDownLatch.new(1) if replyable
|
125
137
|
|
126
138
|
__fiber__.execute do
|
127
139
|
begin
|
128
|
-
self.send(@
|
140
|
+
self.send(@__verbose_target__, "dequeued #{method_name}") if defined? @__verbose_target__
|
129
141
|
result = self.send(:"__#{method_name}__", *args )
|
130
142
|
rescue Exception => ex
|
131
143
|
raise if exception_method.nil?
|
data/mailbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mailbox}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joel Friedman", "Patrick Farley"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-29}
|
13
13
|
s.description = %q{Mailbox is a JRuby module that simplifies concurrency and is backed by JVM threads.}
|
14
14
|
s.email = %q{asher.friedman@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"example/log_example.rb",
|
26
26
|
"example/parallel_each_example.rb",
|
27
27
|
"example/ping_pong_example.rb",
|
28
|
+
"lib/daemon_thread_factory.rb",
|
28
29
|
"lib/mailbox.rb",
|
29
30
|
"lib/synchronized.rb",
|
30
31
|
"mailbox.gemspec",
|
data/mailbox.ipr
CHANGED
@@ -38,6 +38,18 @@
|
|
38
38
|
</component>
|
39
39
|
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
40
40
|
<component name="IdProvider" IDEtalkID="2A4BC5ABDEB6DBFA33020D902AA1570C" />
|
41
|
+
<component name="InspectionProjectProfileManager">
|
42
|
+
<profiles>
|
43
|
+
<profile version="1.0" is_locked="false">
|
44
|
+
<option name="myName" value="Project Default" />
|
45
|
+
<option name="myLocal" value="false" />
|
46
|
+
<inspection_tool class="RubyArgCount" enabled="false" level="ERROR" enabled_by_default="false" />
|
47
|
+
</profile>
|
48
|
+
</profiles>
|
49
|
+
<option name="PROJECT_PROFILE" value="Project Default" />
|
50
|
+
<option name="USE_PROJECT_PROFILE" value="true" />
|
51
|
+
<version value="1.0" />
|
52
|
+
</component>
|
41
53
|
<component name="JavadocGenerationManager">
|
42
54
|
<option name="OUTPUT_DIRECTORY" />
|
43
55
|
<option name="OPTION_SCOPE" value="protected" />
|
data/test/mailbox_test.rb
CHANGED
@@ -22,6 +22,27 @@ class MailboxTest < Test::Unit::TestCase
|
|
22
22
|
assert_not_equal JThread.current_thread.name, thread_info[:name]
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_mailslot_supports_threadpool_based_fibers
|
26
|
+
klass = Class.new do
|
27
|
+
include Mailbox
|
28
|
+
mailbox_thread_pool_size 2
|
29
|
+
|
30
|
+
|
31
|
+
mailslot
|
32
|
+
def test_method(latch, thread_info)
|
33
|
+
thread_info[:name] = JThread.current_thread.name
|
34
|
+
latch.count_down
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
thread_info = {}
|
39
|
+
latch = Latches::CountDownLatch.new( 1 )
|
40
|
+
klass.new.test_method(latch, thread_info)
|
41
|
+
|
42
|
+
assert( latch.await( 1, Latches::TimeUnit::SECONDS ), "Timed out" )
|
43
|
+
assert_not_equal JThread.current_thread.name, thread_info[:name]
|
44
|
+
end
|
45
|
+
|
25
46
|
def test_can_set_mailslot_to_callback_on_exception
|
26
47
|
klass = Class.new do
|
27
48
|
include Mailbox
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joel Friedman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-29 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- example/log_example.rb
|
61
61
|
- example/parallel_each_example.rb
|
62
62
|
- example/ping_pong_example.rb
|
63
|
+
- lib/daemon_thread_factory.rb
|
63
64
|
- lib/mailbox.rb
|
64
65
|
- lib/synchronized.rb
|
65
66
|
- mailbox.gemspec
|