concurrent-ruby 0.6.0 → 0.7.0.rc0

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -51
  3. data/lib/concurrent/actress/ad_hoc.rb +6 -0
  4. data/lib/concurrent/actress/context.rb +10 -8
  5. data/lib/concurrent/actress/core.rb +44 -20
  6. data/lib/concurrent/actress/core_delegations.rb +5 -0
  7. data/lib/concurrent/actress/envelope.rb +21 -5
  8. data/lib/concurrent/actress/reference.rb +5 -5
  9. data/lib/concurrent/actress.rb +152 -6
  10. data/lib/concurrent/agent.rb +9 -9
  11. data/lib/concurrent/atomic.rb +46 -0
  12. data/lib/concurrent/atomic_reference/concurrent_update_error.rb +7 -0
  13. data/lib/concurrent/atomic_reference/delegated_update.rb +28 -0
  14. data/lib/concurrent/atomic_reference/direct_update.rb +28 -0
  15. data/lib/concurrent/atomic_reference/jruby.rb +8 -0
  16. data/lib/concurrent/atomic_reference/mutex_atomic.rb +47 -0
  17. data/lib/concurrent/atomic_reference/numeric_cas_wrapper.rb +24 -0
  18. data/lib/concurrent/atomic_reference/rbx.rb +16 -0
  19. data/lib/concurrent/atomic_reference/ruby.rb +16 -0
  20. data/lib/concurrent/atomics.rb +1 -1
  21. data/lib/concurrent/configuration.rb +7 -2
  22. data/lib/concurrent/executor/ruby_thread_pool_executor.rb +0 -1
  23. data/lib/concurrent/executor/{one_by_one.rb → serialized_execution.rb} +21 -8
  24. data/lib/concurrent/executor/timer_set.rb +6 -1
  25. data/lib/concurrent/executors.rb +1 -1
  26. data/lib/concurrent/logging.rb +1 -1
  27. data/lib/concurrent/observable.rb +1 -1
  28. data/lib/concurrent/supervisor.rb +1 -1
  29. data/lib/concurrent/timer_task.rb +0 -36
  30. data/lib/concurrent/version.rb +1 -1
  31. data/lib/concurrent.rb +3 -4
  32. data/lib/concurrent_ruby_ext.so +0 -0
  33. data/lib/extension_helper.rb +9 -0
  34. metadata +19 -152
  35. data/lib/concurrent/actor/actor.rb +0 -270
  36. data/lib/concurrent/actor/postable.rb +0 -102
  37. data/lib/concurrent/actors.rb +0 -2
  38. data/lib/concurrent/actress/doc.md +0 -53
  39. data/lib/concurrent/atomic/atomic.rb +0 -48
  40. data/lib/concurrent/runnable.rb +0 -90
  41. data/lib/concurrent/stoppable.rb +0 -20
  42. data/spec/concurrent/actor/actor_spec.rb +0 -376
  43. data/spec/concurrent/actor/postable_shared.rb +0 -218
  44. data/spec/concurrent/actress_spec.rb +0 -191
  45. data/spec/concurrent/agent_spec.rb +0 -500
  46. data/spec/concurrent/async_spec.rb +0 -352
  47. data/spec/concurrent/atomic/atomic_boolean_spec.rb +0 -172
  48. data/spec/concurrent/atomic/atomic_fixnum_spec.rb +0 -186
  49. data/spec/concurrent/atomic/atomic_spec.rb +0 -133
  50. data/spec/concurrent/atomic/condition_spec.rb +0 -171
  51. data/spec/concurrent/atomic/copy_on_notify_observer_set_spec.rb +0 -10
  52. data/spec/concurrent/atomic/copy_on_write_observer_set_spec.rb +0 -10
  53. data/spec/concurrent/atomic/count_down_latch_spec.rb +0 -151
  54. data/spec/concurrent/atomic/cyclic_barrier_spec.rb +0 -248
  55. data/spec/concurrent/atomic/event_spec.rb +0 -200
  56. data/spec/concurrent/atomic/observer_set_shared.rb +0 -242
  57. data/spec/concurrent/atomic/thread_local_var_spec.rb +0 -113
  58. data/spec/concurrent/channel/buffered_channel_spec.rb +0 -151
  59. data/spec/concurrent/channel/channel_spec.rb +0 -39
  60. data/spec/concurrent/channel/probe_spec.rb +0 -77
  61. data/spec/concurrent/channel/unbuffered_channel_spec.rb +0 -132
  62. data/spec/concurrent/collection/blocking_ring_buffer_spec.rb +0 -149
  63. data/spec/concurrent/collection/priority_queue_spec.rb +0 -317
  64. data/spec/concurrent/collection/ring_buffer_spec.rb +0 -126
  65. data/spec/concurrent/configuration_spec.rb +0 -71
  66. data/spec/concurrent/dataflow_spec.rb +0 -242
  67. data/spec/concurrent/delay_spec.rb +0 -91
  68. data/spec/concurrent/dereferenceable_shared.rb +0 -146
  69. data/spec/concurrent/exchanger_spec.rb +0 -66
  70. data/spec/concurrent/executor/cached_thread_pool_shared.rb +0 -115
  71. data/spec/concurrent/executor/fixed_thread_pool_shared.rb +0 -136
  72. data/spec/concurrent/executor/global_thread_pool_shared.rb +0 -35
  73. data/spec/concurrent/executor/immediate_executor_spec.rb +0 -12
  74. data/spec/concurrent/executor/java_cached_thread_pool_spec.rb +0 -44
  75. data/spec/concurrent/executor/java_fixed_thread_pool_spec.rb +0 -64
  76. data/spec/concurrent/executor/java_single_thread_executor_spec.rb +0 -21
  77. data/spec/concurrent/executor/java_thread_pool_executor_spec.rb +0 -71
  78. data/spec/concurrent/executor/per_thread_executor_spec.rb +0 -57
  79. data/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb +0 -69
  80. data/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb +0 -39
  81. data/spec/concurrent/executor/ruby_single_thread_executor_spec.rb +0 -18
  82. data/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb +0 -171
  83. data/spec/concurrent/executor/safe_task_executor_spec.rb +0 -103
  84. data/spec/concurrent/executor/thread_pool_class_cast_spec.rb +0 -52
  85. data/spec/concurrent/executor/thread_pool_executor_shared.rb +0 -155
  86. data/spec/concurrent/executor/thread_pool_shared.rb +0 -239
  87. data/spec/concurrent/executor/timer_set_spec.rb +0 -183
  88. data/spec/concurrent/future_spec.rb +0 -329
  89. data/spec/concurrent/ivar_spec.rb +0 -215
  90. data/spec/concurrent/mvar_spec.rb +0 -380
  91. data/spec/concurrent/obligation_shared.rb +0 -102
  92. data/spec/concurrent/obligation_spec.rb +0 -282
  93. data/spec/concurrent/observable_shared.rb +0 -177
  94. data/spec/concurrent/observable_spec.rb +0 -56
  95. data/spec/concurrent/options_parser_spec.rb +0 -71
  96. data/spec/concurrent/promise_spec.rb +0 -367
  97. data/spec/concurrent/runnable_shared.rb +0 -68
  98. data/spec/concurrent/runnable_spec.rb +0 -235
  99. data/spec/concurrent/scheduled_task_spec.rb +0 -342
  100. data/spec/concurrent/stoppable_shared.rb +0 -37
  101. data/spec/concurrent/supervisor_spec.rb +0 -1148
  102. data/spec/concurrent/timer_task_spec.rb +0 -258
  103. data/spec/concurrent/tvar_spec.rb +0 -137
  104. data/spec/concurrent/utility/processor_count_spec.rb +0 -20
  105. data/spec/concurrent/utility/timeout_spec.rb +0 -50
  106. data/spec/concurrent/utility/timer_spec.rb +0 -52
  107. data/spec/spec_helper.rb +0 -31
  108. data/spec/support/example_group_extensions.rb +0 -48
  109. data/spec/support/less_than_or_equal_to_matcher.rb +0 -5
  110. /data/{LICENSE → LICENSE.txt} +0 -0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0.rc0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry D'Antonio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Modern concurrency tools including agents, futures, promises, thread pools, actors, supervisors, and more.
