celluloid 0.18.0.pre → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +258 -39
  3. data/CONDUCT.md +13 -0
  4. data/CONTRIBUTING.md +39 -0
  5. data/README.md +54 -165
  6. data/REFACTOR.md +1 -0
  7. data/architecture.md +120 -0
  8. data/examples/basic_usage.rb +1 -1
  9. data/examples/configurations.rb +78 -0
  10. data/examples/futures.rb +1 -1
  11. data/examples/ring.rb +5 -4
  12. data/examples/simple_pmap.rb +1 -1
  13. data/examples/stack.rb +2 -2
  14. data/examples/supervisors_and_registry.rb +82 -0
  15. data/examples/timers.rb +2 -2
  16. data/lib/celluloid.rb +72 -47
  17. data/lib/celluloid/actor.rb +27 -17
  18. data/lib/celluloid/actor/system.rb +13 -29
  19. data/lib/celluloid/autostart.rb +5 -5
  20. data/lib/celluloid/call/async.rb +2 -0
  21. data/lib/celluloid/call/sync.rb +10 -3
  22. data/lib/celluloid/calls.rb +5 -12
  23. data/lib/celluloid/cell.rb +5 -9
  24. data/lib/celluloid/condition.rb +3 -3
  25. data/lib/celluloid/core_ext.rb +0 -2
  26. data/lib/celluloid/debug.rb +3 -0
  27. data/lib/celluloid/exceptions.rb +2 -2
  28. data/lib/celluloid/future.rb +7 -9
  29. data/lib/celluloid/group.rb +12 -8
  30. data/lib/celluloid/group/pool.rb +1 -3
  31. data/lib/celluloid/group/spawner.rb +2 -6
  32. data/lib/celluloid/internals/call_chain.rb +15 -0
  33. data/lib/celluloid/internals/cpu_counter.rb +62 -0
  34. data/lib/celluloid/internals/handlers.rb +42 -0
  35. data/lib/celluloid/internals/links.rb +38 -0
  36. data/lib/celluloid/internals/logger.rb +104 -0
  37. data/lib/celluloid/internals/method.rb +34 -0
  38. data/lib/celluloid/internals/properties.rb +32 -0
  39. data/lib/celluloid/internals/receivers.rb +64 -0
  40. data/lib/celluloid/internals/registry.rb +102 -0
  41. data/lib/celluloid/internals/responses.rb +46 -0
  42. data/lib/celluloid/internals/signals.rb +24 -0
  43. data/lib/celluloid/internals/stack.rb +74 -0
  44. data/lib/celluloid/internals/stack/dump.rb +12 -0
  45. data/lib/celluloid/internals/stack/states.rb +72 -0
  46. data/lib/celluloid/internals/stack/summary.rb +12 -0
  47. data/lib/celluloid/internals/task_set.rb +51 -0
  48. data/lib/celluloid/internals/thread_handle.rb +52 -0
  49. data/lib/celluloid/internals/uuid.rb +40 -0
  50. data/lib/celluloid/logging/incident.rb +21 -0
  51. data/lib/celluloid/logging/incident_logger.rb +147 -0
  52. data/lib/celluloid/logging/incident_reporter.rb +49 -0
  53. data/lib/celluloid/logging/log_event.rb +20 -0
  54. data/lib/celluloid/logging/ring_buffer.rb +64 -0
  55. data/lib/celluloid/mailbox.rb +22 -9
  56. data/lib/celluloid/mailbox/evented.rb +13 -5
  57. data/lib/celluloid/notifications.rb +95 -0
  58. data/lib/celluloid/pool.rb +6 -0
  59. data/lib/celluloid/probe.rb +81 -0
  60. data/lib/celluloid/proxy/abstract.rb +9 -9
  61. data/lib/celluloid/proxy/async.rb +1 -1
  62. data/lib/celluloid/proxy/block.rb +2 -2
  63. data/lib/celluloid/proxy/cell.rb +1 -1
  64. data/lib/celluloid/proxy/future.rb +2 -4
  65. data/lib/celluloid/proxy/sync.rb +1 -3
  66. data/lib/celluloid/rspec.rb +22 -33
  67. data/lib/celluloid/supervision.rb +17 -0
  68. data/lib/celluloid/supervision/configuration.rb +169 -0
  69. data/lib/celluloid/supervision/configuration/injections.rb +8 -0
  70. data/lib/celluloid/supervision/configuration/instance.rb +113 -0
  71. data/lib/celluloid/supervision/constants.rb +123 -0
  72. data/lib/celluloid/supervision/container.rb +144 -0
  73. data/lib/celluloid/supervision/container/behavior.rb +89 -0
  74. data/lib/celluloid/supervision/container/behavior/pool.rb +71 -0
  75. data/lib/celluloid/supervision/container/behavior/tree.rb +23 -0
  76. data/lib/celluloid/supervision/container/injections.rb +8 -0
  77. data/lib/celluloid/supervision/container/instance.rb +116 -0
  78. data/lib/celluloid/supervision/container/pool.rb +210 -0
  79. data/lib/celluloid/supervision/service.rb +27 -0
  80. data/lib/celluloid/supervision/supervise.rb +34 -0
  81. data/lib/celluloid/supervision/validation.rb +40 -0
  82. data/lib/celluloid/supervision/version.rb +5 -0
  83. data/lib/celluloid/system_events.rb +11 -6
  84. data/lib/celluloid/task.rb +25 -12
  85. data/lib/celluloid/task/fibered.rb +2 -0
  86. data/lib/celluloid/task/threaded.rb +3 -3
  87. data/lib/celluloid/test.rb +5 -2
  88. data/lib/celluloid/thread.rb +0 -2
  89. data/lib/celluloid/version.rb +1 -1
  90. data/spec/celluloid/block_spec.rb +29 -32
  91. data/spec/celluloid/calls_spec.rb +5 -15
  92. data/spec/celluloid/future_spec.rb +2 -2
  93. data/spec/celluloid/internals/cpu_counter_spec.rb +129 -0
  94. data/spec/celluloid/internals/links_spec.rb +43 -0
  95. data/spec/celluloid/internals/properties_spec.rb +40 -0
  96. data/spec/celluloid/internals/registry_spec.rb +62 -0
  97. data/spec/celluloid/internals/stack/dump_spec.rb +4 -0
  98. data/spec/celluloid/internals/stack/summary_spec.rb +4 -0
  99. data/spec/celluloid/internals/thread_handle_spec.rb +60 -0
  100. data/spec/celluloid/internals/uuid_spec.rb +9 -0
  101. data/spec/celluloid/logging/ring_buffer_spec.rb +36 -0
  102. data/spec/celluloid/mailbox/evented_spec.rb +11 -22
  103. data/spec/celluloid/misc/leak_spec.rb +3 -4
  104. data/spec/celluloid/notifications_spec.rb +140 -0
  105. data/spec/celluloid/probe_spec.rb +102 -0
  106. data/spec/celluloid/proxy_spec.rb +30 -30
  107. data/spec/celluloid/supervision/behavior_spec.rb +74 -0
  108. data/spec/celluloid/supervision/configuration_spec.rb +181 -0
  109. data/spec/celluloid/supervision/container_spec.rb +72 -0
  110. data/spec/celluloid/supervision/instance_spec.rb +13 -0
  111. data/spec/celluloid/supervision/root_spec.rb +28 -0
  112. data/spec/celluloid/supervision/supervisor_spec.rb +93 -0
  113. data/spec/celluloid/task/fibered_spec.rb +1 -3
  114. data/spec/celluloid/task/threaded_spec.rb +1 -3
  115. data/spec/shared/actor_examples.rb +58 -33
  116. data/spec/shared/group_examples.rb +2 -2
  117. data/spec/shared/mailbox_examples.rb +1 -1
  118. data/spec/shared/stack_examples.rb +87 -0
  119. data/spec/shared/task_examples.rb +2 -3
  120. data/spec/spec_helper.rb +2 -4
  121. data/spec/support/configure_rspec.rb +2 -3
  122. data/spec/support/coverage.rb +2 -4
  123. data/spec/support/crash_checking.rb +2 -2
  124. data/spec/support/examples/actor_class.rb +3 -8
  125. data/spec/support/examples/call_class.rb +2 -2
  126. data/spec/support/examples/container_class.rb +35 -0
  127. data/spec/support/examples/evented_mailbox_class.rb +1 -2
  128. data/spec/support/examples/stack_classes.rb +58 -0
  129. data/spec/support/examples/stack_methods.rb +23 -0
  130. data/spec/support/examples/subordinate_class.rb +19 -0
  131. data/spec/support/logging.rb +2 -34
  132. data/spec/support/loose_threads.rb +3 -16
  133. data/spec/support/reset_class_variables.rb +5 -1
  134. data/spec/support/stubbing.rb +1 -1
  135. metadata +91 -323
  136. data/culture/CONDUCT.md +0 -38
  137. data/culture/GSoC/1010-why_we_will_participate.md +0 -17
  138. data/culture/GSoC/1020-how_mentors_stay_engaged.md +0 -7
  139. data/culture/GSoC/1030-keeping_students_on_schedule.md +0 -9
  140. data/culture/GSoC/1040-getting_students_involved.md +0 -5
  141. data/culture/GSoC/1050-student_involvement_after.md +0 -5
  142. data/culture/GSoC/README.md +0 -16
  143. data/culture/Gemfile +0 -9
  144. data/culture/LICENSE.txt +0 -22
  145. data/culture/README.md +0 -22
  146. data/culture/Rakefile +0 -5
  147. data/culture/SYNC.md +0 -70
  148. data/culture/celluloid-culture.gemspec +0 -18
  149. data/culture/gems/README.md +0 -39
  150. data/culture/gems/dependencies.yml +0 -93
  151. data/culture/gems/loader.rb +0 -101
  152. data/culture/rubocop/README.md +0 -38
  153. data/culture/rubocop/lint.yml +0 -8
  154. data/culture/rubocop/metrics.yml +0 -15
  155. data/culture/rubocop/perf.yml +0 -0
  156. data/culture/rubocop/rubocop.yml +0 -5
  157. data/culture/rubocop/style.yml +0 -61
  158. data/culture/spec/gems_spec.rb +0 -2
  159. data/culture/spec/spec_helper.rb +0 -0
  160. data/culture/spec/sync_spec.rb +0 -2
  161. data/culture/sync.rb +0 -56
  162. data/culture/tasks/rspec.rake +0 -5
  163. data/culture/tasks/rubocop.rake +0 -2
  164. data/lib/celluloid/actor/manager.rb +0 -7
  165. data/lib/celluloid/backported.rb +0 -2
  166. data/lib/celluloid/current.rb +0 -2
  167. data/lib/celluloid/deprecate.rb +0 -34
  168. data/lib/celluloid/fiber.rb +0 -32
  169. data/lib/celluloid/managed.rb +0 -3
  170. data/lib/celluloid/notices.rb +0 -15
  171. data/spec/deprecate/actor_system_spec.rb +0 -72
  172. data/spec/deprecate/block_spec.rb +0 -52
  173. data/spec/deprecate/calls_spec.rb +0 -39
  174. data/spec/deprecate/evented_mailbox_spec.rb +0 -34
  175. data/spec/deprecate/future_spec.rb +0 -32
  176. data/spec/deprecate/internal_pool_spec.rb +0 -4
  177. data/spec/support/env.rb +0 -21
