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.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +394 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +28 -15
  5. data/culture/CONDUCT.md +28 -0
  6. data/culture/Gemfile +9 -0
  7. data/culture/LICENSE.txt +22 -0
  8. data/culture/README.md +22 -0
  9. data/culture/Rakefile +5 -0
  10. data/culture/SYNC.md +70 -0
  11. data/culture/celluloid-culture.gemspec +18 -0
  12. data/culture/gems/README.md +39 -0
  13. data/culture/gems/dependencies.yml +85 -0
  14. data/culture/gems/loader.rb +101 -0
  15. data/culture/rubocop/README.md +38 -0
  16. data/culture/rubocop/lint.yml +8 -0
  17. data/culture/rubocop/metrics.yml +15 -0
  18. data/culture/rubocop/perf.yml +0 -0
  19. data/culture/rubocop/rubocop.yml +5 -0
  20. data/culture/rubocop/style.yml +57 -0
  21. data/culture/spec/gems_spec.rb +2 -0
  22. data/culture/spec/spec_helper.rb +0 -0
  23. data/culture/spec/sync_spec.rb +2 -0
  24. data/culture/sync.rb +56 -0
  25. data/culture/tasks/rspec.rake +5 -0
  26. data/culture/tasks/rubocop.rake +2 -0
  27. data/examples/basic_usage.rb +49 -0
  28. data/examples/futures.rb +38 -0
  29. data/examples/ring.rb +61 -0
  30. data/examples/simple_pmap.rb +14 -0
  31. data/examples/stack.rb +47 -0
  32. data/examples/timers.rb +72 -0
  33. data/lib/celluloid/actor/manager.rb +7 -0
  34. data/lib/celluloid/actor/system.rb +163 -0
  35. data/lib/celluloid/actor.rb +53 -71
  36. data/lib/celluloid/autostart.rb +1 -1
  37. data/lib/celluloid/backported.rb +2 -0
  38. data/lib/celluloid/call/async.rb +16 -0
  39. data/lib/celluloid/call/block.rb +22 -0
  40. data/lib/celluloid/call/sync.rb +70 -0
  41. data/lib/celluloid/calls.rb +24 -114
  42. data/lib/celluloid/cell.rb +32 -20
  43. data/lib/celluloid/condition.rb +5 -6
  44. data/lib/celluloid/core_ext.rb +1 -1
  45. data/lib/celluloid/current.rb +2 -0
  46. data/lib/celluloid/debug.rb +1 -0
  47. data/lib/celluloid/deprecate.rb +21 -0
  48. data/lib/celluloid/exceptions.rb +22 -16
  49. data/lib/celluloid/fiber.rb +3 -3
  50. data/lib/celluloid/future.rb +46 -8
  51. data/lib/celluloid/group/pool.rb +125 -0
  52. data/lib/celluloid/group/spawner.rb +68 -0
  53. data/lib/celluloid/group.rb +61 -0
  54. data/lib/celluloid/logging.rb +5 -5
  55. data/lib/celluloid/mailbox/evented.rb +74 -0
  56. data/lib/celluloid/mailbox.rb +15 -14
  57. data/lib/celluloid/managed.rb +3 -0
  58. data/lib/celluloid/notices.rb +15 -0
  59. data/lib/celluloid/proxies.rb +11 -0
  60. data/lib/celluloid/proxy/abstract.rb +50 -0
  61. data/lib/celluloid/proxy/actor.rb +37 -0
  62. data/lib/celluloid/proxy/async.rb +15 -0
  63. data/lib/celluloid/proxy/block.rb +28 -0
  64. data/lib/celluloid/proxy/cell.rb +66 -0
  65. data/lib/celluloid/proxy/future.rb +20 -0
  66. data/lib/celluloid/proxy/sync.rb +24 -0
  67. data/lib/celluloid/rspec.rb +67 -9
  68. data/lib/celluloid/system_events.rb +69 -14
  69. data/lib/celluloid/task/fibered.rb +45 -0
  70. data/lib/celluloid/task/threaded.rb +59 -0
  71. data/lib/celluloid/{tasks.rb → task.rb} +30 -38
  72. data/lib/celluloid/test.rb +1 -1
  73. data/lib/celluloid/thread.rb +6 -1
  74. data/lib/celluloid/version.rb +3 -0
  75. data/lib/celluloid.rb +151 -130
  76. data/spec/celluloid/actor/system_spec.rb +83 -0
  77. data/spec/celluloid/actor_spec.rb +2 -2
  78. data/spec/celluloid/block_spec.rb +67 -8
  79. data/spec/celluloid/calls_spec.rb +28 -23
  80. data/spec/celluloid/condition_spec.rb +23 -14
  81. data/spec/celluloid/evented_mailbox_spec.rb +1 -31
  82. data/spec/celluloid/future_spec.rb +15 -12
  83. data/spec/celluloid/group/elastic_spec.rb +0 -0
  84. data/spec/celluloid/group/pool_spec.rb +8 -0
  85. data/spec/celluloid/group/spawner_spec.rb +17 -0
  86. data/spec/celluloid/mailbox/evented_spec.rb +40 -0
  87. data/spec/celluloid/mailbox_spec.rb +1 -3
  88. data/spec/celluloid/misc/leak_spec.rb +73 -0
  89. data/spec/celluloid/proxy_spec.rb +33 -0
  90. data/spec/celluloid/task/fibered_spec.rb +5 -0
  91. data/spec/celluloid/task/threaded_spec.rb +5 -0
  92. data/spec/celluloid/timer_spec.rb +14 -16
  93. data/spec/deprecate/actor_system_spec.rb +72 -0
  94. data/spec/deprecate/block_spec.rb +52 -0
  95. data/spec/deprecate/calls_spec.rb +39 -0
  96. data/spec/deprecate/evented_mailbox_spec.rb +34 -0
  97. data/spec/deprecate/future_spec.rb +32 -0
  98. data/spec/deprecate/internal_pool_spec.rb +4 -0
  99. data/spec/shared/actor_examples.rb +1259 -0
  100. data/spec/shared/group_examples.rb +121 -0
  101. data/spec/shared/mailbox_examples.rb +87 -0
  102. data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
  103. data/spec/spec_helper.rb +5 -42
  104. data/spec/support/configure_rspec.rb +77 -0
  105. data/spec/support/coverage.rb +4 -0
  106. data/spec/support/crash_checking.rb +68 -0
  107. data/spec/support/debugging.rb +31 -0
  108. data/spec/support/env.rb +21 -0
  109. data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
  110. data/spec/support/examples/call_class.rb +37 -0
  111. data/spec/support/examples/evented_mailbox_class.rb +27 -0
  112. data/spec/support/includer.rb +6 -0
  113. data/spec/support/logging.rb +55 -0
  114. data/spec/support/loose_threads.rb +68 -0
  115. data/spec/support/reset_class_variables.rb +27 -0
  116. data/spec/support/sleep_and_wait.rb +14 -0
  117. data/spec/support/stubbing.rb +14 -0
  118. metadata +276 -78
  119. data/lib/celluloid/actor_system.rb +0 -107
  120. data/lib/celluloid/call_chain.rb +0 -13
  121. data/lib/celluloid/cpu_counter.rb +0 -34
  122. data/lib/celluloid/evented_mailbox.rb +0 -73
  123. data/lib/celluloid/fsm.rb +0 -186
  124. data/lib/celluloid/handlers.rb +0 -41
  125. data/lib/celluloid/internal_pool.rb +0 -159
  126. data/lib/celluloid/legacy.rb +0 -9
  127. data/lib/celluloid/links.rb +0 -36
  128. data/lib/celluloid/logger.rb +0 -93
  129. data/lib/celluloid/logging/incident.rb +0 -21
  130. data/lib/celluloid/logging/incident_logger.rb +0 -129
  131. data/lib/celluloid/logging/incident_reporter.rb +0 -48
  132. data/lib/celluloid/logging/log_event.rb +0 -20
  133. data/lib/celluloid/logging/ring_buffer.rb +0 -65
  134. data/lib/celluloid/method.rb +0 -32
  135. data/lib/celluloid/notifications.rb +0 -83
  136. data/lib/celluloid/pool_manager.rb +0 -146
  137. data/lib/celluloid/probe.rb +0 -73
  138. data/lib/celluloid/properties.rb +0 -24
  139. data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
  140. data/lib/celluloid/proxies/actor_proxy.rb +0 -38
  141. data/lib/celluloid/proxies/async_proxy.rb +0 -31
  142. data/lib/celluloid/proxies/block_proxy.rb +0 -29
  143. data/lib/celluloid/proxies/cell_proxy.rb +0 -68
  144. data/lib/celluloid/proxies/future_proxy.rb +0 -35
  145. data/lib/celluloid/proxies/sync_proxy.rb +0 -36
  146. data/lib/celluloid/receivers.rb +0 -63
  147. data/lib/celluloid/registry.rb +0 -57
  148. data/lib/celluloid/responses.rb +0 -44
  149. data/lib/celluloid/rspec/actor_examples.rb +0 -1054
  150. data/lib/celluloid/rspec/mailbox_examples.rb +0 -84
  151. data/lib/celluloid/signals.rb +0 -23
  152. data/lib/celluloid/stack_dump.rb +0 -133
  153. data/lib/celluloid/supervision_group.rb +0 -169
  154. data/lib/celluloid/supervisor.rb +0 -22
  155. data/lib/celluloid/task_set.rb +0 -49
  156. data/lib/celluloid/tasks/task_fiber.rb +0 -43
  157. data/lib/celluloid/tasks/task_thread.rb +0 -53
  158. data/lib/celluloid/thread_handle.rb +0 -50
  159. data/lib/celluloid/uuid.rb +0 -38
  160. data/spec/celluloid/actor_system_spec.rb +0 -69
  161. data/spec/celluloid/cpu_counter_spec.rb +0 -82
  162. data/spec/celluloid/fsm_spec.rb +0 -107
  163. data/spec/celluloid/internal_pool_spec.rb +0 -52
  164. data/spec/celluloid/links_spec.rb +0 -45
  165. data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
  166. data/spec/celluloid/notifications_spec.rb +0 -120
  167. data/spec/celluloid/pool_spec.rb +0 -92
  168. data/spec/celluloid/probe_spec.rb +0 -121
  169. data/spec/celluloid/properties_spec.rb +0 -42
  170. data/spec/celluloid/registry_spec.rb +0 -64
  171. data/spec/celluloid/stack_dump_spec.rb +0 -64
  172. data/spec/celluloid/supervision_group_spec.rb +0 -65
  173. data/spec/celluloid/supervisor_spec.rb +0 -103
  174. data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
  175. data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
  176. data/spec/celluloid/thread_handle_spec.rb +0 -26
  177. data/spec/celluloid/uuid_spec.rb +0 -11
