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,15 @@
1
+ module Celluloid
2
+ module Notices
3
+ class << self
4
+ @@notices = []
5
+
6
+ def backported
7
+ @@notices << [:debug, "Celluloid #{Celluloid::VERSION} is running in BACKPORTED mode. [ http://git.io/vJf3J ]"]
8
+ end
9
+
10
+ def output
11
+ @@notices.each { |type, notice| Celluloid::Internals::Logger.send type, notice }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Celluloid
2
+ module Proxy
3
+ end
4
+ end
5
+
6
+ require "celluloid/proxy/abstract"
7
+ require "celluloid/proxy/sync"
8
+ require "celluloid/proxy/cell"
9
+ require "celluloid/proxy/actor"
10
+ require "celluloid/proxy/async"
11
+ require "celluloid/proxy/future"
12
+ require "celluloid/proxy/block"
@@ -0,0 +1,24 @@
1
+ module Celluloid
2
+ module Proxy
3
+ # Base class of all Celluloid proxies
4
+ class Abstract < BasicObject
5
+ # Used for reflecting on proxy objects themselves
6
+ def __class__
7
+ Proxy::Abstract
8
+ end
9
+
10
+ # Needed for storing proxies in data structures
11
+ needed = [:object_id, :__id__, :hash, :private_methods] - instance_methods
12
+ if needed.any?
13
+ include ::Kernel.dup.module_eval {
14
+ undef_method(*(instance_methods - needed))
15
+ self
16
+ }
17
+
18
+ # rubinius bug? These methods disappear when we include hacked kernel
19
+ define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==)
20
+ alias_method(:equal?, :==) unless instance_methods.include?(:equal?)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,46 @@
1
+ module Celluloid
2
+ module Proxy
3
+ # A proxy which controls the Actor lifecycle
4
+ class Actor < Abstract
5
+ attr_reader :thread, :mailbox
6
+
7
+ # Used for reflecting on proxy objects themselves
8
+ def __class__
9
+ Proxy::Actor
10
+ end
11
+
12
+ def initialize(thread, mailbox)
13
+ @thread = thread
14
+ @mailbox = mailbox
15
+ end
16
+
17
+ def inspect
18
+ # TODO: use a system event to fetch actor state: tasks?
19
+ "#<Celluloid::Proxy::Actor(#{@mailbox.address}) alive>"
20
+ rescue DeadActorError
21
+ "#<Celluloid::Proxy::Actor(#{@mailbox.address}) dead>"
22
+ end
23
+
24
+ def alive?
25
+ @mailbox.alive?
26
+ end
27
+
28
+ def dead?
29
+ !alive?
30
+ end
31
+
32
+ # Terminate the associated actor
33
+ def terminate
34
+ terminate!
35
+ ::Celluloid::Actor.join(self)
36
+ nil
37
+ end
38
+
39
+ # Terminate the associated actor asynchronously
40
+ def terminate!
41
+ ::Kernel.raise DeadActorError, "actor already terminated" unless alive?
42
+ @mailbox << TerminationRequest.new
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ module Celluloid
2
+ module Proxy
3
+ # A proxy which sends asynchronous calls to an actor
4
+ class Async < Abstract
5
+ attr_reader :mailbox
6
+
7
+ # Used for reflecting on proxy objects themselves
8
+ def __class__
9
+ Proxy::Async
10
+ end
11
+
12
+ def initialize(mailbox, klass)
13
+ @mailbox = mailbox
14
+ @klass = klass
15
+ end
16
+
17
+ def inspect
18
+ "#<Celluloid::Proxy::Async(#{@klass})>"
19
+ end
20
+
21
+ def method_missing(meth, *args, &block)
22
+ if @mailbox == ::Thread.current[:celluloid_mailbox]
23
+ args.unshift meth
24
+ meth = :__send__
25
+ end
26
+
27
+ if block_given?
28
+ # FIXME: nicer exception
29
+ fail "Cannot use blocks with async yet"
30
+ end
31
+
32
+ @mailbox << Call::Async.new(meth, args, block)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ module Celluloid
2
+ module Proxy
3
+ class Block
4
+ def initialize(call, mailbox, block)
5
+ @call = call
6
+ @mailbox = mailbox
7
+ @block = block
8
+ @execution = :sender
9
+ end
10
+ attr_writer :execution
11
+ attr_reader :call, :block
12
+
13
+ def to_proc
14
+ if @execution == :sender
15
+ lambda do |*values|
16
+ if task = Thread.current[:celluloid_task]
17
+ @mailbox << Call::Block.new(self, Celluloid::Actor.current.mailbox, values)
18
+ # TODO: if respond fails, the Task will never be resumed
19
+ task.suspend(:invokeblock)
20
+ else
21
+ # FIXME: better exception
22
+ fail "No task to suspend"
23
+ end
24
+ end
25
+ else
26
+ @block
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,76 @@
1
+ module Celluloid
2
+ module Proxy
3
+ # A proxy object returned from Celluloid::Actor.new/new_link which converts
4
+ # the normal Ruby method protocol into an inter-actor message protocol
5
+ class Cell < Sync
6
+ # Used for reflecting on proxy objects themselves
7
+ def __class__
8
+ Proxy::Cell
9
+ end
10
+
11
+ def initialize(actor_proxy, mailbox, klass)
12
+ super(mailbox, klass)
13
+ @actor_proxy = actor_proxy
14
+ @sync_proxy = Sync.new(mailbox, klass)
15
+ @async_proxy = Async.new(mailbox, klass)
16
+ @future_proxy = Future.new(mailbox, klass)
17
+ end
18
+
19
+ def _send_(meth, *args, &block)
20
+ method_missing :__send__, meth, *args, &block
21
+ end
22
+
23
+ def inspect
24
+ method_missing :inspect
25
+ rescue DeadActorError
26
+ "#<Celluloid::Proxy::Cell(#{@klass}) dead>"
27
+ end
28
+
29
+ def method(name)
30
+ Internals::Method.new(self, name)
31
+ end
32
+
33
+ alias_method :sync, :method_missing
34
+
35
+ # Obtain an async proxy or explicitly invoke a named async method
36
+ def async(method_name = nil, *args, &block)
37
+ if method_name
38
+ @async_proxy.method_missing method_name, *args, &block
39
+ else
40
+ @async_proxy
41
+ end
42
+ end
43
+
44
+ # Obtain a future proxy or explicitly invoke a named future method
45
+ def future(method_name = nil, *args, &block)
46
+ if method_name
47
+ @future_proxy.method_missing method_name, *args, &block
48
+ else
49
+ @future_proxy
50
+ end
51
+ end
52
+
53
+ def alive?
54
+ @actor_proxy.alive?
55
+ end
56
+
57
+ def dead?
58
+ @actor_proxy.dead?
59
+ end
60
+
61
+ def thread
62
+ @actor_proxy.thread
63
+ end
64
+
65
+ # Terminate the associated actor
66
+ def terminate
67
+ @actor_proxy.terminate
68
+ end
69
+
70
+ # Terminate the associated actor asynchronously
71
+ def terminate!
72
+ @actor_proxy.terminate!
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,40 @@
1
+ module Celluloid
2
+ module Proxy
3
+ # A proxy which creates future calls to an actor
4
+ class Future < Abstract
5
+ attr_reader :mailbox
6
+
7
+ # Used for reflecting on proxy objects themselves
8
+ def __class__
9
+ Proxy::Future
10
+ end
11
+
12
+ def initialize(mailbox, klass)
13
+ @mailbox = mailbox
14
+ @klass = klass
15
+ end
16
+
17
+ def inspect
18
+ "#<Celluloid::Proxy::Future(#{@klass})>"
19
+ end
20
+
21
+ def method_missing(meth, *args, &block)
22
+ unless @mailbox.alive?
23
+ fail DeadActorError, "attempted to call a dead actor"
24
+ end
25
+
26
+ if block_given?
27
+ # FIXME: nicer exception
28
+ fail "Cannot use blocks with futures yet"
29
+ end
30
+
31
+ future = ::Celluloid::Future.new
32
+ call = Call::Sync.new(future, meth, args, block)
33
+
34
+ @mailbox << call
35
+
36
+ future
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ module Celluloid
2
+ module Proxy
3
+ # A proxy which sends synchronous calls to an actor
4
+ class Sync < Abstract
5
+ attr_reader :mailbox
6
+
7
+ # Used for reflecting on proxy objects themselves
8
+ def __class__
9
+ Proxy::Sync
10
+ end
11
+
12
+ def initialize(mailbox, klass)
13
+ @mailbox = mailbox
14
+ @klass = klass
15
+ end
16
+
17
+ def inspect
18
+ "#<Celluloid::Proxy::Sync(#{@klass})>"
19
+ end
20
+
21
+ def respond_to?(meth, include_private = false)
22
+ __class__.instance_methods.include?(meth) || method_missing(:respond_to?, meth, include_private)
23
+ end
24
+
25
+ def method_missing(meth, *args, &block)
26
+ unless @mailbox.alive?
27
+ fail DeadActorError, "attempted to call a dead actor"
28
+ end
29
+
30
+ if @mailbox == ::Thread.current[:celluloid_mailbox]
31
+ args.unshift meth
32
+ meth = :__send__
33
+ # actor = Thread.current[:celluloid_actor]
34
+ # actor = actor.behavior.subject.bare_object
35
+ # return actor.__send__(*args, &block)
36
+ end
37
+
38
+ call = Call::Sync.new(::Celluloid.mailbox, meth, args, block)
39
+ @mailbox << call
40
+ call.value
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,13 +1,12 @@
1
- require 'celluloid/rspec/example_actor_class'
2
- require 'celluloid/rspec/actor_examples'
3
- require 'celluloid/rspec/mailbox_examples'
4
- require 'celluloid/rspec/task_examples'
5
-
6
- module Celluloid
7
- # Timer accuracy enforced by the tests (50ms)
8
- TIMER_QUANTUM = 0.05
9
- end
1
+ require "celluloid/test"
10
2
 