@@ -18,27 +18,23 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files:
20
20
  - README.md
21
- - LICENSE
21
+ - LICENSE.txt
22
22
  files:
23
- - LICENSE
23
+ - LICENSE.txt
24
24
  - README.md
25
25
  - lib/concurrent.rb
26
- - lib/concurrent/actor/actor.rb
27
- - lib/concurrent/actor/postable.rb
28
- - lib/concurrent/actors.rb
29
26
  - lib/concurrent/actress.rb
30
27
  - lib/concurrent/actress/ad_hoc.rb
31
28
  - lib/concurrent/actress/context.rb
32
29
  - lib/concurrent/actress/core.rb
33
30
  - lib/concurrent/actress/core_delegations.rb
34
- - lib/concurrent/actress/doc.md
35
31
  - lib/concurrent/actress/envelope.rb
36
32
  - lib/concurrent/actress/errors.rb
37
33
  - lib/concurrent/actress/reference.rb
38
34
  - lib/concurrent/actress/type_check.rb
39
35
  - lib/concurrent/agent.rb
40
36
  - lib/concurrent/async.rb
41
- - lib/concurrent/atomic/atomic.rb
37
+ - lib/concurrent/atomic.rb
42
38
  - lib/concurrent/atomic/atomic_boolean.rb
