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.

Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +333 -0
  3. data/README.md +1 -1
  4. data/culture/CODE_OF_CONDUCT.md +28 -0
  5. data/culture/Gemfile +9 -0
  6. data/culture/README.md +22 -0
  7. data/culture/Rakefile +5 -0
  8. data/culture/SYNC.md +70 -0
  9. data/culture/celluloid-culture.gemspec +18 -0
  10. data/culture/gems/README.md +39 -0
  11. data/culture/gems/dependencies.yml +78 -0
  12. data/culture/gems/loader.rb +101 -0
  13. data/culture/rubocop/README.md +38 -0
  14. data/culture/rubocop/lint.yml +8 -0
  15. data/culture/rubocop/metrics.yml +15 -0
  16. data/culture/rubocop/rubocop.yml +4 -0
  17. data/culture/rubocop/style.yml +48 -0
  18. data/culture/spec/gems_spec.rb +2 -0
  19. data/culture/spec/spec_helper.rb +0 -0
  20. data/culture/spec/sync_spec.rb +2 -0
  21. data/culture/sync.rb +56 -0
  22. data/culture/tasks/rspec.rake +5 -0
  23. data/culture/tasks/rubocop.rake +2 -0
  24. data/examples/basic_usage.rb +49 -0
  25. data/examples/futures.rb +38 -0
  26. data/examples/ring.rb +61 -0
  27. data/examples/simple_pmap.rb +14 -0
  28. data/examples/timers.rb +72 -0
  29. data/lib/celluloid.rb +142 -127
  30. data/lib/celluloid/actor.rb +47 -41
  31. data/lib/celluloid/actor_system.rb +75 -22
  32. data/lib/celluloid/autostart.rb +1 -1
  33. data/lib/celluloid/backported.rb +2 -0
  34. data/lib/celluloid/call/async.rb +16 -0
  35. data/lib/celluloid/call/block.rb +22 -0
  36. data/lib/celluloid/call/sync.rb +70 -0
  37. data/lib/celluloid/calls.rb +25 -114
  38. data/lib/celluloid/cell.rb +32 -20
  39. data/lib/celluloid/condition.rb +3 -3
  40. data/lib/celluloid/core_ext.rb +1 -1
  41. data/lib/celluloid/current.rb +2 -0
  42. data/lib/celluloid/deprecate.rb +18 -0
  43. data/lib/celluloid/exceptions.rb +1 -1
  44. data/lib/celluloid/fiber.rb +3 -3
  45. data/lib/celluloid/future.rb +7 -6
  46. data/lib/celluloid/group.rb +65 -0
  47. data/lib/celluloid/group/manager.rb +27 -0
  48. data/lib/celluloid/group/pool.rb +125 -0
  49. data/lib/celluloid/group/spawner.rb +71 -0
  50. data/lib/celluloid/logging.rb +5 -5
  51. data/lib/celluloid/mailbox.rb +14 -13
  52. data/lib/celluloid/mailbox/evented.rb +76 -0
  53. data/lib/celluloid/notices.rb +15 -0
  54. data/lib/celluloid/proxies.rb +12 -0
  55. data/lib/celluloid/proxy/abstract.rb +24 -0
  56. data/lib/celluloid/proxy/actor.rb +46 -0
  57. data/lib/celluloid/proxy/async.rb +36 -0
  58. data/lib/celluloid/proxy/block.rb +31 -0
  59. data/lib/celluloid/proxy/cell.rb +76 -0
  60. data/lib/celluloid/proxy/future.rb +40 -0
  61. data/lib/celluloid/proxy/sync.rb +44 -0
  62. data/lib/celluloid/rspec.rb +9 -10
  63. data/lib/celluloid/system_events.rb +16 -15
  64. data/lib/celluloid/{tasks.rb → task.rb} +21 -21
  65. data/lib/celluloid/task/fibered.rb +45 -0
  66. data/lib/celluloid/task/threaded.rb +59 -0
  67. data/lib/celluloid/test.rb +1 -1
  68. data/lib/celluloid/thread.rb +6 -1
  69. data/lib/celluloid/version.rb +3 -0
  70. data/spec/celluloid/actor_spec.rb +2 -2
  71. data/spec/celluloid/actor_system_spec.rb +35 -21
  72. data/spec/celluloid/block_spec.rb +3 -5
  73. data/spec/celluloid/calls_spec.rb +33 -11
  74. data/spec/celluloid/condition_spec.rb +16 -13
  75. data/spec/celluloid/evented_mailbox_spec.rb +1 -31
  76. data/spec/celluloid/future_spec.rb +13 -10
  77. data/spec/celluloid/group/elastic_spec.rb +0 -0
  78. data/spec/celluloid/group/manager_spec.rb +0 -0
  79. data/spec/celluloid/group/pool_spec.rb +8 -0
  80. data/spec/celluloid/group/spawner_spec.rb +8 -0
  81. data/spec/celluloid/mailbox/evented_spec.rb +27 -0
  82. data/spec/celluloid/mailbox_spec.rb +1 -3
  83. data/spec/celluloid/misc/leak_spec.rb +73 -0
  84. data/spec/celluloid/task/fibered_spec.rb +5 -0
  85. data/spec/celluloid/task/threaded_spec.rb +5 -0
  86. data/spec/celluloid/timer_spec.rb +14 -16
  87. data/spec/deprecate/actor_system_spec.rb +72 -0
  88. data/spec/deprecate/block_spec.rb +52 -0
  89. data/spec/deprecate/calls_spec.rb +57 -0
  90. data/spec/deprecate/evented_mailbox_spec.rb +34 -0
  91. data/spec/deprecate/future_spec.rb +32 -0
  92. data/spec/deprecate/internal_pool_spec.rb +4 -0
  93. data/spec/shared/actor_examples.rb +1237 -0
  94. data/spec/shared/group_examples.rb +121 -0
  95. data/{lib/celluloid/rspec → spec/shared}/mailbox_examples.rb +20 -17
  96. data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
  97. data/spec/spec_helper.rb +72 -16
  98. data/spec/support/coverage.rb +4 -0
  99. data/spec/support/crash_checking.rb +68 -0
  100. data/spec/support/debugging.rb +31 -0
  101. data/spec/support/env.rb +16 -0
  102. data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
  103. data/spec/support/examples/evented_mailbox_class.rb +27 -0
  104. data/spec/support/includer.rb +9 -0
  105. data/spec/support/logging.rb +63 -0
  106. data/spec/support/loose_threads.rb +65 -0
  107. data/spec/support/reset_class_variables.rb +27 -0
  108. data/spec/support/sleep_and_wait.rb +14 -0
  109. data/spec/support/split_logs.rb +1 -0
  110. data/spec/support/stubbing.rb +14 -0
  111. metadata +255 -95
  112. data/lib/celluloid/call_chain.rb +0 -13
  113. data/lib/celluloid/cpu_counter.rb +0 -34
  114. data/lib/celluloid/evented_mailbox.rb +0 -73
  115. data/lib/celluloid/fsm.rb +0 -186
  116. data/lib/celluloid/handlers.rb +0 -41
  117. data/lib/celluloid/internal_pool.rb +0 -159
  118. data/lib/celluloid/legacy.rb +0 -9
  119. data/lib/celluloid/links.rb +0 -36
  120. data/lib/celluloid/logger.rb +0 -93
  121. data/lib/celluloid/logging/incident.rb +0 -21
  122. data/lib/celluloid/logging/incident_logger.rb +0 -129
  123. data/lib/celluloid/logging/incident_reporter.rb +0 -48
  124. data/lib/celluloid/logging/log_event.rb +0 -20
  125. data/lib/celluloid/logging/ring_buffer.rb +0 -65
  126. data/lib/celluloid/method.rb +0 -32
  127. data/lib/celluloid/notifications.rb +0 -83
  128. data/lib/celluloid/pool_manager.rb +0 -146
  129. data/lib/celluloid/probe.rb +0 -73
  130. data/lib/celluloid/properties.rb +0 -24
  131. data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
  132. data/lib/celluloid/proxies/actor_proxy.rb +0 -38
  133. data/lib/celluloid/proxies/async_proxy.rb +0 -31
  134. data/lib/celluloid/proxies/block_proxy.rb +0 -29
  135. data/lib/celluloid/proxies/cell_proxy.rb +0 -68
  136. data/lib/celluloid/proxies/future_proxy.rb +0 -35
  137. data/lib/celluloid/proxies/sync_proxy.rb +0 -36
  138. data/lib/celluloid/receivers.rb +0 -63
  139. data/lib/celluloid/registry.rb +0 -57
  140. data/lib/celluloid/responses.rb +0 -44
  141. data/lib/celluloid/rspec/actor_examples.rb +0 -1054
  142. data/lib/celluloid/signals.rb +0 -23
  143. data/lib/celluloid/stack_dump.rb +0 -133
  144. data/lib/celluloid/supervision_group.rb +0 -169
  145. data/lib/celluloid/supervisor.rb +0 -22
  146. data/lib/celluloid/task_set.rb +0 -49
  147. data/lib/celluloid/tasks/task_fiber.rb +0 -43
  148. data/lib/celluloid/tasks/task_thread.rb +0 -53
  149. data/lib/celluloid/thread_handle.rb +0 -50
  150. data/lib/celluloid/uuid.rb +0 -38
  151. data/spec/celluloid/cpu_counter_spec.rb +0 -82
  152. data/spec/celluloid/fsm_spec.rb +0 -107
  153. data/spec/celluloid/internal_pool_spec.rb +0 -52
  154. data/spec/celluloid/links_spec.rb +0 -45
  155. data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
  156. data/spec/celluloid/notifications_spec.rb +0 -120
  157. data/spec/celluloid/pool_spec.rb +0 -92
  158. data/spec/celluloid/probe_spec.rb +0 -121
  159. data/spec/celluloid/properties_spec.rb +0 -42
  160. data/spec/celluloid/registry_spec.rb +0 -64
  161. data/spec/celluloid/stack_dump_spec.rb +0 -64
  162. data/spec/celluloid/supervision_group_spec.rb +0 -65
  163. data/spec/celluloid/supervisor_spec.rb +0 -103
  164. data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
  165. data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
  166. data/spec/celluloid/thread_handle_spec.rb +0 -26
  167. data/spec/celluloid/uuid_spec.rb +0 -11
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
4
+ require "celluloid/autostart"
5
+ require "digest/sha2"
6
+
7
+ class Hasher
8
+ include Celluloid
9
+
10
+ def initialize(secret)
11
+ @hash = Digest::SHA2.hexdigest(secret)
12
+ end
13
+
14
+ # Add some data into our hash. This demonstrates a non-trivial computation
15
+ # of the same sort as, say, calculating Fibonacci numbers. Since Celluloid
16
+ # uses several threads, doing something like this won't grind our entire
17
+ # application to a halt
18
+ def add(data, n = 100_000)
19
+ string = @hash + data
20
+ n.times { string = Digest::SHA2.hexdigest(string) }
21
+ @hash = string
22
+ end
23
+ end
24
+
25
+ # Create the hasher
26
+ hasher = Hasher.new("super secret initialization data")
27
+
28
+ # Ask the hasher to perform a complex computation. However, since we're using
29
+ # a future, this doesn't block the current thread
30
+ future = hasher.future.add("some data to be hashed")
31
+
32
+ # We've kicked off the hasher, but this thread can continue performing other
33
+ # activities while the hasher runs in the background
34
+ puts "The hasher is now running, but this thread is free to do whatever it wants"
35
+
36
+ # Now let's ask for the return value from the hasher
37
+ puts "Getting the hasher's return value... "
38
+ p future.value
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
4
+ require "celluloid/autostart"
5
+
6
+ class Ring
7
+ include Celluloid
8
+
9
+ class Node
10
+ include Celluloid
11
+
12
+ def initialize(link)
13
+ @link = link
14
+ end
15
+
16
+ def around(n)
17
+ @link.async.around n
18
+ end
19
+ end
20
+
21
+ def initialize(size)
22
+ @node = Node.new_link current_actor
23
+
24
+ size.times do
25
+ @node = Node.new_link @node
26
+ end
27
+ end
28
+
29
+ # Go around the ring the given number of times
30
+ def run(n)
31
+ fail ArgumentError, "I can't go around a negative number of times" if n < 0
32
+
33
+ async.around n
34
+ wait :done
35
+ end
36
+
37
+ # Go around the ring the given number of times
38
+ def around(n)
39
+ if n.zero?
40
+ signal :done
41
+ else
42
+ @node.async.around n - 1
43
+ end
44
+ end
45
+ end
46
+
47
+ if $PROGRAM_NAME == __FILE__
48
+ require "benchmark"
49
+ SIZE = 512
50
+ TIMES = 10
51
+
52
+ puts "*** Creating a #{SIZE} node ring..."
53
+ puts Benchmark.measure {
54
+ $ring = Ring.new(SIZE)
55
+ }
56
+
57
+ puts "*** Sending a message around #{TIMES} times"
58
+ puts Benchmark.measure {
59
+ $ring.run(TIMES)
60
+ }
61
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
4
+ require "celluloid/autostart"
5
+
6
+ module Enumerable
7
+ # Simple parallel map using Celluloid::Futures
8
+ def pmap(&block)
9
+ futures = map { |elem| Celluloid::Future.new(elem, &block) }
10
+ futures.map(&:value)
11
+ end
12
+ end
13
+
14
+ p 100.times.pmap { |n| n * 2 }
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
4
+ require "celluloid/current"
5
+
6
+ class TimerExample
7
+ include Celluloid
8
+ attr_reader :fired, :timer
9
+
10
+ def initialize
11
+ @fired = false
12
+ @timer = after(3) { puts "Timer fired!"; @fired = true }
13
+ end
14
+ end
15
+
16
+ #
17
+ # Basic timer example
18
+ #
19
+
20
+ actor = TimerExample.new
21
+
22
+ # The timer hasn't fired yet, so this should be false
23
+ puts "Timer hasn't fired yet, so this should be false: #{actor.fired}"
24
+
25
+ # Even if we wait a second, it still hasn't fired
26
+ sleep 1
27
+ puts "Timer still shouldn't have fired yet: #{actor.fired}"
28
+
29
+ # Wait until after the timer should've fired
30
+ sleep 2.1
31
+ puts "Timer should've fired now: #{actor.fired}"
32
+
33
+ #
34
+ # Cancelling timers
35
+ #
36
+
37
+ actor = TimerExample.new
38
+
39
+ # The timer hasn't fired yet, so this should be false
40
+ puts "Timer hasn't fired yet, so this should be false: #{actor.fired}"
41
+
42
+ # Cancel the timer, which should prevent it from firing
43
+ actor.timer.cancel
44
+
45
+ # Wait until after the timer should've fired
46
+ sleep 3.1
47
+ puts "Timer shouldn't have fired because we cancelled it: #{actor.fired}"
48
+
49
+ class RepeatingTimerExample
50
+ include Celluloid
51
+
52
+ def initialize
53
+ @sheep = 0
54
+ end
55
+
56
+ def count_sheep
57
+ print "<#{self.class.name}> Counting sheep to go to sleep: "
58
+ @timer = every(0.1) do
59
+ @sheep += 1
60
+ print @sheep, " "
61
+ end
62
+ end
63
+
64
+ def stop_counting
65
+ @timer.cancel
66
+ end
67
+ end
68
+
69
+ sleepy_actor = RepeatingTimerExample.new
70
+ sleepy_actor.count_sheep
71
+ sleep 1
72
+ sleepy_actor.stop_counting
@@ -1,14 +1,21 @@
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
+
8
+ require "celluloid/version"
9
+ require "celluloid/notices"
10
+
11
+ $CELLULOID_BACKPORTED = false if defined?(CELLULOID_FUTURE) && CELLULOID_FUTURE
12
+ $CELLULOID_BACKPORTED = (ENV["CELLULOID_BACKPORTED"] != "false") unless defined?($CELLULOID_BACKPORTED)
13
+ Celluloid::Notices.backported if $CELLULOID_BACKPORTED
5
14
 