@@ -7,33 +7,18 @@ module Celluloid
7
7
  extend Forwardable
8
8
  def_delegators :@registry, :[], :get, :[]=, :set, :delete
9
9
 
10
- ROOT_SERVICES = begin
11
- root_services = [
12
- {
13
- as: :notifications_fanout,
14
- type: Celluloid::Notifications::Fanout,
15
- },
16
- {
17
- as: :incident_reporter,
18
- type: Celluloid::IncidentReporter,
19
- args: [STDERR],
20
- },
21
- {
22
- as: :public_services,
23
- type: Celluloid::Supervision::Service::Public,
24
- accessors: [:services],
25
- supervise: [],
26
- },
27
- ]
28
- if $CELLULOID_MANAGED
29
- root_services << {
30
- as: :actor_manager,
31
- type: Celluloid::Actor::Manager,
32
- accessors: [:manager],
33
- }
34
- end
35
- root_services
36
- end
10
+ ROOT_SERVICES = [
11
+ {
12
+ as: :notifications_fanout,
13
+ type: Celluloid::Notifications::Fanout
14
+ },
15
+ {
16
+ as: :public_services,
17
+ type: Celluloid::Supervision::Service::Public,
18
+ accessors: [:services],
19
+ supervise: []
20
+ }
21
+ ].freeze
37
22
 