43
39
  - lib/concurrent/atomic/atomic_fixnum.rb
44
40
  - lib/concurrent/atomic/condition.rb
@@ -48,6 +44,14 @@ files:
48
44
  - lib/concurrent/atomic/cyclic_barrier.rb
49
45
  - lib/concurrent/atomic/event.rb
50
46
  - lib/concurrent/atomic/thread_local_var.rb
47
+ - lib/concurrent/atomic_reference/concurrent_update_error.rb
48
+ - lib/concurrent/atomic_reference/delegated_update.rb
49
+ - lib/concurrent/atomic_reference/direct_update.rb
50
+ - lib/concurrent/atomic_reference/jruby.rb
51
+ - lib/concurrent/atomic_reference/mutex_atomic.rb
52
+ - lib/concurrent/atomic_reference/numeric_cas_wrapper.rb
53
+ - lib/concurrent/atomic_reference/rbx.rb
54
+ - lib/concurrent/atomic_reference/ruby.rb
51
55
  - lib/concurrent/atomics.rb
52
56
  - lib/concurrent/channel/buffered_channel.rb
53
57
  - lib/concurrent/channel/channel.rb
@@ -72,7 +76,6 @@ files:
72
76
  - lib/concurrent/executor/java_fixed_thread_pool.rb
73
77
  - lib/concurrent/executor/java_single_thread_executor.rb
74
78
  - lib/concurrent/executor/java_thread_pool_executor.rb
75
- - lib/concurrent/executor/one_by_one.rb
76
79
  - lib/concurrent/executor/per_thread_executor.rb
77
80
  - lib/concurrent/executor/ruby_cached_thread_pool.rb
78
81
  - lib/concurrent/executor/ruby_fixed_thread_pool.rb
@@ -80,6 +83,7 @@ files:
80
83
  - lib/concurrent/executor/ruby_thread_pool_executor.rb
81
84
  - lib/concurrent/executor/ruby_thread_pool_worker.rb
82
85
  - lib/concurrent/executor/safe_task_executor.rb
86
+ - lib/concurrent/executor/serialized_execution.rb
83
87
  - lib/concurrent/executor/single_thread_executor.rb
84
88
  - lib/concurrent/executor/thread_pool_executor.rb
85
89
  - lib/concurrent/executor/timer_set.rb
@@ -92,9 +96,7 @@ files:
92
96
  - lib/concurrent/observable.rb
93
97
  - lib/concurrent/options_parser.rb
94
98
  - lib/concurrent/promise.rb
95
- - lib/concurrent/runnable.rb
96
99
  - lib/concurrent/scheduled_task.rb
97
- - lib/concurrent/stoppable.rb
98
100
  - lib/concurrent/supervisor.rb
99
101
  - lib/concurrent/timer_task.rb
100
102
  - lib/concurrent/tvar.rb
@@ -104,74 +106,8 @@ files:
104
106
  - lib/concurrent/utility/timer.rb
105
107
  - lib/concurrent/version.rb
106
108
  - lib/concurrent_ruby.rb
