celluloid 0.16.0 → 0.17.3
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.
- checksums.yaml +4 -4
- data/CHANGES.md +394 -0
- data/LICENSE.txt +1 -1
- data/README.md +28 -15
- data/culture/CONDUCT.md +28 -0
- data/culture/Gemfile +9 -0
- data/culture/LICENSE.txt +22 -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 +85 -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/perf.yml +0 -0
- data/culture/rubocop/rubocop.yml +5 -0
- data/culture/rubocop/style.yml +57 -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/stack.rb +47 -0
- data/examples/timers.rb +72 -0
- data/lib/celluloid/actor/manager.rb +7 -0
- data/lib/celluloid/actor/system.rb +163 -0
- data/lib/celluloid/actor.rb +53 -71
- 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 +24 -114
- data/lib/celluloid/cell.rb +32 -20
- data/lib/celluloid/condition.rb +5 -6
- data/lib/celluloid/core_ext.rb +1 -1
- data/lib/celluloid/current.rb +2 -0
- data/lib/celluloid/debug.rb +1 -0
- data/lib/celluloid/deprecate.rb +21 -0
- data/lib/celluloid/exceptions.rb +22 -16
- data/lib/celluloid/fiber.rb +3 -3
- data/lib/celluloid/future.rb +46 -8
- data/lib/celluloid/group/pool.rb +125 -0
- data/lib/celluloid/group/spawner.rb +68 -0
- data/lib/celluloid/group.rb +61 -0
- data/lib/celluloid/logging.rb +5 -5
- data/lib/celluloid/mailbox/evented.rb +74 -0
- data/lib/celluloid/mailbox.rb +15 -14
- data/lib/celluloid/managed.rb +3 -0
- data/lib/celluloid/notices.rb +15 -0
- data/lib/celluloid/proxies.rb +11 -0
- data/lib/celluloid/proxy/abstract.rb +50 -0
- data/lib/celluloid/proxy/actor.rb +37 -0
- data/lib/celluloid/proxy/async.rb +15 -0
- data/lib/celluloid/proxy/block.rb +28 -0
- data/lib/celluloid/proxy/cell.rb +66 -0
- data/lib/celluloid/proxy/future.rb +20 -0
- data/lib/celluloid/proxy/sync.rb +24 -0
- data/lib/celluloid/rspec.rb +67 -9
- data/lib/celluloid/system_events.rb +69 -14
- data/lib/celluloid/task/fibered.rb +45 -0
- data/lib/celluloid/task/threaded.rb +59 -0
- data/lib/celluloid/{tasks.rb → task.rb} +30 -38
- data/lib/celluloid/test.rb +1 -1
- data/lib/celluloid/thread.rb +6 -1
- data/lib/celluloid/version.rb +3 -0
- data/lib/celluloid.rb +151 -130
- data/spec/celluloid/actor/system_spec.rb +83 -0
- data/spec/celluloid/actor_spec.rb +2 -2
- data/spec/celluloid/block_spec.rb +67 -8
- data/spec/celluloid/calls_spec.rb +28 -23
- data/spec/celluloid/condition_spec.rb +23 -14
- data/spec/celluloid/evented_mailbox_spec.rb +1 -31
- data/spec/celluloid/future_spec.rb +15 -12
- data/spec/celluloid/group/elastic_spec.rb +0 -0
- data/spec/celluloid/group/pool_spec.rb +8 -0
- data/spec/celluloid/group/spawner_spec.rb +17 -0
- data/spec/celluloid/mailbox/evented_spec.rb +40 -0
- data/spec/celluloid/mailbox_spec.rb +1 -3
- data/spec/celluloid/misc/leak_spec.rb +73 -0
- data/spec/celluloid/proxy_spec.rb +33 -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 +39 -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 +1259 -0
- data/spec/shared/group_examples.rb +121 -0
- data/spec/shared/mailbox_examples.rb +87 -0
- data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
- data/spec/spec_helper.rb +5 -42
- data/spec/support/configure_rspec.rb +77 -0
- 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 +21 -0
- data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
- data/spec/support/examples/call_class.rb +37 -0
- data/spec/support/examples/evented_mailbox_class.rb +27 -0
- data/spec/support/includer.rb +6 -0
- data/spec/support/logging.rb +55 -0
- data/spec/support/loose_threads.rb +68 -0
- data/spec/support/reset_class_variables.rb +27 -0
- data/spec/support/sleep_and_wait.rb +14 -0
- data/spec/support/stubbing.rb +14 -0
- metadata +276 -78
- data/lib/celluloid/actor_system.rb +0 -107
- 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/rspec/mailbox_examples.rb +0 -84
- 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/actor_system_spec.rb +0 -69
- 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.rb
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
1
|
+
require "logger"
|
|
2
|
+
require "thread"
|
|
3
|
+
require "timeout"
|
|
4
|
+
require "set"
|
|
5
|
+
|
|
6
|
+
$CELLULOID_DEBUG = false
|
|
7
|
+
$CELLULOID_MANAGED ||= false
|
|
8
|
+
|
|
9
|
+
require "celluloid/version"
|
|
10
|
+
require "celluloid/notices"
|
|
11
|
+
|
|
12
|
+
$CELLULOID_BACKPORTED = false if defined?(CELLULOID_FUTURE) && CELLULOID_FUTURE
|
|
13
|
+
$CELLULOID_BACKPORTED = (ENV["CELLULOID_BACKPORTED"] != "false") unless defined?($CELLULOID_BACKPORTED)
|
|
14
|
+
Celluloid::Notices.backported if $CELLULOID_BACKPORTED
|
|
5
15
|
|
|
6
16
|
module Celluloid
|
|
7
17
|
# Expose all instance methods as singleton methods
|
|
8
18
|
extend self
|
|
9
19
|
|
|
10
|
-
VERSION = '0.16.0'
|
|
11
|
-
|
|
12
20
|
# Linking times out after 5 seconds
|
|
13
21
|
LINKING_TIMEOUT = 5
|
|
14
22
|
|
|
@@ -16,16 +24,18 @@ module Celluloid
|
|
|
16
24
|
BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "
|
|
17
25
|
|
|
18
26
|
class << self
|
|
19
|
-
attr_writer
|
|
20
|
-
attr_accessor :logger
|
|
21
|
-
attr_accessor :
|
|
22
|
-
attr_accessor :
|
|
27
|
+
attr_writer :actor_system # Default Actor System
|
|
28
|
+
attr_accessor :logger # Thread-safe logger class
|
|
29
|
+
attr_accessor :log_actor_crashes
|
|
30
|
+
attr_accessor :group_class # Default internal thread group to use
|
|
31
|
+
attr_accessor :task_class # Default task type to use
|
|
32
|
+
attr_accessor :shutdown_timeout # How long actors have to terminate
|
|
23
33
|
|
|
24
34
|
def actor_system
|
|
25
35
|
if Thread.current.celluloid?
|
|
26
|
-
Thread.current[:celluloid_actor_system]
|
|
36
|
+
Thread.current[:celluloid_actor_system] || fail(Error, "actor system not running")
|
|
27
37
|
else
|
|
28
|
-
Thread.current[:celluloid_actor_system] || @actor_system
|
|
38
|
+
Thread.current[:celluloid_actor_system] || @actor_system || fail(Error, "Celluloid is not yet started; use Celluloid.boot")
|
|
29
39
|
end
|
|
30
40
|
end
|
|
31
41
|
|
|
@@ -33,27 +43,32 @@ module Celluloid
|
|
|
33
43
|
klass.send :extend, ClassMethods
|
|
34
44
|
klass.send :include, InstanceMethods
|
|
35
45
|
|
|
36
|
-
klass.send :extend, Properties
|
|
46
|
+
klass.send :extend, Internals::Properties
|
|
37
47
|
|
|
38
|
-
klass.property :mailbox_class, :
|
|
39
|
-
klass.property :proxy_class, :
|
|
40
|
-
klass.property :task_class, :
|
|
48
|
+
klass.property :mailbox_class, default: Celluloid::Mailbox
|
|
49
|
+
klass.property :proxy_class, default: Celluloid::Proxy::Cell
|
|
50
|
+
klass.property :task_class, default: Celluloid.task_class
|
|
51
|
+
klass.property :group_class, default: Celluloid.group_class
|
|
41
52
|
klass.property :mailbox_size
|
|
42
53
|
|
|
43
|
-
klass.property :exclusive_actor, :
|
|
44
|
-
klass.property :exclusive_methods, :
|
|
54
|
+
klass.property :exclusive_actor, default: false
|
|
55
|
+
klass.property :exclusive_methods, multi: true
|
|
45
56
|
klass.property :execute_block_on_receiver,
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
default: [:after, :every, :receive],
|
|
58
|
+
multi: true
|
|
48
59
|
|
|
49
60
|
klass.property :finalizer
|
|
50
61
|
klass.property :exit_handler_name
|
|
51
62
|
|
|
52
|
-
klass
|
|
63
|
+
singleton = class << klass; self; end
|
|
64
|
+
singleton.send(:remove_method, :trap_exit) rescue nil
|
|
65
|
+
singleton.send(:remove_method, :exclusive) rescue nil
|
|
66
|
+
|
|
67
|
+
singleton.send(:define_method, :trap_exit) do |*args|
|
|
53
68
|
exit_handler_name(*args)
|
|
54
69
|
end
|
|
55
70
|
|
|
56
|
-
|
|
71
|
+
singleton.send(:define_method, :exclusive) do |*args|
|
|
57
72
|
if args.any?
|
|
58
73
|
exclusive_methods(*exclusive_methods, *args)
|
|
59
74
|
else
|
|
@@ -74,12 +89,12 @@ module Celluloid
|
|
|
74
89
|
|
|
75
90
|
# Generate a Universally Unique Identifier
|
|
76
91
|
def uuid
|
|
77
|
-
UUID.generate
|
|
92
|
+
Internals::UUID.generate
|
|
78
93
|
end
|
|
79
94
|
|
|
80
95
|
# Obtain the number of CPUs in the system
|
|
81
96
|
def cores
|
|
82
|
-
|
|
97
|
+
Internals::CPUCounter.cores
|
|
83
98
|
end
|
|
84
99
|
alias_method :cpus, :cores
|
|
85
100
|
alias_method :ncpus, :cores
|
|
@@ -90,6 +105,16 @@ module Celluloid
|
|
|
90
105
|
end
|
|
91
106
|
alias_method :dump, :stack_dump
|
|
92
107
|
|
|
108
|
+
# Perform a stack summary of all actors to the given output object
|
|
109
|
+
def stack_summary(output = STDERR)
|
|
110
|
+
actor_system.stack_summary.print(output)
|
|
111
|
+
end
|
|
112
|
+
alias_method :summarize, :stack_summary
|
|
113
|
+
|
|
114
|
+
def public_registry
|
|
115
|
+
actor_system.public_registry
|
|
116
|
+
end
|
|
117
|
+
|
|
93
118
|
# Detect if a particular call is recursing through multiple actors
|
|
94
119
|
def detect_recursion
|
|
95
120
|
actor = Thread.current[:celluloid_actor]
|
|
@@ -98,13 +123,13 @@ module Celluloid
|
|
|
98
123
|
task = Thread.current[:celluloid_task]
|
|
99
124
|
return unless task
|
|
100
125
|
|
|
101
|
-
chain_id = CallChain.current_id
|
|
126
|
+
chain_id = Internals::CallChain.current_id
|
|
102
127
|
actor.tasks.to_a.any? { |t| t != task && t.chain_id == chain_id }
|
|
103
128
|
end
|
|
104
129
|
|
|
105
130
|
# Define an exception handler for actor crashes
|
|
106
131
|
def exception_handler(&block)
|
|
107
|
-
Logger.exception_handler(&block)
|
|
132
|
+
Internals::Logger.exception_handler(&block)
|
|
108
133
|
end
|
|
109
134
|
|
|
110
135
|
def suspend(status, waiter)
|
|
@@ -123,7 +148,7 @@ module Celluloid
|
|
|
123
148
|
end
|
|
124
149
|
|
|
125
150
|
def init
|
|
126
|
-
@actor_system =
|
|
151
|
+
@actor_system = Actor::System.new
|
|
127
152
|
end
|
|
128
153
|
|
|
129
154
|
def start
|
|
@@ -135,13 +160,16 @@ module Celluloid
|
|
|
135
160
|
end
|
|
136
161
|
|
|
137
162
|
def register_shutdown
|
|
138
|
-
return if @shutdown_registered
|
|
163
|
+
return if defined?(@shutdown_registered) && @shutdown_registered
|
|
164
|
+
|
|
139
165
|
# Terminate all actors at exit
|
|
140
166
|
at_exit do
|
|
167
|
+
sleep 0.126 # hax grace period for unnaturally terminating actors
|
|
168
|
+
# allows "reason" in exit_handler to resolve before being destroyed
|
|
141
169
|
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
|
|
142
170
|
# workaround for MRI bug losing exit status in at_exit block
|
|
143
171
|
# http://bugs.ruby-lang.org/issues/5218
|
|
144
|
-
exit_status =
|
|
172
|
+
exit_status = $ERROR_INFO.status if $ERROR_INFO.is_a?(SystemExit)
|
|
145
173
|
Celluloid.shutdown
|
|
146
174
|
exit exit_status if exit_status
|
|
147
175
|
else
|
|
@@ -163,7 +191,6 @@ module Celluloid
|
|
|
163
191
|
|
|
164
192
|
# Class methods added to classes which include Celluloid
|
|
165
193
|
module ClassMethods
|
|
166
|
-
# Create a new actor
|
|
167
194
|
def new(*args, &block)
|
|
168
195
|
proxy = Cell.new(allocate, behavior_options, actor_options).proxy
|
|
169
196
|
proxy._send_(:initialize, *args, &block)
|
|
@@ -173,7 +200,7 @@ module Celluloid
|
|
|
173
200
|
|
|
174
201
|
# Create a new actor and link to the current one
|
|
175
202
|
def new_link(*args, &block)
|
|
176
|
-
|
|
203
|
+
fail NotActorError, "can't link outside actor context" unless Celluloid.actor?
|
|
177
204
|
|
|
178
205
|
proxy = Cell.new(allocate, behavior_options, actor_options).proxy
|
|
179
206
|
Actor.link(proxy)
|
|
@@ -182,32 +209,6 @@ module Celluloid
|
|
|
182
209
|
end
|
|
183
210
|
alias_method :spawn_link, :new_link
|
|
184
211
|
|
|
185
|
-
# Create a supervisor which ensures an instance of an actor will restart
|
|
186
|
-
# an actor if it fails
|
|
187
|
-
def supervise(*args, &block)
|
|
188
|
-
Supervisor.supervise(self, *args, &block)
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# Create a supervisor which ensures an instance of an actor will restart
|
|
192
|
-
# an actor if it fails, and keep the actor registered under a given name
|
|
193
|
-
def supervise_as(name, *args, &block)
|
|
194
|
-
Supervisor.supervise_as(name, self, *args, &block)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# Create a new pool of workers. Accepts the following options:
|
|
198
|
-
#
|
|
199
|
-
# * size: how many workers to create. Default is worker per CPU core
|
|
200
|
-
# * args: array of arguments to pass when creating a worker
|
|
201
|
-
#
|
|
202
|
-
def pool(options = {})
|
|
203
|
-
PoolManager.new(self, options)
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
# Same as pool, but links to the pool manager
|
|
207
|
-
def pool_link(options = {})
|
|
208
|
-
PoolManager.new_link(self, options)
|
|
209
|
-
end
|
|
210
|
-
|
|
211
212
|
# Run an actor in the foreground
|
|
212
213
|
def run(*args, &block)
|
|
213
214
|
Actor.join(new(*args, &block))
|
|
@@ -220,26 +221,26 @@ module Celluloid
|
|
|
220
221
|
# Configuration options for Actor#new
|
|
221
222
|
def actor_options
|
|
222
223
|
{
|
|
223
|
-
:
|
|
224
|
-
:
|
|
225
|
-
:
|
|
226
|
-
:
|
|
227
|
-
:
|
|
224
|
+
actor_system: actor_system,
|
|
225
|
+
mailbox_class: mailbox_class,
|
|
226
|
+
mailbox_size: mailbox_size,
|
|
227
|
+
task_class: task_class,
|
|
228
|
+
exclusive: exclusive_actor,
|
|
228
229
|
}
|
|
229
230
|
end
|
|
230
231
|
|
|
231
232
|
def behavior_options
|
|
232
233
|
{
|
|
233
|
-
:
|
|
234
|
-
:
|
|
235
|
-
:
|
|
236
|
-
:
|
|
237
|
-
:
|
|
234
|
+
proxy_class: proxy_class,
|
|
235
|
+
exclusive_methods: exclusive_methods,
|
|
236
|
+
exit_handler_name: exit_handler_name,
|
|
237
|
+
finalizer: finalizer,
|
|
238
|
+
receiver_block_executions: execute_block_on_receiver,
|
|
238
239
|
}
|
|
239
240
|
end
|
|
240
241
|
|
|
241
242
|
def ===(other)
|
|
242
|
-
other.
|
|
243
|
+
other.is_a? self
|
|
243
244
|
end
|
|
244
245
|
end
|
|
245
246
|
|
|
@@ -259,7 +260,9 @@ module Celluloid
|
|
|
259
260
|
# >> actor.bare_object
|
|
260
261
|
# => #<WARNING: BARE CELLULOID OBJECT (Foo:0x3fefcb77c194)>
|
|
261
262
|
#
|
|
262
|
-
def bare_object
|
|
263
|
+
def bare_object
|
|
264
|
+
self
|
|
265
|
+
end
|
|
263
266
|
alias_method :wrapped_object, :bare_object
|
|
264
267
|
|
|
265
268
|
# Are we being invoked in a different thread from our owner?
|
|
@@ -286,7 +289,7 @@ module Celluloid
|
|
|
286
289
|
if leaked?
|
|
287
290
|
str << Celluloid::BARE_OBJECT_WARNING_MESSAGE
|
|
288
291
|
else
|
|
289
|
-
str << "Celluloid::
|
|
292
|
+
str << "Celluloid::Proxy::Cell"
|
|
290
293
|
end
|
|
291
294
|
|
|
292
295
|
str << "(#{self.class}:0x#{object_id.to_s(16)})"
|
|
@@ -297,7 +300,11 @@ module Celluloid
|
|
|
297
300
|
str << "#{ivar}=#{instance_variable_get(ivar).inspect} "
|
|
298
301
|
end
|
|
299
302
|
|
|
300
|
-
str.sub!(/\s$/,
|
|
303
|
+
str.sub!(/\s$/, ">")
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def __arity
|
|
307
|
+
method(:initialize).arity
|
|
301
308
|
end
|
|
302
309
|
end
|
|
303
310
|
|
|
@@ -309,11 +316,11 @@ module Celluloid
|
|
|
309
316
|
# Raise an exception in sender context, but stay running
|
|
310
317
|
def abort(cause)
|
|
311
318
|
cause = case cause
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
319
|
+
when String then RuntimeError.new(cause)
|
|
320
|
+
when Exception then cause
|
|
321
|
+
else fail TypeError, "Exception object/String expected, but #{cause.class} received"
|
|
315
322
|
end
|
|
316
|
-
|
|
323
|
+
fail AbortError.new(cause)
|
|
317
324
|
end
|
|
318
325
|
|
|
319
326
|
# Terminate this actor
|
|
@@ -338,7 +345,7 @@ module Celluloid
|
|
|
338
345
|
|
|
339
346
|
# Obtain the UUID of the current call chain
|
|
340
347
|
def call_chain_id
|
|
341
|
-
CallChain.current_id
|
|
348
|
+
Internals::CallChain.current_id
|
|
342
349
|
end
|
|
343
350
|
|
|
344
351
|
# Obtain the running tasks for this actor
|
|
@@ -431,7 +438,7 @@ module Celluloid
|
|
|
431
438
|
end
|
|
432
439
|
|
|
433
440
|
# Perform a blocking or computationally intensive action inside an
|
|
434
|
-
# asynchronous
|
|
441
|
+
# asynchronous group of threads, allowing the sender to continue processing other
|
|
435
442
|
# messages in its mailbox in the meantime
|
|
436
443
|
def defer(&block)
|
|
437
444
|
# This implementation relies on the present implementation of
|
|
@@ -451,66 +458,80 @@ module Celluloid
|
|
|
451
458
|
end
|
|
452
459
|
|
|
453
460
|
if defined?(JRUBY_VERSION) && JRUBY_VERSION == "1.7.3"
|
|
454
|
-
|
|
461
|
+
fail "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+"
|
|
455
462
|
end
|
|
456
463
|
|
|
457
|
-
require
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
require
|
|
467
|
-
require
|
|
468
|
-
require
|
|
469
|
-
|
|
470
|
-
require
|
|
471
|
-
|
|
472
|
-
require
|
|
473
|
-
|
|
474
|
-
require
|
|
475
|
-
|
|
476
|
-
require
|
|
477
|
-
require
|
|
478
|
-
|
|
479
|
-
require
|
|
480
|
-
|
|
481
|
-
require
|
|
482
|
-
require
|
|
483
|
-
require
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
require
|
|
487
|
-
require
|
|
488
|
-
|
|
489
|
-
require
|
|
490
|
-
require
|
|
491
|
-
require
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
require
|
|
495
|
-
|
|
496
|
-
require
|
|
497
|
-
require 'celluloid/actor_system'
|
|
498
|
-
require 'celluloid/pool_manager'
|
|
499
|
-
require 'celluloid/supervision_group'
|
|
500
|
-
require 'celluloid/supervisor'
|
|
501
|
-
require 'celluloid/notifications'
|
|
502
|
-
require 'celluloid/logging'
|
|
503
|
-
|
|
504
|
-
require 'celluloid/legacy' unless defined?(CELLULOID_FUTURE)
|
|
464
|
+
require "celluloid/exceptions"
|
|
465
|
+
|
|
466
|
+
Celluloid.logger = Logger.new(STDERR).tap do |logger|
|
|
467
|
+
logger.level = Logger::INFO unless $CELLULOID_DEBUG
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
Celluloid.shutdown_timeout = 10
|
|
471
|
+
Celluloid.log_actor_crashes = true
|
|
472
|
+
|
|
473
|
+
require "celluloid/calls"
|
|
474
|
+
require "celluloid/condition"
|
|
475
|
+
require "celluloid/thread"
|
|
476
|
+
|
|
477
|
+
require "celluloid/core_ext"
|
|
478
|
+
|
|
479
|
+
require "celluloid/system_events"
|
|
480
|
+
|
|
481
|
+
require "celluloid/proxies"
|
|
482
|
+
|
|
483
|
+
require "celluloid/mailbox"
|
|
484
|
+
require "celluloid/mailbox/evented"
|
|
485
|
+
|
|
486
|
+
require "celluloid/essentials"
|
|
487
|
+
|
|
488
|
+
require "celluloid/group"
|
|
489
|
+
require "celluloid/group/spawner"
|
|
490
|
+
require "celluloid/group/pool" # TODO: Find way to only load this if being used.
|
|
491
|
+
|
|
492
|
+
require "celluloid/task"
|
|
493
|
+
require "celluloid/task/fibered"
|
|
494
|
+
require "celluloid/task/threaded" # TODO: Find way to only load this if being used.
|
|
495
|
+
|
|
496
|
+
require "celluloid/actor"
|
|
497
|
+
require "celluloid/cell"
|
|
498
|
+
require "celluloid/future"
|
|
499
|
+
|
|
500
|
+
require "celluloid/actor/system"
|
|
501
|
+
require "celluloid/actor/manager"
|
|
502
|
+
|
|
503
|
+
require "celluloid/deprecate" unless $CELLULOID_BACKPORTED == false
|
|
505
504
|
|
|
506
505
|
$CELLULOID_MONITORING = false
|
|
506
|
+
Celluloid::Notices.output
|
|
507
507
|
|
|
508
508
|
# Configure default systemwide settings
|
|
509
|
-
Celluloid.task_class = Celluloid::TaskFiber
|
|
510
|
-
Celluloid.logger = Logger.new(STDERR)
|
|
511
|
-
Celluloid.shutdown_timeout = 10
|
|
512
509
|
|
|
513
|
-
|
|
510
|
+
Celluloid.task_class =
|
|
511
|
+
begin
|
|
512
|
+
str = ENV["CELLULOID_TASK_CLASS"] || "Fibered"
|
|
513
|
+
Kernel.const_get(str)
|
|
514
|
+
rescue NameError
|
|
515
|
+
begin
|
|
516
|
+
Celluloid.const_get(str)
|
|
517
|
+
rescue NameError
|
|
518
|
+
Celluloid::Task.const_get(str)
|
|
519
|
+
end
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
Celluloid.group_class =
|
|
523
|
+
begin
|
|
524
|
+
str = ENV["CELLULOID_GROUP_CLASS"] || "Spawner"
|
|
525
|
+
Kernel.const_get(str)
|
|
526
|
+
rescue NameError
|
|
527
|
+
begin
|
|
528
|
+
Celluloid.const_get(str)
|
|
529
|
+
rescue NameError
|
|
530
|
+
Celluloid::Group.const_get(str)
|
|
531
|
+
end
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
|
|
514
535
|
Celluloid.register_shutdown
|
|
515
536
|
Celluloid.init
|
|
516
537
|
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
RSpec.describe Celluloid::Actor::System do
|
|
2
|
+
class TestActor
|
|
3
|
+
include Celluloid
|
|
4
|
+
def identity
|
|
5
|
+
:testing
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
after do
|
|
10
|
+
subject.shutdown
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "supports non-global Actor::System" do
|
|
14
|
+
subject.within do
|
|
15
|
+
expect(Celluloid.actor_system).to eq(subject)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "makes actors accessible by Celluloid[:actor]" do
|
|
20
|
+
subject.start
|
|
21
|
+
subject.within do
|
|
22
|
+
TestActor.supervise as: :testing, type: TestActor
|
|
23
|
+
expect(subject.registered).to include(:testing)
|
|
24
|
+
expect(Celluloid::Actor[:testing].identity).to eq(:testing)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "starts default actors" do
|
|
29
|
+
subject.start
|
|
30
|
+
expect(subject.registered).to eq(Celluloid::Actor::System::ROOT_SERVICES.map { |r| r[:as] })
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "support getting threads" do
|
|
34
|
+
queue = Queue.new
|
|
35
|
+
subject.get_thread do
|
|
36
|
+
expect(Celluloid.actor_system).to eq(subject)
|
|
37
|
+
queue << nil
|
|
38
|
+
end
|
|
39
|
+
queue.pop
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "allows a stack dump" do
|
|
43
|
+
expect(subject.stack_dump).to be_a(Celluloid::Internals::Stack::Dump)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "allows a stack summary" do
|
|
47
|
+
expect(subject.stack_summary).to be_a(Celluloid::Internals::Stack::Summary)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "returns named actors" do
|
|
51
|
+
subject.start
|
|
52
|
+
subject.within do
|
|
53
|
+
TestActor.supervise as: :test
|
|
54
|
+
end
|
|
55
|
+
expect(subject.registered).to include(:test)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "returns running actors" do
|
|
59
|
+
expect(subject.running).to be_empty
|
|
60
|
+
|
|
61
|
+
first = subject.within do
|
|
62
|
+
TestActor.new
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
second = subject.within do
|
|
66
|
+
TestActor.new
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
expect(subject.running).to eq([first, second])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "shuts down" do
|
|
73
|
+
subject.shutdown
|
|
74
|
+
|
|
75
|
+
expect { subject.get_thread }
|
|
76
|
+
.to raise_error(Celluloid::NotActive)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "warns nicely when no actor system is started" do
|
|
80
|
+
expect { TestActor.new }
|
|
81
|
+
.to raise_error("Celluloid is not yet started; use Celluloid.boot")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
describe "Blocks", actor_system: :global do
|
|
1
|
+
RSpec.describe "Blocks", actor_system: :global do
|
|
4
2
|
class MyBlockActor
|
|
5
3
|
include Celluloid
|
|
6
4
|
|
|
@@ -14,10 +12,36 @@ describe "Blocks", actor_system: :global do
|
|
|
14
12
|
$data << [:outside, @name, current_actor.name]
|
|
15
13
|
other.do_something_and_callback do |value|
|
|
16
14
|
$data << [:yielded, @name, current_actor.name]
|
|
17
|
-
$data <<
|
|
15
|
+
$data << receive_result(:self)
|
|
18
16
|
$data << current_actor.receive_result(:current_actor)
|
|
19
17
|
$data << sender_actor.receive_result(:sender)
|
|
20
|
-
|
|
18
|
+
:pete_the_polyglot_alien
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def deferred_excecution(value, &_block)
|
|
23
|
+
defer do
|
|
24
|
+
yield(value)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def deferred_current_actor(&_block)
|
|
29
|
+
defer do
|
|
30
|
+
yield(current_actor.name)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def defer_for_something(other, &_block)
|
|
35
|
+
sender_actor = current_actor
|
|
36
|
+
defer do
|
|
37
|
+
$data << [:outside, @name, current_actor.name]
|
|
38
|
+
other.do_something_and_callback do |value|
|
|
39
|
+
$data << [:yielded, @name, current_actor.name]
|
|
40
|
+
$data << receive_result(:self)
|
|
41
|
+
$data << current_actor.receive_result(:current_actor)
|
|
42
|
+
$data << sender_actor.receive_result(:sender)
|
|
43
|
+
:pete_the_polyglot_alien
|
|
44
|
+
end
|
|
21
45
|
end
|
|
22
46
|
end
|
|
23
47
|
|
|
@@ -31,7 +55,7 @@ describe "Blocks", actor_system: :global do
|
|
|
31
55
|
end
|
|
32
56
|
end
|
|
33
57
|
|
|
34
|
-
it "
|
|
58
|
+
it "work between actors" do
|
|
35
59
|
$data = []
|
|
36
60
|
|
|
37
61
|
a1 = MyBlockActor.new("one")
|
|
@@ -46,9 +70,44 @@ describe "Blocks", actor_system: :global do
|
|
|
46
70
|
[:self, "one", "one"],
|
|
47
71
|
[:current_actor, "one", "one"],
|
|
48
72
|
[:sender, "one", "one"],
|
|
49
|
-
|
|
73
|
+
:pete_the_polyglot_alien,
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
expect($data).to eq(expected)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
execute_deferred = proc do
|
|
80
|
+
a1 = MyBlockActor.new("one")
|
|
81
|
+
expect(a1.deferred_excecution(:pete_the_polyglot_alien) { |v| v })
|
|
82
|
+
.to eq(:pete_the_polyglot_alien)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# unless RUBY_ENGINE == 'jruby'
|
|
86
|
+
xit("can be deferred", &execute_deferred)
|
|
87
|
+
# else
|
|
88
|
+
# it("can be deferred", &execute_deferred)
|
|
89
|
+
# end
|
|
90
|
+
|
|
91
|
+
xit "can execute deferred blocks referencing current_actor" do
|
|
92
|
+
a1 = MyBlockActor.new("one")
|
|
93
|
+
expect(a1.deferred_current_actor { |v| v }).to be("one")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
xit "can execute deferred blocks with another actor" do
|
|
97
|
+
$data = []
|
|
98
|
+
a1 = MyBlockActor.new("one")
|
|
99
|
+
a2 = MyBlockActor.new("two")
|
|
100
|
+
a1.defer_for_something a2
|
|
101
|
+
expected = [
|
|
102
|
+
[:outside, "one", "one"],
|
|
103
|
+
[:something, "two", "two"],
|
|
104
|
+
[:yielded, "one", "one"],
|
|
105
|
+
[:self, "one", "one"],
|
|
106
|
+
[:current_actor, "one", "one"],
|
|
107
|
+
[:sender, "one", "one"],
|
|
108
|
+
:pete_the_polyglot_alien,
|
|
50
109
|
]
|
|
51
110
|
|
|
52
|
-
$data.
|
|
111
|
+
expect($data).to eq(expected)
|
|
53
112
|
end
|
|
54
113
|
end
|