data/lib/celluloid.rb CHANGED
@@ -1,14 +1,22 @@
1
- require 'logger'
2
- require 'thread'
3
- require 'timeout'
4
- require 'set'
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 :actor_system # Default Actor System
20
- attr_accessor :logger # Thread-safe logger class
21
- attr_accessor :task_class # Default task type to use
22
- attr_accessor :shutdown_timeout # How long actors have to terminate
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] or raise Error, "actor system not running"
36
+ Thread.current[:celluloid_actor_system] || fail(Error, "actor system not running")
27
37
  else
28
- Thread.current[:celluloid_actor_system] || @actor_system or raise Error, "Celluloid is not yet started; use Celluloid.boot"
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, :default => Celluloid::Mailbox
39
- klass.property :proxy_class, :default => Celluloid::CellProxy
40
- klass.property :task_class, :default => Celluloid.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, :default => false
44
- klass.property :exclusive_methods, :multi => true
54
+ klass.property :exclusive_actor, default: false
55
+ klass.property :exclusive_methods, multi: true
45
56
  klass.property :execute_block_on_receiver,
46
- :default => [:after, :every, :receive],
47
- :multi => true
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.send(:define_singleton_method, :trap_exit) do |*args|
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
- klass.send(:define_singleton_method, :exclusive) do |*args|
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
- CPUCounter.cores
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 = ActorSystem.new
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 = $!.status if $!.is_a?(SystemExit)
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
- raise NotActorError, "can't link outside actor context" unless Celluloid.actor?
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
- :actor_system => actor_system,
224
- :mailbox_class => mailbox_class,
225
- :mailbox_size => mailbox_size,
226
- :task_class => task_class,
227
- :exclusive => exclusive_actor,
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
- :proxy_class => proxy_class,
234
- :exclusive_methods => exclusive_methods,
235
- :exit_handler_name => exit_handler_name,
236
- :finalizer => finalizer,
237
- :receiver_block_executions => execute_block_on_receiver,
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.kind_of? self
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; self; end
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::CellProxy"
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
- when String then RuntimeError.new(cause)
313
- when Exception then cause
314
- else raise TypeError, "Exception object/String expected, but #{cause.class} received"
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
- raise AbortError.new(cause)
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 thread pool, allowing the sender to continue processing other
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
- raise "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+"
461
+ fail "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+"
455
462
  end