6
15
  module Celluloid
7
16
  # Expose all instance methods as singleton methods
8
17
  extend self
9
18
 
10
- VERSION = '0.16.0'
11
-
12
19
  # Linking times out after 5 seconds
13
20
  LINKING_TIMEOUT = 5
14
21
 
@@ -16,16 +23,18 @@ module Celluloid
16
23
  BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "
17
24
 
18
25
  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
26
+ attr_writer :actor_system # Default Actor System
27
+ attr_accessor :logger # Thread-safe logger class
28
+ attr_accessor :log_actor_crashes
29
+ attr_accessor :group_class # Default internal thread group to use
30
+ attr_accessor :task_class # Default task type to use
31
+ attr_accessor :shutdown_timeout # How long actors have to terminate
23
32
 
24
33
  def actor_system
25
34
  if Thread.current.celluloid?
26
- Thread.current[:celluloid_actor_system] or raise Error, "actor system not running"
35
+ Thread.current[:celluloid_actor_system] || fail(Error, "actor system not running")
27
36
  else
28
- Thread.current[:celluloid_actor_system] || @actor_system or raise Error, "Celluloid is not yet started; use Celluloid.boot"
37
+ Thread.current[:celluloid_actor_system] || @actor_system || fail(Error, "Celluloid is not yet started; use Celluloid.boot")
29
38
  end