38
23
  attr_reader :registry, :group
39
24
 
@@ -59,7 +44,6 @@ module Celluloid
59
44
  within do
60
45
  @root = Supervision::Service::Root.define
61
46
  @tree = root_configuration.deploy
62
- # de root_services[:group_manager].manage! @group
63
47
  end
64
48
  true
65
49
  end
@@ -119,7 +103,7 @@ module Celluloid
119
103
  def shutdown
120
104
  actors = running
121
105
  Timeout.timeout(shutdown_timeout) do
122
- Internals::Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0
106
+ Internals::Logger.debug "Terminating #{actors.size} #{actors.size > 1 ? 'actors' : 'actor'}..." unless actors.empty?
123
107
 
124
108
  # Actors cannot self-terminate, you must do it for them
125
109
  actors.each do |actor|
@@ -1,8 +1,8 @@
1
1
  require "celluloid"
2
2
 
3
- Celluloid.start
3
+ Celluloid.boot
4
4
 
5
- unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
6
- Celluloid.register_shutdown
7
- Celluloid.init
8
- end
5
+ # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
6
+ # rubocop:disable Style/GlobalVars
7
+ Celluloid.register_shutdown unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
8
+ # rubocop:enable Style/GlobalVars
@@ -7,7 +7,9 @@ module Celluloid
7
7
  super(obj)
