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
@@ -1,31 +0,0 @@
1
- module Celluloid
2
- # A proxy which sends asynchronous calls to an actor
3
- class AsyncProxy < AbstractProxy
4
- attr_reader :mailbox
5
-
6
- # Used for reflecting on proxy objects themselves
7
- def __class__; AsyncProxy; end
8
-
9
- def initialize(mailbox, klass)
10
- @mailbox, @klass = mailbox, klass
11
- end
12
-
13
- def inspect
14
- "#<Celluloid::AsyncProxy(#{@klass})>"
15
- end
16
-
17
- def method_missing(meth, *args, &block)
18
- if @mailbox == ::Thread.current[:celluloid_mailbox]
19
- args.unshift meth
20
- meth = :__send__
21
- end
22
-
23
- if block_given?
24
- # FIXME: nicer exception
25
- raise "Cannot use blocks with async yet"
26
- end
27
-
28
- @mailbox << AsyncCall.new(meth, args, block)
29
- end
30
- end
31
- end
@@ -1,29 +0,0 @@
1
- module Celluloid
2
- class BlockProxy
3
- def initialize(call, mailbox, block)
4
- @call = call
5
- @mailbox = mailbox
6
- @block = block
7
- @execution = :sender
8
- end
9
- attr_writer :execution
10
- attr_reader :call, :block
11
-
12
- def to_proc
13
- if @execution == :sender
14
- lambda do |*values|
15
- if task = Thread.current[:celluloid_task]
16
- @mailbox << BlockCall.new(self, Actor.current.mailbox, values)
17
- # TODO: if respond fails, the Task will never be resumed
18
- task.suspend(:invokeblock)
19
- else
20
- # FIXME: better exception
21
- raise "No task to suspend"
22
- end
23
- end
24
- else
25
- @block
26
- end
27
- end
28
- end
29
- end
@@ -1,68 +0,0 @@
1
- module Celluloid
2
- # A proxy object returned from Celluloid::Actor.new/new_link which converts
3
- # the normal Ruby method protocol into an inter-actor message protocol
4
- class CellProxy < SyncProxy
5
- # Used for reflecting on proxy objects themselves
6
- def __class__; CellProxy; end
7
-
8
- def initialize(actor_proxy, mailbox, klass)
9
- super(mailbox, klass)
10
- @actor_proxy = actor_proxy
11
- @sync_proxy = SyncProxy.new(mailbox, klass)
12
- @async_proxy = AsyncProxy.new(mailbox, klass)
13
- @future_proxy = FutureProxy.new(mailbox, klass)
14
- end
15
-
16
- def _send_(meth, *args, &block)
17
- method_missing :__send__, meth, *args, &block
18
- end
19
-
20
- def inspect
21
- method_missing :inspect
22
- rescue DeadActorError
23
- "#<Celluloid::CellProxy(#{@klass}) dead>"
24
- end
25
-
26
- def method(name)
27
- Method.new(self, name)
28
- end
29
-
30
- alias_method :sync, :method_missing
31
-
32
- # Obtain an async proxy or explicitly invoke a named async method
33
- def async(method_name = nil, *args, &block)
34
- if method_name
35
- @async_proxy.method_missing method_name, *args, &block
36
- else
37
- @async_proxy
38
- end
39
- end
40
-
41
- # Obtain a future proxy or explicitly invoke a named future method
42
- def future(method_name = nil, *args, &block)
43
- if method_name
44
- @future_proxy.method_missing method_name, *args, &block
45
- else
46
- @future_proxy
47
- end
48
- end
49
-
50
- def alive?
51
- @actor_proxy.alive?
52
- end
53
-
54
- def thread
55
- @actor_proxy.thread
56
- end
57
-
58
- # Terminate the associated actor
59
- def terminate
60
- @actor_proxy.terminate
61
- end
62
-
63
- # Terminate the associated actor asynchronously
64
- def terminate!
65
- @actor_proxy.terminate!
66
- end
67
- end
68
- end
@@ -1,35 +0,0 @@
1
- module Celluloid
2
- # A proxy which creates future calls to an actor
3
- class FutureProxy < AbstractProxy
4
- attr_reader :mailbox
5
-
6
- # Used for reflecting on proxy objects themselves
7
- def __class__; FutureProxy; end
8
-
9
- def initialize(mailbox, klass)
10
- @mailbox, @klass = mailbox, klass
11
- end
12
-
13
- def inspect
14
- "#<Celluloid::FutureProxy(#{@klass})>"
15
- end
16
-
17
- def method_missing(meth, *args, &block)
18
- unless @mailbox.alive?
19
- raise DeadActorError, "attempted to call a dead actor"
20
- end
21
-
22
- if block_given?
23
- # FIXME: nicer exception
24
- raise "Cannot use blocks with futures yet"
25
- end
26
-
27
- future = Future.new
28
- call = SyncCall.new(future, meth, args, block)
29
-
30
- @mailbox << call
31
-
32
- future
33
- end
34
- end
35
- end
@@ -1,36 +0,0 @@
1
- module Celluloid
2
- # A proxy which sends synchronous calls to an actor
3
- class SyncProxy < AbstractProxy
4
- attr_reader :mailbox
5
-
6
- # Used for reflecting on proxy objects themselves
7
- def __class__; SyncProxy; end
8
-
9
- def initialize(mailbox, klass)
10
- @mailbox, @klass = mailbox, klass
11
- end
12
-
13
- def inspect
14
- "#<Celluloid::SyncProxy(#{@klass})>"
15
- end
16
-
17
- def respond_to?(meth, include_private = false)
18
- __class__.instance_methods.include?(meth) || method_missing(:respond_to?, meth, include_private)
19
- end
20
-
21
- def method_missing(meth, *args, &block)
22
- unless @mailbox.alive?
23
- raise DeadActorError, "attempted to call a dead actor"
24
- end
25
-
26
- if @mailbox == ::Thread.current[:celluloid_mailbox]
27
- args.unshift meth
28
- meth = :__send__
29
- end
30
-
31
- call = SyncCall.new(::Celluloid.mailbox, meth, args, block)
32
- @mailbox << call
33
- call.value
34
- end
35
- end
36
- end
@@ -1,63 +0,0 @@
1
- require 'set'
2
-
3
- require 'timers'
4
-
5
- module Celluloid
6
- # Allow methods to directly interact with the actor protocol
7
- class Receivers
8
- def initialize(timers)
9
- @receivers = Set.new
10
- @timers = timers
11
- end
12
-
13
- # Receive an asynchronous message
14
- def receive(timeout = nil, &block)
15
- if Celluloid.exclusive?
16
- Celluloid.mailbox.receive(timeout, &block)
17
- else
18
- receiver = Receiver.new block
19
-
20
- if timeout
21
- receiver.timer = @timers.after(timeout) do
22
- @receivers.delete receiver
23
- receiver.resume
24
- end
25
- end
26
-
27
- @receivers << receiver
28
- Task.suspend :receiving
29
- end
30
- end
31
-
32
- # Handle incoming messages
33
- def handle_message(message)
34
- receiver = @receivers.find { |r| r.match(message) }
35
- return unless receiver
36
-
37
- @receivers.delete receiver
38
- receiver.timer.cancel if receiver.timer
39
- receiver.resume message
40
- message
41
- end
42
- end
43
-
44
- # Methods blocking on a call to receive
45
- class Receiver
46
- attr_accessor :timer
47
-
48
- def initialize(block)
49
- @block = block
50
- @task = Task.current
51
- @timer = nil
52
- end
53
-
54
- # Match a message with this receiver's block
55
- def match(message)
56
- @block ? @block.call(message) : true
57
- end
58
-
59
- def resume(message = nil)
60
- @task.resume message
61
- end
62
- end
63
- end
@@ -1,57 +0,0 @@
1
- require 'thread'
2
-
3
- module Celluloid
4
- # The Registry allows us to refer to specific actors by human-meaningful names
5
- class Registry
6
- def initialize
7
- @registry = {}
8
- @registry_lock = Mutex.new
9
- end
10
-
11
- # Register an Actor
12
- def []=(name, actor)
13
- actor_singleton = class << actor; self; end
14
- unless actor_singleton.ancestors.include? AbstractProxy
15
- raise TypeError, "not an actor"
16
- end
17
-
18
- @registry_lock.synchronize do
19
- @registry[name.to_sym] = actor
20
- end
21
-
22
- actor.mailbox << NamingRequest.new(name.to_sym)
23
- end
24
-
25
- # Retrieve an actor by name
26
- def [](name)
27
- @registry_lock.synchronize do
28
- @registry[name.to_sym]
29
- end
30
- end
31
-
32
- alias_method :get, :[]
33
- alias_method :set, :[]=
34
-
35
- def delete(name)
36
- @registry_lock.synchronize do
37
- @registry.delete name.to_sym
38
- end
39
- end
40
-
41
- # List all registered actors by name
42
- def names
43
- @registry_lock.synchronize { @registry.keys }
44
- end
45
-
46
- # removes and returns all registered actors as a hash of `name => actor`
47
- # can be used in testing to clear the registry
48
- def clear
49
- hash = nil
50
- @registry_lock.synchronize do
51
- hash = @registry.dup
52
- @registry.clear
53
- end
54
- hash
55
- end
56
- end
57
- end
@@ -1,44 +0,0 @@
1
- module Celluloid
2
- # Responses to calls
3
- class Response
4
- attr_reader :call, :value
5
-
6
- def initialize(call, value)
7
- @call, @value = call, value
8
- end
9
-
10
- def dispatch
11
- @call.task.resume self
12
- end
13
- end
14
-
15
- # Call completed successfully
16
- class SuccessResponse < Response; end
17
-
18
- # Call was aborted due to sender error
19
- class ErrorResponse < Response
20
- def value
21
- ex = super
22
- ex = ex.cause if ex.is_a? AbortError
23
-
24
- if ex.backtrace
25
- ex.backtrace << "(celluloid):0:in `remote procedure call'"
26
- ex.backtrace.concat(caller)
27
- end
28
-
29
- raise ex
30
- end
31
- end
32
-
33
- class BlockResponse
34
- def initialize(call, result)
35
- @call = call
36
- @result = result
37
- end
38
-
39
- def dispatch
40
- @call.task.resume(@result)
41
- end
42
- end
43
-
44
- end