30
39
  end
31
40
 
@@ -33,27 +42,32 @@ module Celluloid
33
42
  klass.send :extend, ClassMethods
34
43
  klass.send :include, InstanceMethods
35
44
 
36
- klass.send :extend, Properties
45
+ klass.send :extend, Internals::Properties
37
46
 
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
47
+ klass.property :mailbox_class, default: Celluloid::Mailbox
48
+ klass.property :proxy_class, default: Celluloid::Proxy::Cell
49
+ klass.property :task_class, default: Celluloid.task_class
50
+ klass.property :group_class, default: Celluloid.group_class
41
51
  klass.property :mailbox_size
42
52
 
43
- klass.property :exclusive_actor, :default => false
44
- klass.property :exclusive_methods, :multi => true
53
+ klass.property :exclusive_actor, default: false
54
+ klass.property :exclusive_methods, multi: true
45
55
  klass.property :execute_block_on_receiver,
46
- :default => [:after, :every, :receive],
47
- :multi => true
56
+ default: [:after, :every, :receive],
57
+ multi: true
48
58
 
49
59
  klass.property :finalizer
50
60
  klass.property :exit_handler_name
51
61
 
52
- klass.send(:define_singleton_method, :trap_exit) do |*args|
62
+ singleton = class << klass; self; end
63
+ singleton.send(:remove_method, :trap_exit) rescue nil
64
+ singleton.send(:remove_method, :exclusive) rescue nil
65
+
66
+ singleton.send(:define_method, :trap_exit) do |*args|
53
67
  exit_handler_name(*args)