8
8
  rescue AbortError => ex
9
9
  # Swallow aborted async calls, as they indicate the sender made a mistake
10
+ # rubocop:disable Metrics/LineLength
10
11
  Internals::Logger.debug("#{obj.class}: async call `#{@method}` aborted!\n#{Internals::Logger.format_exception(ex.cause)}")
12
+ # rubocop:enable Metrics/LineLength
11
13
  ensure
12
14
  Internals::CallChain.current_id = nil
13
15
  end
@@ -4,7 +4,14 @@ module Celluloid
4
4
  class Sync < Call
5
5
  attr_reader :sender, :task, :chain_id
6
6
 
7
- def initialize(sender, method, arguments = [], block = nil, task = Thread.current[:celluloid_task], chain_id = Internals::CallChain.current_id)
7
+ def initialize(
8
+ sender,
9
+ method,
10
+ arguments = [],
11
+ block = nil,
12
+ task = Thread.current[:celluloid_task],
13
+ chain_id = Internals::CallChain.current_id
14
+ )
8
15
  super(method, arguments, block)
9
16
  @sender = sender
10
17
  @task = task
@@ -29,7 +36,7 @@ module Celluloid
29
36
  end
30
37
 
31
38
  def cleanup
32
- exception = DeadActorError.new("attempted to call a dead actor: #{self.method}")
39
+ exception = DeadActorError.new("attempted to call a dead actor: #{method}")
33
40
  respond Internals::Response::Error.new(self, exception)
34
41
  end
35
42
 
@@ -46,7 +53,7 @@ module Celluloid
46
53
  end
47
54
 
48
55
  def wait
49
- while true
56
+ loop do
50
57
  message = Celluloid.mailbox.receive do |msg|
51
58
  msg.respond_to?(:call) && msg.call == self
52
59
  end
@@ -10,7 +10,7 @@ module Celluloid
10
10
  if block
11
11
  if Celluloid.exclusive?
12
12
  # FIXME: nicer exception
13
- fail "Cannot execute blocks on sender in exclusive mode"
13
+ raise "Cannot execute blocks on sender in exclusive mode"
14
14
  end
15
15
  @block = Proxy::Block.new(Celluloid.mailbox, self, block)