107
- - spec/concurrent/actor/actor_spec.rb
108
- - spec/concurrent/actor/postable_shared.rb
109
- - spec/concurrent/actress_spec.rb
110
- - spec/concurrent/agent_spec.rb
111
- - spec/concurrent/async_spec.rb
112
- - spec/concurrent/atomic/atomic_boolean_spec.rb
113
- - spec/concurrent/atomic/atomic_fixnum_spec.rb
114
- - spec/concurrent/atomic/atomic_spec.rb
115
- - spec/concurrent/atomic/condition_spec.rb
116
- - spec/concurrent/atomic/copy_on_notify_observer_set_spec.rb
117
- - spec/concurrent/atomic/copy_on_write_observer_set_spec.rb
118
- - spec/concurrent/atomic/count_down_latch_spec.rb
119
- - spec/concurrent/atomic/cyclic_barrier_spec.rb
120
- - spec/concurrent/atomic/event_spec.rb
121
- - spec/concurrent/atomic/observer_set_shared.rb
122
- - spec/concurrent/atomic/thread_local_var_spec.rb
123
- - spec/concurrent/channel/buffered_channel_spec.rb
124
- - spec/concurrent/channel/channel_spec.rb
125
- - spec/concurrent/channel/probe_spec.rb
126
- - spec/concurrent/channel/unbuffered_channel_spec.rb
127
- - spec/concurrent/collection/blocking_ring_buffer_spec.rb
128
- - spec/concurrent/collection/priority_queue_spec.rb
129
- - spec/concurrent/collection/ring_buffer_spec.rb
130
- - spec/concurrent/configuration_spec.rb
131
- - spec/concurrent/dataflow_spec.rb
132
- - spec/concurrent/delay_spec.rb
133
- - spec/concurrent/dereferenceable_shared.rb
134
- - spec/concurrent/exchanger_spec.rb
135
- - spec/concurrent/executor/cached_thread_pool_shared.rb
136
- - spec/concurrent/executor/fixed_thread_pool_shared.rb
137
- - spec/concurrent/executor/global_thread_pool_shared.rb
138
- - spec/concurrent/executor/immediate_executor_spec.rb
139
- - spec/concurrent/executor/java_cached_thread_pool_spec.rb
140
- - spec/concurrent/executor/java_fixed_thread_pool_spec.rb
141
- - spec/concurrent/executor/java_single_thread_executor_spec.rb
142
- - spec/concurrent/executor/java_thread_pool_executor_spec.rb
143
- - spec/concurrent/executor/per_thread_executor_spec.rb
144
- - spec/concurrent/executor/ruby_cached_thread_pool_spec.rb
145
- - spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb
146
- - spec/concurrent/executor/ruby_single_thread_executor_spec.rb
147
- - spec/concurrent/executor/ruby_thread_pool_executor_spec.rb
148
- - spec/concurrent/executor/safe_task_executor_spec.rb
149
- - spec/concurrent/executor/thread_pool_class_cast_spec.rb
150
- - spec/concurrent/executor/thread_pool_executor_shared.rb
151
- - spec/concurrent/executor/thread_pool_shared.rb
152
- - spec/concurrent/executor/timer_set_spec.rb
153
- - spec/concurrent/future_spec.rb
154
- - spec/concurrent/ivar_spec.rb
155
- - spec/concurrent/mvar_spec.rb
156
- - spec/concurrent/obligation_shared.rb
157
- - spec/concurrent/obligation_spec.rb
158
- - spec/concurrent/observable_shared.rb
159
- - spec/concurrent/observable_spec.rb
160
- - spec/concurrent/options_parser_spec.rb
161
- - spec/concurrent/promise_spec.rb
162
- - spec/concurrent/runnable_shared.rb
163
- - spec/concurrent/runnable_spec.rb
164
- - spec/concurrent/scheduled_task_spec.rb
165
- - spec/concurrent/stoppable_shared.rb
166
- - spec/concurrent/supervisor_spec.rb
167
- - spec/concurrent/timer_task_spec.rb
168
- - spec/concurrent/tvar_spec.rb
169
- - spec/concurrent/utility/processor_count_spec.rb
170
- - spec/concurrent/utility/timeout_spec.rb
171
- - spec/concurrent/utility/timer_spec.rb
172
- - spec/spec_helper.rb
173
- - spec/support/example_group_extensions.rb
174
- - spec/support/less_than_or_equal_to_matcher.rb
109
+ - lib/concurrent_ruby_ext.so
110
+ - lib/extension_helper.rb
175
111
  homepage: http://www.concurrent-ruby.com
176
112
  licenses:
177
113
  - MIT
@@ -187,9 +123,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
123
  version: 1.9.3
188
124
  required_rubygems_version: !ruby/object:Gem::Requirement
189
125
  requirements:
190
- - - ">="
126
+ - - ">"
191
127
  - !ruby/object:Gem::Version
192
- version: '0'
128
+ version: 1.3.1
193
129
  requirements: []
194
130
  rubyforge_project:
195
131
  rubygems_version: 2.2.2
@@ -197,73 +133,4 @@ signing_key:
197
133
  specification_version: 4
198
134
  summary: Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell,
199
135
  F#, C#, Java, and classic concurrency patterns.