54
68
  end
55
69
 
56
- klass.send(:define_singleton_method, :exclusive) do |*args|
70
+ singleton.send(:define_method, :exclusive) do |*args|
57
71
  if args.any?
58
72
  exclusive_methods(*exclusive_methods, *args)
59
73
  else
@@ -74,12 +88,12 @@ module Celluloid
74
88
 
75
89
  # Generate a Universally Unique Identifier
76
90
  def uuid
77
- UUID.generate
91
+ Internals::UUID.generate
78
92
  end
79
93
 
80
94
  # Obtain the number of CPUs in the system
81
95
  def cores
82
- CPUCounter.cores
96
+ Internals::CPUCounter.cores
83
97
  end
84
98
  alias_method :cpus, :cores
85
99
  alias_method :ncpus, :cores
@@ -90,6 +104,16 @@ module Celluloid
90
104
  end
91
105
  alias_method :dump, :stack_dump
92
106
 
107
+ # Perform a stack summary of all actors to the given output object
108
+ def stack_summary(output = STDERR)
109
+ actor_system.stack_summary.print(output)
110
+ end
111
+ alias_method :summarize, :stack_summary
112
+
113
+ def public_registry
114
+ actor_system.public_registry
115
+ end
116
+
93
117
  # Detect if a particular call is recursing through multiple actors