11
3
  $CELLULOID_DEBUG = true
12
4
 
13
- require 'celluloid/test'
5
+ # Load shared examples and test support code for other gems to use.
6
+
7
+ %w(env logging split_logs sleep_and_wait reset_class_variables crash_checking stubbing coverage includer).each { |f|
8
+ require "#{File.expand_path('../../../spec/support', __FILE__)}/#{f}.rb"
9
+ }
10
+
11
+ Dir["#{File.expand_path('../../../spec/support/examples', __FILE__)}/*.rb"].map { |f| require f }
12
+ Dir["#{File.expand_path('../../../spec/shared', __FILE__)}/*.rb"].map { |f| require f }
@@ -1,16 +1,20 @@
1
1
  module Celluloid
2
2
  # High-priority internal system events
3
- class SystemEvent; end
3
+ class SystemEvent
4
+ class LinkingEvent < SystemEvent
5
+ # Shared initializer for LinkingRequest and LinkingResponse
6
+ def initialize(actor, type)
7
+ @actor = actor
8
+ @type = type.to_sym
9
+ fail ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
10
+ end
11
+ end
12
+ end
4
13
 
5
14
  # Request to link with another actor
6
- class LinkingRequest < SystemEvent
15
+ class LinkingRequest < SystemEvent::LinkingEvent
7
16
  attr_reader :actor, :type