16
16
  else
@@ -24,14 +24,7 @@ module Celluloid
24
24
 
25
25
  def dispatch(obj)
26
26
  check(obj)
27
- _b = @block && @block.to_proc
28
- obj.public_send(@method, *@arguments, &_b)
29
- # rescue Celluloid::TaskTimeout => ex
30
- # raise ex unless ( @retry += 1 ) <= RETRY_CALL_LIMIT
31
- # puts "retrying"
32
- # Internals::Logger.warn("TaskTimeout at Call dispatch. Retrying in #{RETRY_CALL_WAIT} seconds. ( Attempt #{@retry} of #{RETRY_CALL_LIMIT} )")
33
- # sleep RETRY_CALL_WAIT
34
- # retry
27
+ obj.public_send(@method, *@arguments, &(@block && @block.to_proc))
35
28
  end
36
29
 
37
30
  def check(obj)
@@ -48,18 +41,18 @@ module Celluloid
48
41
  if @arguments.size != arity
49
42
  e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{arity})")
50
43
  e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`")
51
- fail e
44
+ raise e
52
45
  end
53
46
  elsif arity < -1
54
47
  mandatory_args = -arity - 1
55
48
  if arguments.size < mandatory_args
56
49
  e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{mandatory_args}+)")
57
50
  e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`")
58
- fail e
51
+ raise e
59
52
  end
60
53
  end
61
54
  rescue => ex
62
- raise AbortError.new(ex)
55
+ raise AbortError, ex
63
56
  end
64
57
  end
65
58
  end
@@ -36,9 +36,7 @@ module Celluloid
36
36
  @actor.handle(Call::Block) do |message|
37
37
  task(:invoke_block) { message.dispatch }
38
38
  end
39
- @actor.handle(Internals::Response::Block, Internals::Response) do |message|
40
- message.dispatch
41
- end
39
+ @actor.handle(Internals::Response::Block, Internals::Response, &:dispatch)
42
40
 
43
41
  @actor.start
44
42
  @proxy = (options[:proxy_class] || Proxy::Cell).new(@actor.mailbox, @actor.proxy, @subject.class.to_s)
@@ -57,18 +55,16 @@ module Celluloid
57
55
  meth = call.method
58
56
  meth = call.arguments.first if meth == :__send__
59
57
  if @receiver_block_executions && meth
60
- if @receiver_block_executions.include?(meth.to_sym)
61
- call.execute_block_on_receiver
62
- end
58
+ call.execute_block_on_receiver if @receiver_block_executions.include?(meth.to_sym)
63
59
  end
64
60
 