94
118
  def detect_recursion
95
119
  actor = Thread.current[:celluloid_actor]
@@ -98,13 +122,13 @@ module Celluloid
98
122
  task = Thread.current[:celluloid_task]
99
123
  return unless task
100
124
 
101
- chain_id = CallChain.current_id
125
+ chain_id = Internals::CallChain.current_id
102
126
  actor.tasks.to_a.any? { |t| t != task && t.chain_id == chain_id }
103
127
  end
104
128
 
105
129
  # Define an exception handler for actor crashes
106
130
  def exception_handler(&block)
107
- Logger.exception_handler(&block)
131
+ Internals::Logger.exception_handler(&block)
108
132
  end
109
133
 
110
134
  def suspend(status, waiter)
@@ -135,13 +159,14 @@ module Celluloid
135
159
  end
136
160
 
137
161
  def register_shutdown
138
- return if @shutdown_registered
162
+ return if defined?(@shutdown_registered) && @shutdown_registered
163
+
139
164
  # Terminate all actors at exit
140
165
  at_exit do
141
166
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
142
167
  # workaround for MRI bug losing exit status in at_exit block
143
168
  # http://bugs.ruby-lang.org/issues/5218
144
- exit_status = $!.status if $!.is_a?(SystemExit)
169
+ exit_status = $ERROR_INFO.status if $ERROR_INFO.is_a?(SystemExit)
145
170
  Celluloid.shutdown
