celluloid 0.17.3 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +300 -73
- data/CONDUCT.md +13 -0
- data/CONTRIBUTING.md +39 -0
- data/README.md +54 -150
- data/REFACTOR.md +1 -0
- data/architecture.md +120 -0
- data/examples/basic_usage.rb +1 -1
- data/examples/configurations.rb +78 -0
- data/examples/futures.rb +1 -1
- data/examples/ring.rb +5 -4
- data/examples/simple_pmap.rb +1 -1
- data/examples/stack.rb +2 -2
- data/examples/supervisors_and_registry.rb +82 -0
- data/examples/timers.rb +2 -2
- data/lib/celluloid.rb +74 -64
- data/lib/celluloid/actor.rb +27 -17
- data/lib/celluloid/actor/system.rb +13 -29
- data/lib/celluloid/autostart.rb +6 -1
- data/lib/celluloid/call/async.rb +2 -0
- data/lib/celluloid/call/sync.rb +10 -3
- data/lib/celluloid/calls.rb +13 -12
- data/lib/celluloid/cell.rb +5 -9
- data/lib/celluloid/condition.rb +3 -3
- data/lib/celluloid/core_ext.rb +0 -2
- data/lib/celluloid/debug.rb +3 -0
- data/lib/celluloid/exceptions.rb +2 -2
- data/lib/celluloid/future.rb +8 -10
- data/lib/celluloid/group.rb +16 -6
- data/lib/celluloid/group/pool.rb +1 -3
- data/lib/celluloid/group/spawner.rb +2 -6
- data/lib/celluloid/internals/call_chain.rb +15 -0
- data/lib/celluloid/internals/cpu_counter.rb +62 -0
- data/lib/celluloid/internals/handlers.rb +42 -0
- data/lib/celluloid/internals/links.rb +38 -0
- data/lib/celluloid/internals/logger.rb +104 -0
- data/lib/celluloid/internals/method.rb +34 -0
- data/lib/celluloid/internals/properties.rb +32 -0
- data/lib/celluloid/internals/receivers.rb +64 -0
- data/lib/celluloid/internals/registry.rb +102 -0
- data/lib/celluloid/internals/responses.rb +46 -0
- data/lib/celluloid/internals/signals.rb +24 -0
- data/lib/celluloid/internals/stack.rb +74 -0
- data/lib/celluloid/internals/stack/dump.rb +12 -0
- data/lib/celluloid/internals/stack/states.rb +72 -0
- data/lib/celluloid/internals/stack/summary.rb +12 -0
- data/lib/celluloid/internals/task_set.rb +51 -0
- data/lib/celluloid/internals/thread_handle.rb +52 -0
- data/lib/celluloid/internals/uuid.rb +40 -0
- data/lib/celluloid/logging/incident.rb +21 -0
- data/lib/celluloid/logging/incident_logger.rb +147 -0
- data/lib/celluloid/logging/incident_reporter.rb +49 -0
- data/lib/celluloid/logging/log_event.rb +20 -0
- data/lib/celluloid/logging/ring_buffer.rb +64 -0
- data/lib/celluloid/mailbox.rb +22 -9
- data/lib/celluloid/mailbox/evented.rb +13 -5
- data/lib/celluloid/notifications.rb +95 -0
- data/lib/celluloid/pool.rb +6 -0
- data/lib/celluloid/probe.rb +81 -0
- data/lib/celluloid/proxy/abstract.rb +9 -9
- data/lib/celluloid/proxy/async.rb +1 -1
- data/lib/celluloid/proxy/block.rb +2 -2
- data/lib/celluloid/proxy/cell.rb +1 -1
- data/lib/celluloid/proxy/future.rb +2 -4
- data/lib/celluloid/proxy/sync.rb +1 -3
- data/lib/celluloid/rspec.rb +22 -33
- data/lib/celluloid/supervision.rb +17 -0
- data/lib/celluloid/supervision/configuration.rb +169 -0
- data/lib/celluloid/supervision/configuration/injections.rb +8 -0
- data/lib/celluloid/supervision/configuration/instance.rb +113 -0
- data/lib/celluloid/supervision/constants.rb +123 -0
- data/lib/celluloid/supervision/container.rb +144 -0
- data/lib/celluloid/supervision/container/behavior.rb +89 -0
- data/lib/celluloid/supervision/container/behavior/pool.rb +71 -0
- data/lib/celluloid/supervision/container/behavior/tree.rb +23 -0
- data/lib/celluloid/supervision/container/injections.rb +8 -0
- data/lib/celluloid/supervision/container/instance.rb +116 -0
- data/lib/celluloid/supervision/container/pool.rb +210 -0
- data/lib/celluloid/supervision/service.rb +27 -0
- data/lib/celluloid/supervision/supervise.rb +34 -0
- data/lib/celluloid/supervision/validation.rb +40 -0
- data/lib/celluloid/supervision/version.rb +5 -0
- data/lib/celluloid/system_events.rb +11 -6
- data/lib/celluloid/task.rb +25 -12
- data/lib/celluloid/task/fibered.rb +6 -2
- data/lib/celluloid/task/threaded.rb +3 -3
- data/lib/celluloid/test.rb +5 -2
- data/lib/celluloid/thread.rb +0 -2
- data/lib/celluloid/version.rb +1 -1
- data/spec/celluloid/block_spec.rb +29 -32
- data/spec/celluloid/calls_spec.rb +5 -15
- data/spec/celluloid/future_spec.rb +7 -1
- data/spec/celluloid/internals/cpu_counter_spec.rb +129 -0
- data/spec/celluloid/internals/links_spec.rb +43 -0
- data/spec/celluloid/internals/properties_spec.rb +40 -0
- data/spec/celluloid/internals/registry_spec.rb +62 -0
- data/spec/celluloid/internals/stack/dump_spec.rb +4 -0
- data/spec/celluloid/internals/stack/summary_spec.rb +4 -0
- data/spec/celluloid/internals/thread_handle_spec.rb +60 -0
- data/spec/celluloid/internals/uuid_spec.rb +9 -0
- data/spec/celluloid/logging/ring_buffer_spec.rb +36 -0
- data/spec/celluloid/mailbox/evented_spec.rb +11 -22
- data/spec/celluloid/misc/leak_spec.rb +3 -4
- data/spec/celluloid/notifications_spec.rb +140 -0
- data/spec/celluloid/probe_spec.rb +102 -0
- data/spec/celluloid/proxy_spec.rb +30 -30
- data/spec/celluloid/supervision/behavior_spec.rb +74 -0
- data/spec/celluloid/supervision/configuration_spec.rb +181 -0
- data/spec/celluloid/supervision/container_spec.rb +72 -0
- data/spec/celluloid/supervision/instance_spec.rb +13 -0
- data/spec/celluloid/supervision/root_spec.rb +28 -0
- data/spec/celluloid/supervision/supervisor_spec.rb +93 -0
- data/spec/celluloid/task/fibered_spec.rb +1 -3
- data/spec/celluloid/task/threaded_spec.rb +1 -3
- data/spec/shared/actor_examples.rb +58 -33
- data/spec/shared/group_examples.rb +2 -2
- data/spec/shared/mailbox_examples.rb +1 -1
- data/spec/shared/stack_examples.rb +87 -0
- data/spec/shared/task_examples.rb +2 -3
- data/spec/spec_helper.rb +2 -4
- data/spec/support/configure_rspec.rb +2 -3
- data/spec/support/coverage.rb +2 -4
- data/spec/support/crash_checking.rb +2 -2
- data/spec/support/examples/actor_class.rb +3 -8
- data/spec/support/examples/call_class.rb +2 -2
- data/spec/support/examples/container_class.rb +35 -0
- data/spec/support/examples/evented_mailbox_class.rb +1 -2
- data/spec/support/examples/stack_classes.rb +58 -0
- data/spec/support/examples/stack_methods.rb +23 -0
- data/spec/support/examples/subordinate_class.rb +19 -0
- data/spec/support/logging.rb +3 -34
- data/spec/support/loose_threads.rb +3 -16
- data/spec/support/reset_class_variables.rb +5 -1
- data/spec/support/stubbing.rb +1 -1
- metadata +91 -290
- data/culture/CONDUCT.md +0 -28
- data/culture/Gemfile +0 -9
- data/culture/LICENSE.txt +0 -22
- data/culture/README.md +0 -22
- data/culture/Rakefile +0 -5
- data/culture/SYNC.md +0 -70
- data/culture/celluloid-culture.gemspec +0 -18
- data/culture/gems/README.md +0 -39
- data/culture/gems/dependencies.yml +0 -85
- data/culture/gems/loader.rb +0 -101
- data/culture/rubocop/README.md +0 -38
- data/culture/rubocop/lint.yml +0 -8
- data/culture/rubocop/metrics.yml +0 -15
- data/culture/rubocop/perf.yml +0 -0
- data/culture/rubocop/rubocop.yml +0 -5
- data/culture/rubocop/style.yml +0 -57
- data/culture/spec/gems_spec.rb +0 -2
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +0 -2
- data/culture/sync.rb +0 -56
- data/culture/tasks/rspec.rake +0 -5
- data/culture/tasks/rubocop.rake +0 -2
- data/lib/celluloid/actor/manager.rb +0 -7
- data/lib/celluloid/backported.rb +0 -2
- data/lib/celluloid/current.rb +0 -2
- data/lib/celluloid/deprecate.rb +0 -21
- data/lib/celluloid/fiber.rb +0 -32
- data/lib/celluloid/managed.rb +0 -3
- data/lib/celluloid/notices.rb +0 -15
- data/spec/deprecate/actor_system_spec.rb +0 -72
- data/spec/deprecate/block_spec.rb +0 -52
- data/spec/deprecate/calls_spec.rb +0 -39
- data/spec/deprecate/evented_mailbox_spec.rb +0 -34
- data/spec/deprecate/future_spec.rb +0 -32
- data/spec/deprecate/internal_pool_spec.rb +0 -4
- data/spec/support/env.rb +0 -21
data/lib/celluloid/actor.rb
CHANGED
@@ -16,14 +16,14 @@ module Celluloid
|
|
16
16
|
# Obtain the current actor
|
17
17
|
def current
|
18
18
|
actor = Thread.current[:celluloid_actor]
|
19
|
-
|
19
|
+
raise NotActorError, "not in actor scope" unless actor
|
20
20
|
actor.behavior_proxy
|
21
21
|
end
|
22
22
|
|
23
23
|
# Obtain the name of the current actor
|
24
24
|
def registered_name
|
25
25
|
actor = Thread.current[:celluloid_actor]
|
26
|
-
|
26
|
+
raise NotActorError, "not in actor scope" unless actor
|
27
27
|
actor.name
|
28
28
|
end
|
29
29
|
|
@@ -52,13 +52,13 @@ module Celluloid
|
|
52
52
|
|
53
53
|
# Watch for exit events from another actor
|
54
54
|
def monitor(actor)
|
55
|
-
|
55
|
+
raise NotActorError, "can't link outside actor context" unless Celluloid.actor?
|
56
56
|
Thread.current[:celluloid_actor].linking_request(actor, :link)
|
57
57
|
end
|
58
58
|
|
59
59
|
# Stop waiting for exit events from another actor
|
60
60
|
def unmonitor(actor)
|
61
|
-
|
61
|
+
raise NotActorError, "can't link outside actor context" unless Celluloid.actor?
|
62
62
|
Thread.current[:celluloid_actor].linking_request(actor, :unlink)
|
63
63
|
end
|
64
64
|
|
@@ -132,8 +132,11 @@ module Celluloid
|
|
132
132
|
end
|
133
133
|
|
134
134
|
@proxy = Proxy::Actor.new(@mailbox, @thread)
|
135
|
+
|
136
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
137
|
+
# rubocop:disable Style/GlobalVars
|
135
138
|
Celluloid::Probe.actor_created(self) if $CELLULOID_MONITORING
|
136
|
-
|
139
|
+
# rubocop:enable Style/GlobalVars
|
137
140
|
end
|
138
141
|
|
139
142
|
def behavior_proxy
|
@@ -187,25 +190,28 @@ module Celluloid
|
|
187
190
|
begin
|
188
191
|
message = @mailbox.receive(remaining) do |msg|
|
189
192
|
msg.is_a?(LinkingResponse) &&
|
190
|
-
|
191
|
-
|
193
|
+
msg.actor.mailbox.address == receiver.mailbox.address &&
|
194
|
+
msg.type == type
|
192
195
|
end
|
193
196
|
rescue TaskTimeout
|
194
197
|
next # IO reactor did something, no message in queue yet.
|
195
198
|
end
|
196
199
|
|
197
200
|
if message.instance_of? LinkingResponse
|
201
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
202
|
+
# rubocop:disable Style/GlobalVars
|
198
203
|
Celluloid::Probe.actors_linked(self, receiver) if $CELLULOID_MONITORING
|
204
|
+
# rubocop:enable Style/GlobalVars
|
199
205
|
system_events.each { |ev| @mailbox << ev }
|
200
206
|
return
|
201
207
|
elsif message.is_a? SystemEvent
|
202
208
|
# Queue up pending system events to be processed after we've successfully linked
|
203
209
|
system_events << message
|
204
|
-
else
|
210
|
+
else raise "Unexpected message type: #{message.class}. Expected LinkingResponse, NilClass, SystemEvent."
|
205
211
|
end
|
206
212
|
end
|
207
213
|
|
208
|
-
|
214
|
+
raise TaskTimeout, "linking timeout of #{LINKING_TIMEOUT} seconds exceeded with receiver: #{receiver}"
|
209
215
|
end
|
210
216
|
end
|
211
217
|
|
@@ -218,7 +224,7 @@ module Celluloid
|
|
218
224
|
def wait(name)
|
219
225
|
@signals.wait name
|
220
226
|
end
|
221
|
-
|
227
|
+
|
222
228
|
# Register a new handler for a given pattern
|
223
229
|
def handle(*patterns, &block)
|
224
230
|
@handlers.handle(*patterns, &block)
|
@@ -226,7 +232,7 @@ module Celluloid
|
|
226
232
|
|
227
233
|
# Receive an asynchronous message
|
228
234
|
def receive(timeout = nil, &block)
|
229
|
-
|
235
|
+
loop do
|
230
236
|
message = @receivers.receive(timeout, &block)
|
231
237
|
return message unless message.is_a?(SystemEvent)
|
232
238
|
|
@@ -280,16 +286,16 @@ module Celluloid
|
|
280
286
|
|
281
287
|
# Handle standard low-priority messages
|
282
288
|
def handle_message(message)
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
289
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
290
|
+
# rubocop:disable Metrics/LineLength, Style/GlobalVars
|
291
|
+
Internals::Logger.debug "Discarded message (unhandled): #{message}" if !@handlers.handle_message(message) && !@receivers.handle_message(message) && $CELLULOID_DEBUG
|
292
|
+
# rubocop:enable Metrics/LineLength, Style/GlobalVars
|
293
|
+
|
288
294
|
message
|
289
295
|
end
|
290
296
|
|
291
297
|
def default_exit_handler(event)
|
292
|
-
|
298
|
+
raise event.reason if event.reason
|
293
299
|
end
|
294
300
|
|
295
301
|
# Handle any exceptions that occur within a running actor
|
@@ -312,7 +318,11 @@ module Celluloid
|
|
312
318
|
|
313
319
|
# Clean up after this actor
|
314
320
|
def cleanup(exit_event)
|
321
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
322
|
+
# rubocop:disable Style/GlobalVars
|
315
323
|
Celluloid::Probe.actor_died(self) if $CELLULOID_MONITORING
|
324
|
+
# rubocop:enable Style/GlobalVars
|
325
|
+
|
316
326
|
@mailbox.shutdown
|
317
327
|
@links.each do |actor|
|
318
328
|
actor.mailbox << exit_event if actor.mailbox.alive?
|
@@ -7,33 +7,18 @@ module Celluloid
|
|
7
7
|
extend Forwardable
|
8
8
|
def_delegators :@registry, :[], :get, :[]=, :set, :delete
|
9
9
|
|
10
|
-
ROOT_SERVICES =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
as: :public_services,
|
23
|
-
type: Celluloid::Supervision::Service::Public,
|
24
|
-
accessors: [:services],
|
25
|
-
supervise: [],
|
26
|
-
},
|
27
|
-
]
|
28
|
-
if $CELLULOID_MANAGED
|
29
|
-
root_services << {
|
30
|
-
as: :actor_manager,
|
31
|
-
type: Celluloid::Actor::Manager,
|
32
|
-
accessors: [:manager],
|
33
|
-
}
|
34
|
-
end
|
35
|
-
root_services
|
36
|
-
end
|
10
|
+
ROOT_SERVICES = [
|
11
|
+
{
|
12
|
+
as: :notifications_fanout,
|
13
|
+
type: Celluloid::Notifications::Fanout
|
14
|
+
},
|
15
|
+
{
|
16
|
+
as: :public_services,
|
17
|
+
type: Celluloid::Supervision::Service::Public,
|
18
|
+
accessors: [:services],
|
19
|
+
supervise: []
|
20
|
+
}
|
21
|
+
].freeze
|
37
22
|
|
38
23
|
attr_reader :registry, :group
|
39
24
|
|
@@ -59,7 +44,6 @@ module Celluloid
|
|
59
44
|
within do
|
60
45
|
@root = Supervision::Service::Root.define
|
61
46
|
@tree = root_configuration.deploy
|
62
|
-
# de root_services[:group_manager].manage! @group
|
63
47
|
end
|
64
48
|
true
|
65
49
|
end
|
@@ -119,7 +103,7 @@ module Celluloid
|
|
119
103
|
def shutdown
|
120
104
|
actors = running
|
121
105
|
Timeout.timeout(shutdown_timeout) do
|
122
|
-
Internals::Logger.debug "Terminating #{actors.size} #{
|
106
|
+
Internals::Logger.debug "Terminating #{actors.size} #{actors.size > 1 ? 'actors' : 'actor'}..." unless actors.empty?
|
123
107
|
|
124
108
|
# Actors cannot self-terminate, you must do it for them
|
125
109
|
actors.each do |actor|
|
data/lib/celluloid/autostart.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
require "celluloid"
|
2
2
|
|
3
|
-
Celluloid.
|
3
|
+
Celluloid.boot
|
4
|
+
|
5
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
6
|
+
# rubocop:disable Style/GlobalVars
|
7
|
+
Celluloid.register_shutdown unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
|
8
|
+
# rubocop:enable Style/GlobalVars
|
data/lib/celluloid/call/async.rb
CHANGED
@@ -7,7 +7,9 @@ module Celluloid
|
|
7
7
|
super(obj)
|
8
8
|
rescue AbortError => ex
|
9
9
|
# Swallow aborted async calls, as they indicate the sender made a mistake
|
10
|
+
# rubocop:disable Metrics/LineLength
|
10
11
|
Internals::Logger.debug("#{obj.class}: async call `#{@method}` aborted!\n#{Internals::Logger.format_exception(ex.cause)}")
|
12
|
+
# rubocop:enable Metrics/LineLength
|
11
13
|
ensure
|
12
14
|
Internals::CallChain.current_id = nil
|
13
15
|
end
|
data/lib/celluloid/call/sync.rb
CHANGED
@@ -4,7 +4,14 @@ module Celluloid
|
|
4
4
|
class Sync < Call
|
5
5
|
attr_reader :sender, :task, :chain_id
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(
|
8
|
+
sender,
|
9
|
+
method,
|
10
|
+
arguments = [],
|
11
|
+
block = nil,
|
12
|
+
task = Thread.current[:celluloid_task],
|
13
|
+
chain_id = Internals::CallChain.current_id
|
14
|
+
)
|
8
15
|
super(method, arguments, block)
|
9
16
|
@sender = sender
|
10
17
|
@task = task
|
@@ -29,7 +36,7 @@ module Celluloid
|
|
29
36
|
end
|
30
37
|
|
31
38
|
def cleanup
|
32
|
-
exception = DeadActorError.new("attempted to call a dead actor: #{
|
39
|
+
exception = DeadActorError.new("attempted to call a dead actor: #{method}")
|
33
40
|
respond Internals::Response::Error.new(self, exception)
|
34
41
|
end
|
35
42
|
|
@@ -46,7 +53,7 @@ module Celluloid
|
|
46
53
|
end
|
47
54
|
|
48
55
|
def wait
|
49
|
-
|
56
|
+
loop do
|
50
57
|
message = Celluloid.mailbox.receive do |msg|
|
51
58
|
msg.respond_to?(:call) && msg.call == self
|
52
59
|
end
|
data/lib/celluloid/calls.rb
CHANGED
@@ -10,7 +10,7 @@ module Celluloid
|
|
10
10
|
if block
|
11
11
|
if Celluloid.exclusive?
|
12
12
|
# FIXME: nicer exception
|
13
|
-
|
13
|
+
raise "Cannot execute blocks on sender in exclusive mode"
|
14
14
|
end
|
15
15
|
@block = Proxy::Block.new(Celluloid.mailbox, self, block)
|
16
16
|
else
|
@@ -24,14 +24,7 @@ module Celluloid
|
|
24
24
|
|
25
25
|
def dispatch(obj)
|
26
26
|
check(obj)
|
27
|
-
|
28
|
-
obj.public_send(@method, *@arguments, &_b)
|
29
|
-
# rescue Celluloid::TaskTimeout => ex
|
30
|
-
# raise ex unless ( @retry += 1 ) <= RETRY_CALL_LIMIT
|
31
|
-
# puts "retrying"
|
32
|
-
# Internals::Logger.warn("TaskTimeout at Call dispatch. Retrying in #{RETRY_CALL_WAIT} seconds. ( Attempt #{@retry} of #{RETRY_CALL_LIMIT} )")
|
33
|
-
# sleep RETRY_CALL_WAIT
|
34
|
-
# retry
|
27
|
+
obj.public_send(@method, *@arguments, &(@block && @block.to_proc))
|
35
28
|
end
|
36
29
|
|
37
30
|
def check(obj)
|
@@ -45,13 +38,21 @@ module Celluloid
|
|
45
38
|
arity = meth.arity
|
46
39
|
|
47
40
|
if arity >= 0
|
48
|
-
|
41
|
+
if @arguments.size != arity
|
42
|
+
e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{arity})")
|
43
|
+
e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`")
|
44
|
+
raise e
|
45
|
+
end
|
49
46
|
elsif arity < -1
|
50
47
|
mandatory_args = -arity - 1
|
51
|
-
|
48
|
+
if arguments.size < mandatory_args
|
49
|
+
e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{mandatory_args}+)")
|
50
|
+
e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`")
|
51
|
+
raise e
|
52
|
+
end
|
52
53
|
end
|
53
54
|
rescue => ex
|
54
|
-
raise AbortError
|
55
|
+
raise AbortError, ex
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
data/lib/celluloid/cell.rb
CHANGED
@@ -36,9 +36,7 @@ module Celluloid
|
|
36
36
|
@actor.handle(Call::Block) do |message|
|
37
37
|
task(:invoke_block) { message.dispatch }
|
38
38
|
end
|
39
|
-
@actor.handle(Internals::Response::Block, Internals::Response)
|
40
|
-
message.dispatch
|
41
|
-
end
|
39
|
+
@actor.handle(Internals::Response::Block, Internals::Response, &:dispatch)
|
42
40
|
|
43
41
|
@actor.start
|
44
42
|
@proxy = (options[:proxy_class] || Proxy::Cell).new(@actor.mailbox, @actor.proxy, @subject.class.to_s)
|
@@ -57,18 +55,16 @@ module Celluloid
|
|
57
55
|
meth = call.method
|
58
56
|
meth = call.arguments.first if meth == :__send__
|
59
57
|
if @receiver_block_executions && meth
|
60
|
-
if @receiver_block_executions.include?(meth.to_sym)
|
61
|
-
call.execute_block_on_receiver
|
62
|
-
end
|
58
|
+
call.execute_block_on_receiver if @receiver_block_executions.include?(meth.to_sym)
|
63
59
|
end
|
64
60
|
|
65
|
-
task(:call, meth, {call: call, subject: @subject},
|
61
|
+
task(:call, meth, { call: call, subject: @subject },
|
66
62
|
dangerous_suspend: meth == :initialize, &Cell.dispatch)
|
67
63
|
end
|
68
64
|
|
69
65
|
def task(task_type, method_name = nil, subject = nil, meta = nil, &_block)
|
70
66
|
meta ||= {}
|
71
|
-
meta
|
67
|
+
meta[:method_name] = method_name
|
72
68
|
@actor.task(task_type, meta) do
|
73
69
|
if @exclusive_methods && method_name && @exclusive_methods.include?(method_name.to_sym)
|
74
70
|
Celluloid.exclusive { yield subject }
|
@@ -94,7 +90,7 @@ module Celluloid
|
|
94
90
|
def shutdown
|
95
91
|
return unless @finalizer && @subject.respond_to?(@finalizer, true)
|
96
92
|
|
97
|
-
task(:finalizer, @finalizer, {call: @finalizer, subject: @subject},
|
93
|
+
task(:finalizer, @finalizer, { call: @finalizer, subject: @subject },
|
98
94
|
dangerous_suspend: true, &Cell.shutdown)
|
99
95
|
end
|
100
96
|
end
|
data/lib/celluloid/condition.rb
CHANGED
@@ -34,7 +34,7 @@ module Celluloid
|
|
34
34
|
|
35
35
|
# Wait for the given signal and return the associated value
|
36
36
|
def wait(timeout = nil)
|
37
|
-
|
37
|
+
raise ConditionError, "cannot wait for signals while exclusive" if Celluloid.exclusive?
|
38
38
|
|
39
39
|
if actor = Thread.current[:celluloid_actor]
|
40
40
|
task = Task.current
|
@@ -57,7 +57,7 @@ module Celluloid
|
|
57
57
|
|
58
58
|
result = Celluloid.suspend :condwait, waiter
|
59
59
|
timer.cancel if timer
|
60
|
-
|
60
|
+
raise result if result.is_a?(ConditionError)
|
61
61
|
return yield(result) if block_given?
|
62
62
|
result
|
63
63
|
end
|
@@ -83,6 +83,6 @@ module Celluloid
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
alias inspect to_s
|
87
87
|
end
|
88
88
|
end
|
data/lib/celluloid/core_ext.rb
CHANGED
data/lib/celluloid/debug.rb
CHANGED
data/lib/celluloid/exceptions.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Celluloid
|
2
2
|
class Error < StandardError; end
|
3
|
-
class Interruption <
|
3
|
+
class Interruption < RuntimeError; end
|
4
4
|
class TimedOut < Celluloid::Interruption; end # Distinguished from `Timeout`
|
5
5
|
class StillActive < Celluloid::Error; end
|
6
6
|
class NotActive < Celluloid::Error; end
|
@@ -9,7 +9,7 @@ module Celluloid
|
|
9
9
|
class NotTaskError < Celluloid::Error; end # Asked to do task-related things outside a task
|
10
10
|
class DeadTaskError < Celluloid::Error; end # Trying to resume a dead task
|
11
11
|
class TaskTerminated < Celluloid::Interruption; end # Kill a running task after terminate
|
12
|
-
class TaskTimeout < Celluloid::TimedOut; end # A timeout
|
12
|
+
class TaskTimeout < Celluloid::TimedOut; end # A timeout occurred before the given request could complete
|
13
13
|
class ConditionError < Celluloid::Error; end
|
14
14
|
class AbortError < Celluloid::Error # The sender made an error, not the current actor
|
15
15
|
attr_reader :cause
|
data/lib/celluloid/future.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "thread"
|
2
|
-
|
3
1
|
module Celluloid
|
4
2
|
# Celluloid::Future objects allow methods and blocks to run in the
|
5
3
|
# background, their values requested later
|
@@ -50,7 +48,7 @@ module Celluloid
|
|
50
48
|
# Execute the given method in future context
|
51
49
|
def execute(receiver, method, args, block)
|
52
50
|
@mutex.synchronize do
|
53
|
-
|
51
|
+
raise "already calling" if @call
|
54
52
|
@call = Call::Sync.new(self, method, args, block)
|
55
53
|
end
|
56
54
|
|
@@ -93,12 +91,12 @@ module Celluloid
|
|
93
91
|
end
|
94
92
|
|
95
93
|
if result
|
96
|
-
|
94
|
+
result.respond_to?(:value) ? result.value : result
|
97
95
|
else
|
98
|
-
|
96
|
+
raise TimedOut, "Timed out"
|
99
97
|
end
|
100
98
|
end
|
101
|
-
|
99
|
+
alias call value
|
102
100
|
|
103
101
|
# Signal this future with the given result value
|
104
102
|
def signal(value)
|
@@ -106,7 +104,7 @@ module Celluloid
|
|
106
104
|
result = Result.new(value, self)
|
107
105
|
|
108
106
|
@mutex.synchronize do
|
109
|
-
|
107
|
+
raise "the future has already happened!" if @ready
|
110
108
|
|
111
109
|
if @forwards
|
112
110
|
@forwards.is_a?(Array) ? @forwards.each { |f| f << result } : @forwards << result
|
@@ -116,10 +114,10 @@ module Celluloid
|
|
116
114
|
@ready = true
|
117
115
|
end
|
118
116
|
end
|
119
|
-
|
117
|
+
alias << signal
|
120
118
|
|
121
119
|
def cancel(error)
|
122
|
-
response =
|
120
|
+
response = Internals::Response::Error.new(@call, error)
|
123
121
|
signal response
|
124
122
|
@mutex.synchronize do
|
125
123
|
@cancelled = true
|
@@ -127,7 +125,7 @@ module Celluloid
|
|
127
125
|
end
|
128
126
|
|
129
127
|
# Inspect this Celluloid::Future
|
130
|
-
|
128
|
+
alias inspect to_s
|
131
129
|
|
132
130
|
# Wrapper for result values to distinguish them in mailboxes
|
133
131
|
class Result
|