456
463
 
457
- require 'celluloid/exceptions'
458
-
459
- require 'celluloid/calls'
460
- require 'celluloid/call_chain'
461
- require 'celluloid/condition'
462
- require 'celluloid/thread'
463
- require 'celluloid/core_ext'
464
- require 'celluloid/cpu_counter'
465
- require 'celluloid/fiber'
466
- require 'celluloid/fsm'
467
- require 'celluloid/internal_pool'
468
- require 'celluloid/links'
469
- require 'celluloid/logger'
470
- require 'celluloid/mailbox'
471
- require 'celluloid/evented_mailbox'
472
- require 'celluloid/method'
473
- require 'celluloid/properties'
474
- require 'celluloid/handlers'
475
- require 'celluloid/receivers'
476
- require 'celluloid/registry'
477
- require 'celluloid/responses'
478
- require 'celluloid/signals'
479
- require 'celluloid/stack_dump'
480
- require 'celluloid/system_events'
481
- require 'celluloid/tasks'
482
- require 'celluloid/task_set'
483
- require 'celluloid/thread_handle'
484
- require 'celluloid/uuid'
485
-
486
- require 'celluloid/proxies/abstract_proxy'
487
- require 'celluloid/proxies/sync_proxy'
488
- require 'celluloid/proxies/cell_proxy'
489
- require 'celluloid/proxies/actor_proxy'
490
- require 'celluloid/proxies/async_proxy'
491
- require 'celluloid/proxies/future_proxy'
492
- require 'celluloid/proxies/block_proxy'
493
-
494
- require 'celluloid/actor'
495
- require 'celluloid/cell'
496
- require 'celluloid/future'
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
- unless $CELLULOID_TEST
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,5 +1,5 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe Celluloid, actor_system: :global do
3
+ RSpec.describe Celluloid do
4
4
  it_behaves_like "a Celluloid Actor", Celluloid
5
5
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
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 << self.receive_result(:self)
15
+ $data << receive_result(:self)
18
16
  $data << current_actor.receive_result(:current_actor)
19
17
  $data << sender_actor.receive_result(:sender)
20
- "somevalue"
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 "works" do
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
- "somevalue",
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.should eq(expected)
111
+ expect($data).to eq(expected)
53
112
  end
54
113
  end