146
171
  exit exit_status if exit_status
147
172
  else
@@ -163,7 +188,6 @@ module Celluloid
163
188
 
164
189
  # Class methods added to classes which include Celluloid
165
190
  module ClassMethods
166
- # Create a new actor
167
191
  def new(*args, &block)
168
192
  proxy = Cell.new(allocate, behavior_options, actor_options).proxy
169
193
  proxy._send_(:initialize, *args, &block)
@@ -173,7 +197,7 @@ module Celluloid
173
197
 
174
198
  # Create a new actor and link to the current one
175
199
  def new_link(*args, &block)
176
- raise NotActorError, "can't link outside actor context" unless Celluloid.actor?
200
+ fail NotActorError, "can't link outside actor context" unless Celluloid.actor?
177
201
 
178
202
  proxy = Cell.new(allocate, behavior_options, actor_options).proxy
179
203
  Actor.link(proxy)
@@ -182,32 +206,6 @@ module Celluloid
182
206
  end
183
207
  alias_method :spawn_link, :new_link
184
208
 
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
209
  # Run an actor in the foreground
212
210
  def run(*args, &block)
213
211
  Actor.join(new(*args, &block))
@@ -220,26 +218,26 @@ module Celluloid
220
218
  # Configuration options for Actor#new
221
219
  def actor_options
222
220
  {
223
- :actor_system => actor_system,
224
- :mailbox_class => mailbox_class,
225
- :mailbox_size => mailbox_size,
226
- :task_class => task_class,
227
- :exclusive => exclusive_actor,
221
+ actor_system: actor_system,
222
+ mailbox_class: mailbox_class,
223
+ mailbox_size: mailbox_size,
224
+ task_class: task_class,
225
+ exclusive: exclusive_actor,
228
226
  }
229
227
  end
230
228
 
231
229
  def behavior_options
232
230
  {
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,
231
+ proxy_class: proxy_class,
232
+ exclusive_methods: exclusive_methods,
233
+ exit_handler_name: exit_handler_name,
234
+ finalizer: finalizer,
235
+ receiver_block_executions: execute_block_on_receiver,
238
236
  }
239
237
  end
240
238
 
241
239
  def ===(other)
242
- other.kind_of? self
240
+ other.is_a? self
243
241
  end
244
242
  end
245
243
 
@@ -259,7 +257,9 @@ module Celluloid
259
257
  # >> actor.bare_object
260
258
  # => #<WARNING: BARE CELLULOID OBJECT (Foo:0x3fefcb77c194)>
261
259
  #
262
- def bare_object; self; end
260
+ def bare_object
261
+ self
262
+ end
263
263
  alias_method :wrapped_object, :bare_object
264
264
 
265
265
  # Are we being invoked in a different thread from our owner?
@@ -286,7 +286,7 @@ module Celluloid
286
286
  if leaked?
287
287
  str << Celluloid::BARE_OBJECT_WARNING_MESSAGE
288
288
  else
289
- str << "Celluloid::CellProxy"
289
+ str << "Celluloid::Proxy::Cell"
290
290
  end
291
291
 
292
292
  str << "(#{self.class}:0x#{object_id.to_s(16)})"
@@ -297,7 +297,11 @@ module Celluloid
297
297
  str << "#{ivar}=#{instance_variable_get(ivar).inspect} "
298
298
  end
299
299
 