8
17
 
9
- def initialize(actor, type)
10
- @actor, @type = actor, type.to_sym
11
- raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
12
- end
13
-
14
18
  def process(links)
15
19
  case type
16
20
  when :link then links << actor
@@ -22,13 +26,8 @@ module Celluloid
22
26
  end
23
27
 
24
28
  # Response to a link request
25
- class LinkingResponse
29
+ class LinkingResponse < SystemEvent::LinkingEvent
26
30
  attr_reader :actor, :type
27
-
28
- def initialize(actor, type)
29
- @actor, @type = actor, type.to_sym
30
- raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
31
- end
32
31
  end
33
32
 
34
33
  # An actor has exited for the given reason
@@ -36,7 +35,8 @@ module Celluloid
36
35
  attr_reader :actor, :reason
37
36
 
38
37
  def initialize(actor, reason = nil)
39
- @actor, @reason = actor, reason
38
+ @actor = actor
39
+ @reason = reason
40
40
  end
41
41
  end
42
42
 
@@ -55,7 +55,8 @@ module Celluloid
55
55
  # Signal a condition
56
56
  class SignalConditionRequest < SystemEvent
57
57
  def initialize(task, value)
58
- @task, @value = task, value
58
+ @task = task
59
+ @value = value
59
60
  end
60
61
  attr_reader :task, :value
61
62
 
@@ -16,7 +16,7 @@ module Celluloid
16
16
 
17
17
  # Obtain the current task
18
18
  def self.current
19
- Thread.current[:celluloid_task] or raise NotTaskError, "not within a task context"
19
+ Thread.current[:celluloid_task] || fail(NotTaskError, "not within a task context")
20
20
  end
21
21
 
22
22
  # Suspend the running task, deferring to the scheduler
@@ -34,13 +34,13 @@ module Celluloid
34
34
  @status = :new
