celluloid 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of celluloid might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGES.md +333 -0
- data/README.md +1 -1
- data/culture/CODE_OF_CONDUCT.md +28 -0
- data/culture/Gemfile +9 -0
- data/culture/README.md +22 -0
- data/culture/Rakefile +5 -0
- data/culture/SYNC.md +70 -0
- data/culture/celluloid-culture.gemspec +18 -0
- data/culture/gems/README.md +39 -0
- data/culture/gems/dependencies.yml +78 -0
- data/culture/gems/loader.rb +101 -0
- data/culture/rubocop/README.md +38 -0
- data/culture/rubocop/lint.yml +8 -0
- data/culture/rubocop/metrics.yml +15 -0
- data/culture/rubocop/rubocop.yml +4 -0
- data/culture/rubocop/style.yml +48 -0
- data/culture/spec/gems_spec.rb +2 -0
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +2 -0
- data/culture/sync.rb +56 -0
- data/culture/tasks/rspec.rake +5 -0
- data/culture/tasks/rubocop.rake +2 -0
- data/examples/basic_usage.rb +49 -0
- data/examples/futures.rb +38 -0
- data/examples/ring.rb +61 -0
- data/examples/simple_pmap.rb +14 -0
- data/examples/timers.rb +72 -0
- data/lib/celluloid.rb +142 -127
- data/lib/celluloid/actor.rb +47 -41
- data/lib/celluloid/actor_system.rb +75 -22
- data/lib/celluloid/autostart.rb +1 -1
- data/lib/celluloid/backported.rb +2 -0
- data/lib/celluloid/call/async.rb +16 -0
- data/lib/celluloid/call/block.rb +22 -0
- data/lib/celluloid/call/sync.rb +70 -0
- data/lib/celluloid/calls.rb +25 -114
- data/lib/celluloid/cell.rb +32 -20
- data/lib/celluloid/condition.rb +3 -3
- data/lib/celluloid/core_ext.rb +1 -1
- data/lib/celluloid/current.rb +2 -0
- data/lib/celluloid/deprecate.rb +18 -0
- data/lib/celluloid/exceptions.rb +1 -1
- data/lib/celluloid/fiber.rb +3 -3
- data/lib/celluloid/future.rb +7 -6
- data/lib/celluloid/group.rb +65 -0
- data/lib/celluloid/group/manager.rb +27 -0
- data/lib/celluloid/group/pool.rb +125 -0
- data/lib/celluloid/group/spawner.rb +71 -0
- data/lib/celluloid/logging.rb +5 -5
- data/lib/celluloid/mailbox.rb +14 -13
- data/lib/celluloid/mailbox/evented.rb +76 -0
- data/lib/celluloid/notices.rb +15 -0
- data/lib/celluloid/proxies.rb +12 -0
- data/lib/celluloid/proxy/abstract.rb +24 -0
- data/lib/celluloid/proxy/actor.rb +46 -0
- data/lib/celluloid/proxy/async.rb +36 -0
- data/lib/celluloid/proxy/block.rb +31 -0
- data/lib/celluloid/proxy/cell.rb +76 -0
- data/lib/celluloid/proxy/future.rb +40 -0
- data/lib/celluloid/proxy/sync.rb +44 -0
- data/lib/celluloid/rspec.rb +9 -10
- data/lib/celluloid/system_events.rb +16 -15
- data/lib/celluloid/{tasks.rb → task.rb} +21 -21
- data/lib/celluloid/task/fibered.rb +45 -0
- data/lib/celluloid/task/threaded.rb +59 -0
- data/lib/celluloid/test.rb +1 -1
- data/lib/celluloid/thread.rb +6 -1
- data/lib/celluloid/version.rb +3 -0
- data/spec/celluloid/actor_spec.rb +2 -2
- data/spec/celluloid/actor_system_spec.rb +35 -21
- data/spec/celluloid/block_spec.rb +3 -5
- data/spec/celluloid/calls_spec.rb +33 -11
- data/spec/celluloid/condition_spec.rb +16 -13
- data/spec/celluloid/evented_mailbox_spec.rb +1 -31
- data/spec/celluloid/future_spec.rb +13 -10
- data/spec/celluloid/group/elastic_spec.rb +0 -0
- data/spec/celluloid/group/manager_spec.rb +0 -0
- data/spec/celluloid/group/pool_spec.rb +8 -0
- data/spec/celluloid/group/spawner_spec.rb +8 -0
- data/spec/celluloid/mailbox/evented_spec.rb +27 -0
- data/spec/celluloid/mailbox_spec.rb +1 -3
- data/spec/celluloid/misc/leak_spec.rb +73 -0
- data/spec/celluloid/task/fibered_spec.rb +5 -0
- data/spec/celluloid/task/threaded_spec.rb +5 -0
- data/spec/celluloid/timer_spec.rb +14 -16
- data/spec/deprecate/actor_system_spec.rb +72 -0
- data/spec/deprecate/block_spec.rb +52 -0
- data/spec/deprecate/calls_spec.rb +57 -0
- data/spec/deprecate/evented_mailbox_spec.rb +34 -0
- data/spec/deprecate/future_spec.rb +32 -0
- data/spec/deprecate/internal_pool_spec.rb +4 -0
- data/spec/shared/actor_examples.rb +1237 -0
- data/spec/shared/group_examples.rb +121 -0
- data/{lib/celluloid/rspec → spec/shared}/mailbox_examples.rb +20 -17
- data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
- data/spec/spec_helper.rb +72 -16
- data/spec/support/coverage.rb +4 -0
- data/spec/support/crash_checking.rb +68 -0
- data/spec/support/debugging.rb +31 -0
- data/spec/support/env.rb +16 -0
- data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
- data/spec/support/examples/evented_mailbox_class.rb +27 -0
- data/spec/support/includer.rb +9 -0
- data/spec/support/logging.rb +63 -0
- data/spec/support/loose_threads.rb +65 -0
- data/spec/support/reset_class_variables.rb +27 -0
- data/spec/support/sleep_and_wait.rb +14 -0
- data/spec/support/split_logs.rb +1 -0
- data/spec/support/stubbing.rb +14 -0
- metadata +255 -95
- data/lib/celluloid/call_chain.rb +0 -13
- data/lib/celluloid/cpu_counter.rb +0 -34
- data/lib/celluloid/evented_mailbox.rb +0 -73
- data/lib/celluloid/fsm.rb +0 -186
- data/lib/celluloid/handlers.rb +0 -41
- data/lib/celluloid/internal_pool.rb +0 -159
- data/lib/celluloid/legacy.rb +0 -9
- data/lib/celluloid/links.rb +0 -36
- data/lib/celluloid/logger.rb +0 -93
- data/lib/celluloid/logging/incident.rb +0 -21
- data/lib/celluloid/logging/incident_logger.rb +0 -129
- data/lib/celluloid/logging/incident_reporter.rb +0 -48
- data/lib/celluloid/logging/log_event.rb +0 -20
- data/lib/celluloid/logging/ring_buffer.rb +0 -65
- data/lib/celluloid/method.rb +0 -32
- data/lib/celluloid/notifications.rb +0 -83
- data/lib/celluloid/pool_manager.rb +0 -146
- data/lib/celluloid/probe.rb +0 -73
- data/lib/celluloid/properties.rb +0 -24
- data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
- data/lib/celluloid/proxies/actor_proxy.rb +0 -38
- data/lib/celluloid/proxies/async_proxy.rb +0 -31
- data/lib/celluloid/proxies/block_proxy.rb +0 -29
- data/lib/celluloid/proxies/cell_proxy.rb +0 -68
- data/lib/celluloid/proxies/future_proxy.rb +0 -35
- data/lib/celluloid/proxies/sync_proxy.rb +0 -36
- data/lib/celluloid/receivers.rb +0 -63
- data/lib/celluloid/registry.rb +0 -57
- data/lib/celluloid/responses.rb +0 -44
- data/lib/celluloid/rspec/actor_examples.rb +0 -1054
- data/lib/celluloid/signals.rb +0 -23
- data/lib/celluloid/stack_dump.rb +0 -133
- data/lib/celluloid/supervision_group.rb +0 -169
- data/lib/celluloid/supervisor.rb +0 -22
- data/lib/celluloid/task_set.rb +0 -49
- data/lib/celluloid/tasks/task_fiber.rb +0 -43
- data/lib/celluloid/tasks/task_thread.rb +0 -53
- data/lib/celluloid/thread_handle.rb +0 -50
- data/lib/celluloid/uuid.rb +0 -38
- data/spec/celluloid/cpu_counter_spec.rb +0 -82
- data/spec/celluloid/fsm_spec.rb +0 -107
- data/spec/celluloid/internal_pool_spec.rb +0 -52
- data/spec/celluloid/links_spec.rb +0 -45
- data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
- data/spec/celluloid/notifications_spec.rb +0 -120
- data/spec/celluloid/pool_spec.rb +0 -92
- data/spec/celluloid/probe_spec.rb +0 -121
- data/spec/celluloid/properties_spec.rb +0 -42
- data/spec/celluloid/registry_spec.rb +0 -64
- data/spec/celluloid/stack_dump_spec.rb +0 -64
- data/spec/celluloid/supervision_group_spec.rb +0 -65
- data/spec/celluloid/supervisor_spec.rb +0 -103
- data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
- data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
- data/spec/celluloid/thread_handle_spec.rb +0 -26
- data/spec/celluloid/uuid_spec.rb +0 -11
data/lib/celluloid/actor.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require
|
2
|
+
require "timers"
|
3
3
|
|
4
4
|
module Celluloid
|
5
5
|
# Actors are Celluloid's concurrency primitive. They're implemented as
|
@@ -12,37 +12,37 @@ module Celluloid
|
|
12
12
|
class << self
|
13
13
|
extend Forwardable
|
14
14
|
|
15
|
-
def_delegators "Celluloid.actor_system", :[], :[]=, :delete, :registered, :clear_registry
|
15
|
+
def_delegators :"Celluloid.actor_system", :[], :[]=, :delete, :registered, :clear_registry
|
16
16
|
|
17
17
|
# Obtain the current actor
|
18
18
|
def current
|
19
19
|
actor = Thread.current[:celluloid_actor]
|
20
|
-
|
20
|
+
fail NotActorError, "not in actor scope" unless actor
|
21
21
|
actor.behavior_proxy
|
22
22
|
end
|
23
23
|
|
24
24
|
# Obtain the name of the current actor
|
25
25
|
def registered_name
|
26
26
|
actor = Thread.current[:celluloid_actor]
|
27
|
-
|
27
|
+
fail NotActorError, "not in actor scope" unless actor
|
28
28
|
actor.name
|
29
29
|
end
|
30
30
|
|
31
31
|
# Invoke a method on the given actor via its mailbox
|
32
32
|
def call(mailbox, meth, *args, &block)
|
33
|
-
proxy =
|
33
|
+
proxy = Proxy::Sync.new(mailbox, "UnknownClass")
|
34
34
|
proxy.method_missing(meth, *args, &block)
|
35
35
|
end
|
36
36
|
|
37
37
|
# Invoke a method asynchronously on an actor via its mailbox
|
38
38
|
def async(mailbox, meth, *args, &block)
|
39
|
-
proxy =
|
39
|
+
proxy = Proxy::Async.new(mailbox, "UnknownClass")
|
40
40
|
proxy.method_missing(meth, *args, &block)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Call a method asynchronously and retrieve its value later
|
44
44
|
def future(mailbox, meth, *args, &block)
|
45
|
-
proxy =
|
45
|
+
proxy = Proxy::Future.new(mailbox, "UnknownClass")
|
46
46
|
proxy.method_missing(meth, *args, &block)
|
47
47
|
end
|
48
48
|
|
@@ -53,13 +53,13 @@ module Celluloid
|
|
53
53
|
|
54
54
|
# Watch for exit events from another actor
|
55
55
|
def monitor(actor)
|
56
|
-
|
56
|
+
fail NotActorError, "can't link outside actor context" unless Celluloid.actor?
|
57
57
|
Thread.current[:celluloid_actor].linking_request(actor, :link)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Stop waiting for exit events from another actor
|
61
61
|
def unmonitor(actor)
|
62
|
-
|
62
|
+
fail NotActorError, "can't link outside actor context" unless Celluloid.actor?
|
63
63
|
Thread.current[:celluloid_actor].linking_request(actor, :unlink)
|
64
64
|
end
|
65
65
|
|
@@ -85,10 +85,12 @@ module Celluloid
|
|
85
85
|
monitoring?(actor) && Thread.current[:celluloid_actor].links.include?(actor)
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
actor
|
91
|
-
|
88
|
+
unless RUBY_PLATFORM == "java" || RUBY_ENGINE == "rbx"
|
89
|
+
# Forcibly kill a given actor
|
90
|
+
def kill(actor)
|
91
|
+
actor.thread.kill
|
92
|
+
actor.mailbox.shutdown if actor.mailbox.alive?
|
93
|
+
end
|
92
94
|
end
|
93
95
|
|
94
96
|
# Wait for an actor to terminate
|
@@ -109,12 +111,12 @@ module Celluloid
|
|
109
111
|
@exit_handler = method(:default_exit_handler)
|
110
112
|
@exclusive = options.fetch(:exclusive, false)
|
111
113
|
|
112
|
-
@tasks = TaskSet.new
|
113
|
-
@links = Links.new
|
114
|
-
@signals = Signals.new
|
115
114
|
@timers = Timers::Group.new
|
116
|
-
@
|
117
|
-
@
|
115
|
+
@tasks = Internals::TaskSet.new
|
116
|
+
@links = Internals::Links.new
|
117
|
+
@handlers = Internals::Handlers.new
|
118
|
+
@receivers = Internals::Receivers.new(@timers)
|
119
|
+
@signals = Internals::Signals.new
|
118
120
|
@running = false
|
119
121
|
@name = nil
|
120
122
|
|
@@ -125,12 +127,12 @@ module Celluloid
|
|
125
127
|
|
126
128
|
def start
|
127
129
|
@running = true
|
128
|
-
@thread = ThreadHandle.new(@actor_system, :actor) do
|
130
|
+
@thread = Internals::ThreadHandle.new(@actor_system, :actor) do
|
129
131
|
setup_thread
|
130
132
|
run
|
131
133
|
end
|
132
134
|
|
133
|
-
@proxy =
|
135
|
+
@proxy = Proxy::Actor.new(@thread, @mailbox)
|
134
136
|
Celluloid::Probe.actor_created(self) if $CELLULOID_MONITORING
|
135
137
|
end
|
136
138
|
|
@@ -148,8 +150,8 @@ module Celluloid
|
|
148
150
|
while @running
|
149
151
|
begin
|
150
152
|
@timers.wait do |interval|
|
151
|
-
interval = 0 if interval
|
152
|
-
|
153
|
+
interval = 0 if interval && interval < 0
|
154
|
+
|
153
155
|
if message = @mailbox.check(interval)
|
154
156
|
handle_message(message)
|
155
157
|
|
@@ -158,6 +160,9 @@ module Celluloid
|
|
158
160
|
end
|
159
161
|
rescue MailboxShutdown
|
160
162
|
@running = false
|
163
|
+
rescue MailboxDead
|
164
|
+
# TODO: not tests (but fails occasionally in tests)
|
165
|
+
@running = false
|
161
166
|
end
|
162
167
|
end
|
163
168
|
|
@@ -191,19 +196,16 @@ module Celluloid
|
|
191
196
|
|
192
197
|
if message.instance_of? LinkingResponse
|
193
198
|
Celluloid::Probe.actors_linked(self, receiver) if $CELLULOID_MONITORING
|
194
|
-
|
195
|
-
# We're done!
|
196
199
|
system_events.each { |ev| @mailbox << ev }
|
197
|
-
|
198
200
|
return
|
199
201
|
elsif message.is_a? SystemEvent
|
200
202
|
# Queue up pending system events to be processed after we've successfully linked
|
201
203
|
system_events << message
|
202
|
-
else
|
204
|
+
else fail "Unexpected message type: #{message.class}. Expected LinkingResponse, NilClass, SystemEvent."
|
203
205
|
end
|
204
206
|
end
|
205
207
|
|
206
|
-
|
208
|
+
fail TimeoutError, "linking timeout of #{LINKING_TIMEOUT} seconds exceeded with receiver: #{receiver}"
|
207
209
|
end
|
208
210
|
end
|
209
211
|
|
@@ -223,9 +225,9 @@ module Celluloid
|
|
223
225
|
|
224
226
|
# Receive an asynchronous message
|
225
227
|
def receive(timeout = nil, &block)
|
226
|
-
|
228
|
+
while true
|
227
229
|
message = @receivers.receive(timeout, &block)
|
228
|
-
|
230
|
+
return message unless message.is_a?(SystemEvent)
|
229
231
|
|
230
232
|
handle_system_event(message)
|
231
233
|
end
|
@@ -279,7 +281,7 @@ module Celluloid
|
|
279
281
|
def handle_message(message)
|
280
282
|
unless @handlers.handle_message(message)
|
281
283
|
unless @receivers.handle_message(message)
|
282
|
-
Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
|
284
|
+
Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
|
283
285
|
end
|
284
286
|
end
|
285
287
|
message
|
@@ -299,7 +301,7 @@ module Celluloid
|
|
299
301
|
elsif event.instance_of? SignalConditionRequest
|
300
302
|
event.call
|
301
303
|
else
|
302
|
-
Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
|
304
|
+
Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
|
303
305
|
end
|
304
306
|
end
|
305
307
|
|
@@ -311,16 +313,16 @@ module Celluloid
|
|
311
313
|
end
|
312
314
|
|
313
315
|
def default_exit_handler(event)
|
314
|
-
|
316
|
+
fail event.reason if event.reason
|
315
317
|
end
|
316
318
|
|
317
319
|
# Handle any exceptions that occur within a running actor
|
318
320
|
def handle_crash(exception)
|
319
321
|
# TODO: add meta info
|
320
|
-
Logger.crash("Actor crashed!", exception)
|
322
|
+
Internals::Logger.crash("Actor crashed!", exception)
|
321
323
|
shutdown ExitEvent.new(behavior_proxy, exception)
|
322
324
|
rescue => ex
|
323
|
-
Logger.crash("
|
325
|
+
Internals::Logger.crash("Actor#handle_crash CRASHED!", ex)
|
324
326
|
end
|
325
327
|
|
326
328
|
# Handle cleaning up this actor after it exits
|
@@ -337,26 +339,30 @@ module Celluloid
|
|
337
339
|
Celluloid::Probe.actor_died(self) if $CELLULOID_MONITORING
|
338
340
|
@mailbox.shutdown
|
339
341
|
@links.each do |actor|
|
340
|
-
if actor.mailbox.alive?
|
341
|
-
actor.mailbox << exit_event
|
342
|
-
end
|
342
|
+
actor.mailbox << exit_event if actor.mailbox.alive?
|
343
343
|
end
|
344
344
|
|
345
|
-
tasks.to_a.each
|
345
|
+
tasks.to_a.each do |task|
|
346
|
+
begin
|
347
|
+
task.terminate
|
348
|
+
rescue DeadTaskError
|
349
|
+
# TODO: not tested (failed on Travis)
|
350
|
+
end
|
351
|
+
end
|
346
352
|
rescue => ex
|
347
353
|
# TODO: metadata
|
348
|
-
Logger.crash("CLEANUP CRASHED!", ex)
|
354
|
+
Internals::Logger.crash("CLEANUP CRASHED!", ex)
|
349
355
|
end
|
350
356
|
|
351
357
|
# Run a method inside a task unless it's exclusive
|
352
358
|
def task(task_type, meta = nil)
|
353
|
-
@task_class.new(task_type, meta)
|
359
|
+
@task_class.new(task_type, meta) do
|
354
360
|
if @exclusive
|
355
361
|
Celluloid.exclusive { yield }
|
356
362
|
else
|
357
363
|
yield
|
358
364
|
end
|
359
|
-
|
365
|
+
end.resume
|
360
366
|
end
|
361
367
|
end
|
362
368
|
end
|
@@ -1,19 +1,63 @@
|
|
1
1
|
module Celluloid
|
2
|
+
extend Forwardable
|
3
|
+
def_delegators :actor_system, :[], :[]=
|
4
|
+
|
2
5
|
class ActorSystem
|
3
6
|
extend Forwardable
|
7
|
+
def_delegators :@registry, :[], :get, :[]=, :set, :delete
|
8
|
+
|
9
|
+
ROOT_SERVICES = [
|
10
|
+
{
|
11
|
+
as: :notifications_fanout,
|
12
|
+
type: Celluloid::Notifications::Fanout,
|
13
|
+
},
|
14
|
+
{
|
15
|
+
as: :incident_reporter,
|
16
|
+
type: Celluloid::IncidentReporter,
|
17
|
+
args: [STDERR],
|
18
|
+
},
|
19
|
+
{
|
20
|
+
as: :group_manager,
|
21
|
+
type: Celluloid::Group::Manager,
|
22
|
+
accessors: [:manager],
|
23
|
+
},
|
24
|
+
{
|
25
|
+
as: :public_services,
|
26
|
+
type: Celluloid::Supervision::Service::Public,
|
27
|
+
accessors: [:services],
|
28
|
+
supervise: [],
|
29
|
+
},
|
30
|
+
]
|
31
|
+
|
32
|
+
attr_reader :registry, :group
|
33
|
+
|
34
|
+
module Error
|
35
|
+
class Uninitialized < StandardError; end
|
36
|
+
end
|
37
|
+
|
38
|
+
# the root of the supervisor tree is established at supervision/root
|
39
|
+
|
40
|
+
def root_services
|
41
|
+
@tree
|
42
|
+
end
|
43
|
+
|
44
|
+
def root_configuration
|
45
|
+
@root
|
46
|
+
end
|
4
47
|
|
5
48
|
def initialize
|
6
|
-
@
|
7
|
-
@
|
49
|
+
@tree = nil
|
50
|
+
@group = Celluloid.group_class.new
|
51
|
+
@registry = Internals::Registry.new
|
52
|
+
@root = ROOT_SERVICES
|
8
53
|
end
|
9
|
-
attr_reader :registry
|
10
54
|
|
11
55
|
# Launch default services
|
12
|
-
# FIXME: We should set up the supervision hierarchy here
|
13
56
|
def start
|
14
57
|
within do
|
15
|
-
|
16
|
-
|
58
|
+
@root = Supervision::Service::Root.define
|
59
|
+
@tree = root_configuration.deploy
|
60
|
+
# de root_services[:group_manager].manage! @group
|
17
61
|
end
|
18
62
|
true
|
19
63
|
end
|
@@ -27,17 +71,19 @@ module Celluloid
|
|
27
71
|
end
|
28
72
|
|
29
73
|
def get_thread
|
30
|
-
@
|
74
|
+
@group.get do
|
31
75
|
Thread.current[:celluloid_actor_system] = self
|
32
76
|
yield
|
33
77
|
end
|
34
78
|
end
|
35
79
|
|
36
80
|
def stack_dump
|
37
|
-
|
81
|
+
Internals::Stack::Dump.new(@group)
|
38
82
|
end
|
39
83
|
|
40
|
-
|
84
|
+
def stack_summary
|
85
|
+
Internals::Stack::Summary.new(@group)
|
86
|
+
end
|
41
87
|
|
42
88
|
def registered
|
43
89
|
@registry.names
|
@@ -49,22 +95,29 @@ module Celluloid
|
|
49
95
|
|
50
96
|
def running
|
51
97
|
actors = []
|
52
|
-
@
|
98
|
+
@group.each do |t|
|
53
99
|
next unless t.role == :actor
|
54
|
-
|
100
|
+
actor = t.actor
|
101
|
+
|
102
|
+
# NOTE - these are in separate statements, since on JRuby t.actor may
|
103
|
+
# become nil befor .behavior_proxy() is called
|
104
|
+
next unless actor
|
105
|
+
next unless actor.respond_to?(:behavior_proxy)
|
106
|
+
proxy = actor.behavior_proxy
|
107
|
+
actors << proxy
|
55
108
|
end
|
56
109
|
actors
|
57
110
|
end
|
58
111
|
|
59
112
|
def running?
|
60
|
-
@
|
113
|
+
@group.active?
|
61
114
|
end
|
62
115
|
|
63
116
|
# Shut down all running actors
|
64
117
|
def shutdown
|
65
118
|
actors = running
|
66
119
|
Timeout.timeout(shutdown_timeout) do
|
67
|
-
Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0
|
120
|
+
Internals::Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0
|
68
121
|
|
69
122
|
# Actors cannot self-terminate, you must do it for them
|
70
123
|
actors.each do |actor|
|
@@ -80,24 +133,24 @@ module Celluloid
|
|
80
133
|
rescue DeadActorError
|
81
134
|
end
|
82
135
|
end
|
83
|
-
|
84
|
-
@internal_pool.shutdown
|
85
136
|
end
|
86
137
|
rescue Timeout::Error
|
87
|
-
Logger.error("Couldn't cleanly terminate all actors in #{shutdown_timeout} seconds!")
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
138
|
+
Internals::Logger.error("Couldn't cleanly terminate all actors in #{shutdown_timeout} seconds!")
|
139
|
+
unless RUBY_PLATFORM == "java" || RUBY_ENGINE == "rbx"
|
140
|
+
actors.each do |actor|
|
141
|
+
begin
|
142
|
+
Actor.kill(actor)
|
143
|
+
rescue DeadActorError, MailboxDead
|
144
|
+
end
|
92
145
|
end
|
93
146
|
end
|
94
147
|
ensure
|
95
|
-
@
|
148
|
+
@group.shutdown
|
96
149
|
clear_registry
|
97
150
|
end
|
98
151
|
|
99
152
|
def assert_inactive
|
100
|
-
@
|
153
|
+
@group.assert_inactive
|
101
154
|
end
|
102
155
|
|
103
156
|
def shutdown_timeout
|
data/lib/celluloid/autostart.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Celluloid
|
2
|
+
class Call
|
3
|
+
# Asynchronous calls don't wait for a response
|
4
|
+
class Async < Call
|
5
|
+
def dispatch(obj)
|
6
|
+
Internals::CallChain.current_id = Celluloid.uuid
|
7
|
+
super(obj)
|
8
|
+
rescue AbortError => ex
|
9
|
+
# Swallow aborted async calls, as they indicate the sender made a mistake
|
10
|
+
Internals::Logger.debug("#{obj.class}: async call `#{@method}` aborted!\n#{Internals::Logger.format_exception(ex.cause)}")
|
11
|
+
ensure
|
12
|
+
Internals::CallChain.current_id = nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Celluloid
|
2
|
+
class Call
|
3
|
+
class Block
|
4
|
+
def initialize(block_proxy, sender, arguments, task = Thread.current[:celluloid_task])
|
5
|
+
@block_proxy = block_proxy
|
6
|
+
@sender = sender
|
7
|
+
@arguments = arguments
|
8
|
+
@task = task
|
9
|
+
end
|
10
|
+
attr_reader :task
|
11
|
+
|
12
|
+
def call
|
13
|
+
@block_proxy.call
|
14
|
+
end
|
15
|
+
|
16
|
+
def dispatch
|
17
|
+
response = @block_proxy.block.call(*@arguments)
|
18
|
+
@sender << Internals::Response::Block.new(self, response)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|