300
- str.sub!(/\s$/, '>')
300
+ str.sub!(/\s$/, ">")
301
+ end
302
+
303
+ def __arity
304
+ method(:initialize).arity
301
305
  end
302
306
  end
303
307
 
@@ -311,9 +315,9 @@ module Celluloid
311
315
  cause = case cause
312
316
  when String then RuntimeError.new(cause)
313
317
  when Exception then cause
314
- else raise TypeError, "Exception object/String expected, but #{cause.class} received"
318
+ else fail TypeError, "Exception object/String expected, but #{cause.class} received"
315
319
  end
316
- raise AbortError.new(cause)
320
+ fail AbortError.new(cause)
317
321
  end
318
322
 
319
323
  # Terminate this actor
@@ -338,7 +342,7 @@ module Celluloid
338
342
 
339
343
  # Obtain the UUID of the current call chain
340
344
  def call_chain_id
341
- CallChain.current_id
345
+ Internals::CallChain.current_id
342
346
  end
343
347
 
344
348
  # Obtain the running tasks for this actor
@@ -431,7 +435,7 @@ module Celluloid
431
435
  end
432
436
 
433
437
  # Perform a blocking or computationally intensive action inside an
434
- # asynchronous thread pool, allowing the sender to continue processing other
438
+ # asynchronous group of threads, allowing the sender to continue processing other
435
439
  # messages in its mailbox in the meantime
436
440
  def defer(&block)
437
441
  # This implementation relies on the present implementation of
@@ -451,66 +455,77 @@ module Celluloid
451
455
  end
452
456
 
453
457
  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+"
458
+ fail "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+"
455
459
  end
456
460
 
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)
461
+ require "celluloid/exceptions"
462
+
463
+ Celluloid.logger = Logger.new(STDERR)
464
+ Celluloid.shutdown_timeout = 10
465
+ Celluloid.log_actor_crashes = true
466
+
467
+ require "celluloid/calls"
468
+ require "celluloid/condition"
469
+ require "celluloid/thread"
470
+
471
+ require "celluloid/core_ext"
472
+
473
+ require "celluloid/system_events"
474
+
475
+ require "celluloid/proxies"
476
+
477
+ require "celluloid/mailbox"
478
+ require "celluloid/mailbox/evented"
479
+
480
+ require "celluloid/essentials"
481
+
482
+ require "celluloid/group"
483
+ require "celluloid/group/manager"
484
+ require "celluloid/group/spawner"
485
+ require "celluloid/group/pool" # TODO: Find way to only load this if being used.
486
+
487
+ require "celluloid/task"
488
+ require "celluloid/task/fibered"
489
+ require "celluloid/task/threaded" # TODO: Find way to only load this if being used.
490
+
491
+ require "celluloid/actor"
492
+ require "celluloid/cell"
493
+ require "celluloid/future"
494
+
495
+ require "celluloid/actor_system"
496
+
497
+ require "celluloid/deprecate" unless $CELLULOID_BACKPORTED == false
505
498
 
506
499
  $CELLULOID_MONITORING = false
500
+ Celluloid::Notices.output
507
501
 
508
502
  # Configure default systemwide settings
509
- Celluloid.task_class = Celluloid::TaskFiber
510
- Celluloid.logger = Logger.new(STDERR)
511
- Celluloid.shutdown_timeout = 10
512
503
 
513
- unless $CELLULOID_TEST
504
+ Celluloid.task_class =
505
+ begin
506
+ str = ENV["CELLULOID_TASK_CLASS"] || "Fibered"
507
+ Kernel.const_get(str)
508
+ rescue NameError
509
+ begin
510
+ Celluloid.const_get(str)
511
+ rescue NameError
512
+ Celluloid::Task.const_get(str)
513
+ end
514
+ end
515
+
516
+ Celluloid.group_class =
517
+ begin
518
+ str = ENV["CELLULOID_GROUP_CLASS"] || "Spawner"
519
+ Kernel.const_get(str)
520
+ rescue NameError
521
+ begin
522
+ Celluloid.const_get(str)
523
+ rescue NameError
524
+ Celluloid::Group.const_get(str)
525
+ end
526
+ end
527
+
528
+ unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
514
529
  Celluloid.register_shutdown
515
530
  Celluloid.init
516
531
  end