65
- task(:call, meth, {call: call, subject: @subject},
61
+ task(:call, meth, { call: call, subject: @subject },
66
62
  dangerous_suspend: meth == :initialize, &Cell.dispatch)
67
63
  end
68
64
 
69
65
  def task(task_type, method_name = nil, subject = nil, meta = nil, &_block)
70
66
  meta ||= {}
71
- meta.merge!(method_name: method_name)
67
+ meta[:method_name] = method_name
72
68
  @actor.task(task_type, meta) do
73
69
  if @exclusive_methods && method_name && @exclusive_methods.include?(method_name.to_sym)
74
70
  Celluloid.exclusive { yield subject }
@@ -94,7 +90,7 @@ module Celluloid
94
90
  def shutdown
95
91
  return unless @finalizer && @subject.respond_to?(@finalizer, true)
96
92
 
97
- task(:finalizer, @finalizer, {call: @finalizer, subject: @subject},
93
+ task(:finalizer, @finalizer, { call: @finalizer, subject: @subject },
98
94
  dangerous_suspend: true, &Cell.shutdown)
99
95
  end
100
96
  end
@@ -34,7 +34,7 @@ module Celluloid
34
34
 
35
35
  # Wait for the given signal and return the associated value
36
36
  def wait(timeout = nil)
37
- fail ConditionError, "cannot wait for signals while exclusive" if Celluloid.exclusive?
37
+ raise ConditionError, "cannot wait for signals while exclusive" if Celluloid.exclusive?
38
38
 
39
39
  if actor = Thread.current[:celluloid_actor]
40
40
  task = Task.current
@@ -57,7 +57,7 @@ module Celluloid
57
57
 
58
58
  result = Celluloid.suspend :condwait, waiter
59
59
  timer.cancel if timer
60
- fail result if result.is_a?(ConditionError)
60
+ raise result if result.is_a?(ConditionError)
61
61
  return yield(result) if block_given?
62
62
  result
63
63
  end
@@ -83,6 +83,6 @@ module Celluloid
83
83
  end
84
84
  end
85
85
 
86
- alias_method :inspect, :to_s
86
+ alias inspect to_s
87
87
  end
88
88
  end
@@ -1,5 +1,3 @@
1
- require "celluloid/fiber"
2
-
3
1
  class Thread
4
2
  attr_accessor :uuid_counter, :uuid_limit
5
3
 
@@ -1 +1,4 @@
1
+ # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
2
+ # rubocop:disable Style/GlobalVars
1
3
  $CELLULOID_DEBUG = true
4
+ # rubocop:enable Style/GlobalVars
@@ -1,6 +1,6 @@
1
1
  module Celluloid
2
2
  class Error < StandardError; end
3
- class Interruption < Exception; end
3
+ class Interruption < RuntimeError; end
4
4
  class TimedOut < Celluloid::Interruption; end # Distinguished from `Timeout`
5
5
  class StillActive < Celluloid::Error; end
6
6
  class NotActive < Celluloid::Error; end
@@ -9,7 +9,7 @@ module Celluloid
9
9
  class NotTaskError < Celluloid::Error; end # Asked to do task-related things outside a task
10
10
  class DeadTaskError < Celluloid::Error; end # Trying to resume a dead task
11
11
  class TaskTerminated < Celluloid::Interruption; end # Kill a running task after terminate
12
- class TaskTimeout < Celluloid::TimedOut; end # A timeout occured before the given request could complete
12
+ class TaskTimeout < Celluloid::TimedOut; end # A timeout occurred before the given request could complete
13
13
  class ConditionError < Celluloid::Error; end
14
14
  class AbortError < Celluloid::Error # The sender made an error, not the current actor
15
15
  attr_reader :cause
@@ -1,5 +1,3 @@
1
- require "thread"
2
-
3
1
  module Celluloid
4
2
  # Celluloid::Future objects allow methods and blocks to run in the
5
3
  # background, their values requested later
@@ -50,7 +48,7 @@ module Celluloid
50
48
  # Execute the given method in future context
51
49
  def execute(receiver, method, args, block)
52
50
  @mutex.synchronize do
53
- fail "already calling" if @call
51
+ raise "already calling" if @call
54
52
  @call = Call::Sync.new(self, method, args, block)
55
53
  end
56
54
 
@@ -93,12 +91,12 @@ module Celluloid
93
91
  end
94
92
 
95
93
  if result
96
- (result.respond_to?(:value)) ? result.value : result
94
+ result.respond_to?(:value) ? result.value : result
97
95
  else
98
- fail TimedOut, "Timed out"
96
+ raise TimedOut, "Timed out"
99
97
  end
100
98
  end
101
- alias_method :call, :value
99
+ alias call value
102
100
 
103
101
  # Signal this future with the given result value
104
102
  def signal(value)
@@ -106,7 +104,7 @@ module Celluloid
106
104
  result = Result.new(value, self)
107
105
 
108
106
  @mutex.synchronize do
109
- fail "the future has already happened!" if @ready
107
+ raise "the future has already happened!" if @ready
110
108
 
111
109
  if @forwards
112
110
  @forwards.is_a?(Array) ? @forwards.each { |f| f << result } : @forwards << result
@@ -116,7 +114,7 @@ module Celluloid
116
114
  @ready = true
117
115
  end
118
116
  end
119
- alias_method :<<, :signal
117
+ alias << signal
120
118
 
121
119
  def cancel(error)
122
120
  response = Internals::Response::Error.new(@call, error)
@@ -127,7 +125,7 @@ module Celluloid
127
125
  end
128
126
 
129
127
  # Inspect this Celluloid::Future
130
- alias_method :inspect, :to_s
128
+ alias inspect to_s
131
129
 
132
130
  # Wrapper for result values to distinguish them in mailboxes
133
131
  class Result
@@ -3,14 +3,14 @@ module Celluloid
3
3
  attr_accessor :group
4
4
 
5
5
  def initialize
6
- @pid = $$
6
+ @pid = $PROCESS_ID
7
7
  @mutex = Mutex.new
8
8
  @group = []
9
9
  @running = true
10
10
  end
11
11
 
12
12
  def assert_active
13
- fail Celluloid::NotActive unless active?
13
+ raise Celluloid::NotActive unless active?
14
14
  end
15
15
 
16
16
  def assert_inactive
@@ -18,7 +18,7 @@ module Celluloid
18
18
  if RUBY_PLATFORM == "java"
19
19
  Celluloid.logger.warn "Group is still active"
20
20
  else
21
- fail Celluloid::StillActive
21
+ raise Celluloid::StillActive
22
22
  end
23
23
  end
24
24
 
@@ -27,7 +27,7 @@ module Celluloid
27
27
  end
28
28
 
29
29
  def forked?
30
- @pid != $$
30
+ @pid != $PROCESS_ID
31
31
  end
32
32
 
33
33
  def to_a
@@ -40,7 +40,11 @@ module Celluloid
40
40
  def purge(thread)
41
41
  @mutex.synchronize do
42
42
  @group.delete(thread)
43
- thread.kill rescue nil
43
+ begin
44
+ thread.kill
45
+ rescue
46
+ nil
47
+ end
44
48
  end
45
49
  end
46
50
 
@@ -53,15 +57,15 @@ module Celluloid
53
57
  end
54
58
 
55
59
  def get
56
- fail NotImplementedError
60
+ raise NotImplementedError
57
61
  end
58
62
 
59
63
  def create
60
- fail NotImplementedError
64
+ raise NotImplementedError
61
65
  end
62
66
 
63
67
  def shutdown
64
- fail NotImplementedError
68
+ raise NotImplementedError
65
69
  end
66
70
  end
67
71
  end
@@ -1,5 +1,3 @@
1
- require "thread"
2
-
3
1
  module Celluloid
4
2
  class Group
5
3
  class Pool < Group
@@ -12,7 +10,7 @@ module Celluloid
12
10
  super
13
11
  @mutex = Mutex.new
14
12
  @idle_threads = []
15
- @group = []
13
+ @group = []
16
14
  @busy_size = 0
17
15
  @idle_size = 0
18
16
 
@@ -1,5 +1,3 @@
1
- require "thread"
2
-
3
1
  module Celluloid
4
2
  class Group
5
3
  class Spawner < Group
@@ -11,7 +9,7 @@ module Celluloid
11
9
 
12
10
  def get(&block)
13
11
  assert_active
14
- fail ArgumentError.new("No block sent to Spawner.get()") unless block_given?
12
+ raise ArgumentError, "No block sent to Spawner.get()" unless block_given?
15
13
  instantiate block
16
14
  end
17
15
 
@@ -52,9 +50,7 @@ module Celluloid
52
50
  Internals::Logger.crash("thread crashed", ex)
53
51
  Thread.current[:celluloid_thread_state] = :error
54
52
  ensure
55
- unless Thread.current[:celluloid_thread_state] == :error
56
- Thread.current[:celluloid_thread_state] = :finished
57
- end
53
+ Thread.current[:celluloid_thread_state] = :finished unless Thread.current[:celluloid_thread_state] == :error
58
54
  @mutex.synchronize { @group.delete Thread.current }
59
55
  Thread.exit
60
56
  end
@@ -0,0 +1,15 @@
1
+ module Celluloid
2
+ module Internals
3
+ class CallChain
4
+ def self.current_id=(value)
5
+ Thread.current[:celluloid_chain_id] = value
6
+ task = Thread.current[:celluloid_task]
7
+ task.chain_id = value if task
8
+ end
9
+
10
+ def self.current_id
11
+ Thread.current[:celluloid_chain_id]
12
+ end
13
+ end
14
+ end
15
+ end