200
- test_files:
201
- - spec/concurrent/actor/actor_spec.rb
202
- - spec/concurrent/actor/postable_shared.rb
203
- - spec/concurrent/actress_spec.rb
204
- - spec/concurrent/agent_spec.rb
205
- - spec/concurrent/async_spec.rb
206
- - spec/concurrent/atomic/atomic_boolean_spec.rb
207
- - spec/concurrent/atomic/atomic_fixnum_spec.rb
208
- - spec/concurrent/atomic/atomic_spec.rb
209
- - spec/concurrent/atomic/condition_spec.rb
210
- - spec/concurrent/atomic/copy_on_notify_observer_set_spec.rb
211
- - spec/concurrent/atomic/copy_on_write_observer_set_spec.rb
212
- - spec/concurrent/atomic/count_down_latch_spec.rb
213
- - spec/concurrent/atomic/cyclic_barrier_spec.rb
214
- - spec/concurrent/atomic/event_spec.rb
215
- - spec/concurrent/atomic/observer_set_shared.rb
216
- - spec/concurrent/atomic/thread_local_var_spec.rb
217
- - spec/concurrent/channel/buffered_channel_spec.rb
218
- - spec/concurrent/channel/channel_spec.rb
219
- - spec/concurrent/channel/probe_spec.rb
220
- - spec/concurrent/channel/unbuffered_channel_spec.rb
221
- - spec/concurrent/collection/blocking_ring_buffer_spec.rb
222
- - spec/concurrent/collection/priority_queue_spec.rb
223
- - spec/concurrent/collection/ring_buffer_spec.rb
224
- - spec/concurrent/configuration_spec.rb
225
- - spec/concurrent/dataflow_spec.rb
226
- - spec/concurrent/delay_spec.rb
227
- - spec/concurrent/dereferenceable_shared.rb
228
- - spec/concurrent/exchanger_spec.rb
229
- - spec/concurrent/executor/cached_thread_pool_shared.rb
230
- - spec/concurrent/executor/fixed_thread_pool_shared.rb
231
- - spec/concurrent/executor/global_thread_pool_shared.rb
232
- - spec/concurrent/executor/immediate_executor_spec.rb
233
- - spec/concurrent/executor/java_cached_thread_pool_spec.rb
234
- - spec/concurrent/executor/java_fixed_thread_pool_spec.rb
235
- - spec/concurrent/executor/java_single_thread_executor_spec.rb
236
- - spec/concurrent/executor/java_thread_pool_executor_spec.rb
237
- - spec/concurrent/executor/per_thread_executor_spec.rb
238
- - spec/concurrent/executor/ruby_cached_thread_pool_spec.rb
239
- - spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb
240
- - spec/concurrent/executor/ruby_single_thread_executor_spec.rb
241
- - spec/concurrent/executor/ruby_thread_pool_executor_spec.rb
242
- - spec/concurrent/executor/safe_task_executor_spec.rb
243
- - spec/concurrent/executor/thread_pool_class_cast_spec.rb
244
- - spec/concurrent/executor/thread_pool_executor_shared.rb
245
- - spec/concurrent/executor/thread_pool_shared.rb
246
- - spec/concurrent/executor/timer_set_spec.rb
247
- - spec/concurrent/future_spec.rb
248
- - spec/concurrent/ivar_spec.rb
249
- - spec/concurrent/mvar_spec.rb
250
- - spec/concurrent/obligation_shared.rb
251
- - spec/concurrent/obligation_spec.rb
252
- - spec/concurrent/observable_shared.rb
253
- - spec/concurrent/observable_spec.rb
254
- - spec/concurrent/options_parser_spec.rb
255
- - spec/concurrent/promise_spec.rb
256
- - spec/concurrent/runnable_shared.rb
257
- - spec/concurrent/runnable_spec.rb
258
- - spec/concurrent/scheduled_task_spec.rb
259
- - spec/concurrent/stoppable_shared.rb
260
- - spec/concurrent/supervisor_spec.rb
261
- - spec/concurrent/timer_task_spec.rb
262
- - spec/concurrent/tvar_spec.rb
263
- - spec/concurrent/utility/processor_count_spec.rb
264
- - spec/concurrent/utility/timeout_spec.rb
265
- - spec/concurrent/utility/timer_spec.rb
266
- - spec/spec_helper.rb
267
- - spec/support/example_group_extensions.rb
268
- - spec/support/less_than_or_equal_to_matcher.rb
269
- has_rdoc:
136
+ test_files: []
@@ -1,270 +0,0 @@
1
- require 'thread'
2
- require 'observer'
3
-
4
- require 'concurrent/actor/postable'
5
- require 'concurrent/atomic/event'
6
- require 'concurrent/obligation'
7
- require 'concurrent/runnable'
8
-
9
- module Concurrent
10
-
11
- # Actor-based concurrency is all the rage in some circles. Originally described in
12
- # 1973, the actor model is a paradigm for creating asynchronous, concurrent objects
13
- # that is becoming increasingly popular. Much has changed since actors were first
14
- # written about four decades ago, which has led to a serious fragmentation within
15
- # the actor community. There is *no* universally accepted, strict definition of
16
- # "actor" and actor implementations differ widely between languages and libraries.
17
- #
18
- # A good definition of "actor" is:
19
- #
20
- # An independent, concurrent, single-purpose, computational entity that communicates exclusively via message passing.
21
- #
22
- # The +Concurrent::Actor+ class in this library is based solely on the
23
- # {http://www.scala-lang.org/api/current/index.html#scala.actors.Actor Actor} trait
24
- # defined in the Scala standard library. It does not implement all the features of
25
- # Scala's +Actor+ but its behavior for what *has* been implemented is nearly identical.
26
- # The excluded features mostly deal with Scala's message semantics, strong typing,
27
- # and other characteristics of Scala that don't really apply to Ruby.
28
- #
29
- # Unlike many of the abstractions in this library, +Actor+ takes an *object-oriented*
30
- # approach to asynchronous concurrency, rather than a *functional programming*
31
- # approach.
32
- #
33
- # Because +Actor+ mixes in the +Concurrent::Runnable+ module subclasses have access to
34
- # the +#on_error+ method and can override it to implement custom error handling. The
35
- # +Actor+ base class does not use +#on_error+ so as to avoid conflit with subclasses
36
- # which override it. Generally speaking, +#on_error+ should not be used. The +Actor+
37
- # base class provides concictent, reliable, and robust error handling already, and
38
- # error handling specifics are tied to the message posting method. Incorrect behavior
39
- # in an +#on_error+ override can lead to inconsistent +Actor+ behavior that may lead
40
- # to confusion and difficult debugging.
41
- #
42
- # The +Actor+ superclass mixes in the Ruby standard library
43
- # {http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html Observable}
44
- # module to provide consistent callbacks upon message processing completion. The normal
45
- # +Observable+ methods, including +#add_observer+ behave normally. Once an observer
46
- # is added to an +Actor+ it will be notified of all messages processed *after*
47
- # addition. Notification will *not* occur for any messages that have already been
48
- # processed.
49
- #
50
- # Observers will be notified regardless of whether the message processing is successful
51
- # or not. The +#update+ method of the observer will receive four arguments. The
52
- # appropriate method signature is:
53
- #
54
- # def update(time, message, result, reason)
55
- #
56
- # These four arguments represent:
57
- #
58
- # * The time that message processing was completed
59
- # * An array containing all elements of the original message, in order
60
- # * The result of the call to +#act+ (will be +nil+ if an exception was raised)
61
- # * Any exception raised by +#act+ (or +nil+ if message processing was successful)
62
- #
63
- # @example Actor Ping Pong
64
- # class Ping < Concurrent::Actor
65
- #
66
- # def initialize(count, pong)
67
- # super()
68
- # @pong = pong
69
- # @remaining = count
70
- # end
71
- #
72
- # def act(msg)
73
- #
74
- # if msg == :pong
75
- # print "Ping: pong\n" if @remaining % 1000 == 0
76
- # @pong.post(:ping)
77
- #
78
- # if @remaining > 0
79
- # @pong << :ping
80
- # @remaining -= 1
81
- # else
82
- # print "Ping :stop\n"
83
- # @pong << :stop
84
- # self.stop
85
- # end
86
- # end
87
- # end
88
- # end
89
- #
90
- # class Pong < Concurrent::Actor
91
- #
92
- # attr_writer :ping
93
- #
94
- # def initialize
95
- # super()
96
- # @count = 0
97
- # end
98
- #
99
- # def act(msg)
100
- #
101
- # if msg == :ping
102
- # print "Pong: ping\n" if @count % 1000 == 0
103
- # @ping << :pong
104
- # @count += 1
105
- #
106
- # elsif msg == :stop
107
- # print "Pong :stop\n"
108
- # self.stop
109
- # end
110
- # end
111
- # end
112
- #
113
- # pong = Pong.new
114
- # ping = Ping.new(10000, pong)
115
- # pong.ping = ping
116
- #
117
- # t1 = ping.run!
118
- # t2 = pong.run!
119
- #
120
- # ping << :pong
121
- #
122
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
123
- #
124
- # @see http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html
125
- class Actor
126
- include ::Observable
127
- include Postable
128
- include Runnable
129
-
130
- private
131
-
132
- # @!visibility private
133
- class Poolbox # :nodoc:
134
- include Postable
135
-
136
- def initialize(queue)
137
- @queue = queue
138
- end
139
- end
140
-
141
- public
142
-
143
- # Create a pool of actors that share a common mailbox.
144
- #
145
- # Every +Actor+ instance operates on its own thread. When one thread isn't enough capacity
146
- # to manage all the messages being sent to an +Actor+ a *pool* can be used instead. A pool
147
- # is a collection of +Actor+ instances, all of the same type, that shate a message queue.
148
- # Messages from other threads are all sent to a single queue against which all +Actor+s
149
- # load balance.
150
- #
151
- # @param [Integer] count the number of actors in the pool
152
- # @param [Array] args zero or more arguments to pass to each actor in the pool
153
- #
154
- # @return [Array] two-element array with the shared mailbox as the first element
155
- # and an array of actors as the second element
156
- #
157
- # @raise ArgumentError if +count+ is zero or less
158
- #
159
- # @example
160
- # class EchoActor < Concurrent::Actor
161
- # def act(*message)
162
- # puts "#{message} handled by #{self}"
163
- # end
164
- # end
165
- #
166
- # mailbox, pool = EchoActor.pool(5)
167
- # pool.each{|echo| echo.run! }
168
- #
169
- # 10.times{|i| mailbox.post(i) }
170
- # #=> [0] handled by #<EchoActor:0x007fc8014fb8b8>
171
- # #=> [1] handled by #<EchoActor:0x007fc8014fb890>
172
- # #=> [2] handled by #<EchoActor:0x007fc8014fb868>
173
- # #=> [3] handled by #<EchoActor:0x007fc8014fb890>
174
- # #=> [4] handled by #<EchoActor:0x007fc8014fb840>
175
- # #=> [5] handled by #<EchoActor:0x007fc8014fb8b8>
176
- # #=> [6] handled by #<EchoActor:0x007fc8014fb8b8>
177
- # #=> [7] handled by #<EchoActor:0x007fc8014fb818>
178
- # #=> [8] handled by #<EchoActor:0x007fc8014fb890>
179
- #
180
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
181
- def self.pool(count, *args, &block)
182
- warn '[DEPRECATED] `Actor` is deprecated and will be replaced with `Actress`.'
183
- raise ArgumentError.new('count must be greater than zero') unless count > 0
184
- mailbox = Queue.new
185
- actors = count.times.collect do
186
- if block_given?
187
- actor = self.new(*args, &block.dup)
188
- else
189
- actor = self.new(*args)
190
- end
191
- actor.instance_variable_set(:@queue, mailbox)
192
- actor
193
- end
194
- return Poolbox.new(mailbox), actors
195
- end
196
-
197
- protected
198
-
199
- # Actors are defined by subclassing the +Concurrent::Actor+ class and overriding the
200
- # #act method. The #act method can have any signature/arity but +def act(*args)+
201
- # is the most flexible and least error-prone signature. The #act method is called in
202
- # response to a message being post to the +Actor+ instance (see *Behavior* below).
203
- #
204
- # @param [Array] message one or more arguments representing the message sent to the
205
- # actor via one of the Concurrent::Postable methods
206
- #
207
- # @return [Object] the result obtained when the message is successfully processed
208
- #
209
- # @raise NotImplementedError unless overridden in the +Actor+ subclass
210
- #
211
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
212
- #
213
- # @!visibility public
214
- def act(*message)
215
- warn '[DEPRECATED] `Actor` is deprecated and will be replaced with `Actress`.'
216
- raise NotImplementedError.new("#{self.class} does not implement #act")
217
- end
218
-
219
- # @!visibility private
220
- #
221
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
222
- def on_run # :nodoc:
223
- warn '[DEPRECATED] `Actor` is deprecated and will be replaced with `Actress`.'
224
- queue.clear
225
- end
226
-
227
- # @!visibility private
228
- #
229
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
230
- def on_stop # :nodoc:
231
- queue.clear
232
- queue.push(:stop)
233
- end
234
-
235
- # @!visibility private
236
- #
237
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
238
- def on_task # :nodoc:
239
- package = queue.pop
240
- return if package == :stop
241
- result = ex = nil
242
- notifier = package.notifier
243
- begin
244
- if notifier.nil? || (notifier.is_a?(Event) && ! notifier.set?)
245
- result = act(*package.message)
246
- end
247
- rescue => ex
248
- on_error(Time.now, package.message, ex)
249
- ensure
250
- if notifier.is_a?(Event) && ! notifier.set?
251
- package.handler.push(result || ex)
252
- package.notifier.set
253
- elsif package.handler.is_a?(IVar)
254
- package.handler.complete(! result.nil?, result, ex)
255
- elsif package.handler.respond_to?(:post) && ex.nil?
256
- package.handler.post(result)
257
- end
258
-
259
- changed
260
- notify_observers(Time.now, package.message, result, ex)
261
- end
262
- end
263
-
264
- # @!visibility private
265
- #
266
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
267
- def on_error(time, msg, ex) # :nodoc:
268
- end
269
- end
270
- end
@@ -1,102 +0,0 @@
1
- require 'concurrent/atomic/event'
2
-
3
- module Concurrent
4
-
5
- module Postable
6
-
7
- # @!visibility private
8
- Package = Struct.new(:message, :handler, :notifier) # :nodoc:
9
-
10
- # Sends a message to and returns. It's a fire-and-forget interaction.
11
- #
12
- # @param [Array] message one or more arguments representing a single message
13
- # to be sent to the receiver.
14
- #
15
- # @return [Object] false when the message cannot be queued else the number
16
- # of messages in the queue *after* this message has been post
17
- #
18
- # @raise ArgumentError when the message is empty
19
- #
20
- # @example
21
- # class EchoActor < Concurrent::Actor
22
- # def act(*message)
23
- # p message
24
- # end
25
- # end
26
- #
27
- # echo = EchoActor.new
28
- # echo.run!
29
- #
30
- # echo.post("Don't panic") #=> true
31
- # #=> ["Don't panic"]
32
- #
33
- # echo.post(1, 2, 3, 4, 5) #=> true
34
- # #=> [1, 2, 3, 4, 5]
35
- #
36
- # echo << "There's a frood who really knows where his towel is." #=> #<EchoActor:0x007fc8012b8448...
37
- # #=> ["There's a frood who really knows where his towel is."]
38
- def post(*message)
39
- raise ArgumentError.new('empty message') if message.empty?
40
- return false unless ready?
41
- queue.push(Package.new(message))
42
- true
43
- end
44
-
45
- def <<(message)
46
- post(*message)
47
- self
48
- end
49
-
50
- def post?(*message)
51
- raise ArgumentError.new('empty message') if message.empty?
52
- return nil unless ready?
53
- ivar = IVar.new
54
- queue.push(Package.new(message, ivar))
55
- ivar
56
- end
57
-
58
- def post!(seconds, *message)
59
- raise ArgumentError.new('empty message') if message.empty?
60
- raise Concurrent::LifecycleError unless ready?
61
- raise Concurrent::TimeoutError if seconds.to_f <= 0.0
62
- event = Event.new
63
- cback = Queue.new
64
- queue.push(Package.new(message, cback, event))
65
- if event.wait(seconds)
66
- result = cback.pop
67
- if result.is_a?(Exception)
68
- raise result
69
- else
70
- return result
71
- end
72
- else
73
- event.set # attempt to cancel
74
- raise Concurrent::TimeoutError
75
- end
76
- end
77
-
78
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
79
- def forward(receiver, *message)
80
- raise ArgumentError.new('empty message') if message.empty?
81
- return false unless ready?
82
- queue.push(Package.new(message, receiver))
83
- queue.length
84
- end
85
-
86
- # @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
87
- def ready?
88
- if self.respond_to?(:running?) && ! running?
89
- false
90
- else
91
- true
92
- end
93
- end
94
-
95
- private
96
-
97
- # @!visibility private
98
- def queue # :nodoc:
99
- @queue ||= Queue.new
100
- end
101
- end
102
- end
@@ -1,2 +0,0 @@
1
- require 'concurrent/actor/actor'
2
- require 'concurrent/actor/postable'
@@ -1,53 +0,0 @@
1
- # Light-weighted implement of Actors. Inspired by Akka and Erlang.
2
-
3
- Actors are using a thread-pool by default which makes them very cheap to create and discard.
4
- Thousands of actors can be created allowing to brake the program to small maintainable pieces
5
- without breaking single responsibility principles.
6
-
7
- ## Quick example
8
-
9
- class Counter
10
- include Context
11
-
12
- def initialize(initial_value)
13
- @count = initial_value
14
- end
15
-
16
- def on_message(message)
17
- case message
18
- when Integer
19
- @count += message
20
- when :terminate
21
- terminate!
22
- else
23
- raise 'unknown'
24
- end
25
- end
26
- end
27
-
28
- # create new actor
29
- counter = Counter.spawn(:test_counter, 5) # => a Reference
30
-
31
- # send messages
32
- counter.tell(1) # => counter
33
- counter << 1 # => counter
34
-
35
- # send messages getting an IVar back for synchronization
36
- counter.ask(0) # => an ivar
37
- counter.ask(0).value # => 7
38
-
39
- # terminate the actor
40
- counter.ask(:terminate).wait
41
- counter.terminated? # => true
42
- counter.ask(5).wait.rejected? # => true
43
-
44
- # failure on message processing will terminate the actor
45
- counter = Counter.spawn(:test_counter, 0)
46
- counter.ask('boom').wait.rejected? # => true
47
- counter.terminated? # => true
48
-
49
-
50
-
51
-
52
-
53
-