35
35
 
36
36
  @exclusive = false
37
- @dangerous_suspend = @meta ? @meta.delete(:dangerous_suspend) : false
37
+ @dangerous_suspend = @meta ? @meta.dup.delete(:dangerous_suspend) : false
38
38
  @guard_warnings = false
39
39
 
40
40
  actor = Thread.current[:celluloid_actor]
41
- @chain_id = CallChain.current_id
41
+ @chain_id = Internals::CallChain.current_id
42
42
 
43
- raise NotActorError, "can't create tasks outside of actors" unless actor
43
+ fail NotActorError, "can't create tasks outside of actors" unless actor
44
44
  guard "can't create tasks inside of tasks" if Thread.current[:celluloid_task]
45
45
 
46
46
  create do
@@ -51,7 +51,7 @@ module Celluloid
51
51
  name_current_thread thread_metadata
52
52
 
53
53
  Thread.current[:celluloid_task] = self
54
- CallChain.current_id = @chain_id
54
+ Internals::CallChain.current_id = @chain_id
55
55
 
56
56
  actor.tasks << self
57
57
  yield
@@ -65,19 +65,19 @@ module Celluloid
65
65
  end
66
66
  end
67
67
 
68
- def create(&block)
69
- raise "Implement #{self.class}#create"
68
+ def create(&_block)
69
+ fail "Implement #{self.class}#create"
70
70
  end
71
71
 
72
72
  # Suspend the current task, changing the status to the given argument
73
73
  def suspend(status)
74
- raise "Cannot suspend while in exclusive mode" if exclusive?
75
- raise "Cannot suspend a task from outside of itself" unless Task.current == self
74
+ fail "Cannot suspend while in exclusive mode" if exclusive?
75
+ fail "Cannot suspend a task from outside of itself" unless Task.current == self
76
76
 
77
77
  @status = status
78
78
 
79
79
  if $CELLULOID_DEBUG && @dangerous_suspend
80
- Logger.with_backtrace(caller[2...8]) do |logger|
80
+ Internals::Logger.with_backtrace(caller[2...8]) do |logger|
81
81
  logger.warn "Dangerously suspending task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}"
82
82
  end
83
83
  end
@@ -85,7 +85,7 @@ module Celluloid
85
85
  value = signal
86
86
 
87
87
  @status = :running
88
- raise value if value.is_a?(Celluloid::ResumableError)
88
+ fail value if value.is_a?(Celluloid::ResumableError)
89
89
 
90
90
  value
91
91
  end
@@ -113,17 +113,18 @@ module Celluloid
113
113
 
114
114
  # Terminate this task
115
115
  def terminate
116
- raise "Cannot terminate an exclusive task" if exclusive?
116
+ fail "Cannot terminate an exclusive task" if exclusive?
117
117
 
118
118
  if running?
119
- Logger.with_backtrace(backtrace) do |logger|
120
- logger.warn "Terminating task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}"
119
+ Internals::Logger.with_backtrace(backtrace) do |logger|
120
+ type = @dangerous_suspend ? :warn : :debug
121
+ logger.send(type, "Terminating task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}")
121
122
  end
122
123
  exception = Task::TerminatedError.new("task was terminated")
123
124
  exception.set_backtrace(caller)
124
125
  resume exception
125
126
  else
126
- raise DeadTaskError, "task is already dead"
127
+ fail DeadTaskError, "task is already dead"
127
128
  end
128
129
  end
129
130
 
@@ -136,7 +137,9 @@ module Celluloid
136
137
  end
137
138
 
138
139
  # Is the current task still running?
139
- def running?; @status != :dead; end
140
+ def running?
141
+ @status != :dead
142
+ end
140
143
 
141
144
  # Nicer string inspect for tasks
142
145
  def inspect
@@ -145,9 +148,9 @@ module Celluloid
145
148
 
146
149
  def guard(message)
147
150
  if @guard_warnings
148
- Logger.warn message if $CELLULOID_DEBUG
151
+ Internals::Logger.warn message if $CELLULOID_DEBUG
149
152
  else
150
- raise message if $CELLULOID_DEBUG
153
+ fail message if $CELLULOID_DEBUG
151
154
  end
152
155
  end
153
156
 
@@ -171,6 +174,3 @@ module Celluloid
171
174
  end
172
175
  end
173
176
  end
174
-
175
- require 'celluloid/tasks/task_fiber'
176
- require 'celluloid/tasks/task_thread'