concurrent-ruby 0.7.0.rc2-java → 0.7.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +138 -0
- data/README.md +108 -95
- data/lib/concurrent/actor.rb +12 -13
- data/lib/concurrent/actor/behaviour/errors_on_unknown_message.rb +1 -1
- data/lib/concurrent/actor/behaviour/executes_context.rb +1 -1
- data/lib/concurrent/actor/behaviour/linking.rb +4 -1
- data/lib/concurrent/actor/behaviour/pausing.rb +2 -2
- data/lib/concurrent/actor/behaviour/supervised.rb +3 -2
- data/lib/concurrent/actor/behaviour/terminates_children.rb +1 -1
- data/lib/concurrent/actor/behaviour/termination.rb +1 -1
- data/lib/concurrent/actor/context.rb +2 -1
- data/lib/concurrent/actor/core.rb +8 -4
- data/lib/concurrent/actor/utils.rb +10 -0
- data/lib/concurrent/actor/utils/ad_hoc.rb +21 -0
- data/lib/concurrent/actor/utils/balancer.rb +42 -0
- data/lib/concurrent/actor/utils/broadcast.rb +22 -6
- data/lib/concurrent/actor/utils/pool.rb +59 -0
- data/lib/concurrent/agent.rb +1 -22
- data/lib/concurrent/async.rb +1 -79
- data/lib/concurrent/atomic.rb +20 -26
- data/lib/concurrent/atomic/atomic_boolean.rb +4 -1
- data/lib/concurrent/atomic/atomic_fixnum.rb +4 -1
- data/lib/concurrent/atomic/thread_local_var.rb +71 -24
- data/lib/concurrent/atomic_reference/jruby.rb +10 -6
- data/lib/concurrent/atomic_reference/ruby.rb +14 -10
- data/lib/concurrent/atomics.rb +0 -1
- data/lib/concurrent/configuration.rb +11 -5
- data/lib/concurrent/dataflow.rb +1 -30
- data/lib/concurrent/dereferenceable.rb +9 -2
- data/lib/concurrent/executor/indirect_immediate_executor.rb +46 -0
- data/lib/concurrent/executor/java_thread_pool_executor.rb +2 -4
- data/lib/concurrent/executor/ruby_thread_pool_executor.rb +24 -22
- data/lib/concurrent/executor/serialized_execution.rb +36 -23
- data/lib/concurrent/executor/thread_pool_executor.rb +2 -0
- data/lib/concurrent/executor/timer_set.rb +7 -8
- data/lib/concurrent/executors.rb +1 -0
- data/lib/concurrent/future.rb +7 -29
- data/lib/concurrent/ivar.rb +9 -0
- data/lib/concurrent/logging.rb +3 -0
- data/lib/concurrent/mvar.rb +26 -9
- data/lib/concurrent/observable.rb +33 -0
- data/lib/concurrent/promise.rb +59 -1
- data/lib/concurrent/scheduled_task.rb +1 -0
- data/lib/concurrent/timer_task.rb +18 -18
- data/lib/concurrent/tvar.rb +3 -1
- data/lib/concurrent/version.rb +1 -1
- data/lib/concurrent_ruby_ext.jar +0 -0
- data/lib/concurrent_ruby_ext.so +0 -0
- data/lib/extension_helper.rb +25 -6
- metadata +15 -7
- data/lib/concurrent/actor/ad_hoc.rb +0 -19
- data/lib/concurrent/actor/utills.rb +0 -7
data/CHANGELOG.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
## Current Release v0.7.1 (4 December 2014)
|
2
|
+
|
3
|
+
Please see the [roadmap](https://github.com/ruby-concurrency/concurrent-ruby/issues/142) for more information on the next planned release.
|
4
|
+
|
5
|
+
* Added `flat_map` method to `Promise`
|
6
|
+
* Added `zip` method to `Promise`
|
7
|
+
* Fixed bug with logging in `Actor`
|
8
|
+
* Improvements to `Promise` tests
|
9
|
+
* Removed actor-experimental warning
|
10
|
+
* Added an `IndirectImmediateExecutor` class
|
11
|
+
* Allow disabling auto termination of global executors
|
12
|
+
* Fix thread leaking in `ThreadLocalVar` (uses `Ref` gem on non-JRuby systems)
|
13
|
+
* Fix thread leaking when pruning pure-Ruby thread pools
|
14
|
+
* Prevent `Actor` from using an `ImmediateExecutor` (causes deadlock)
|
15
|
+
* Added missing synchronizations to `TimerSet`
|
16
|
+
* Fixed bug with return value of `Concurrent::Actor::Utils::Pool#ask`
|
17
|
+
* Fixed timing bug in `TimerTask`
|
18
|
+
* Fixed bug when creating a `JavaThreadPoolExecutor` with minimum pool size of zero
|
19
|
+
* Removed confusing warning when not using native extenstions
|
20
|
+
* Improved documentation
|
21
|
+
|
22
|
+
### Release v0.7.0 (13 August 2014)
|
23
|
+
|
24
|
+
* Merge the [atomic](https://github.com/ruby-concurrency/atomic) gem
|
25
|
+
- Pure Ruby `MutexAtomic` atomic reference class
|
26
|
+
- Platform native atomic reference classes `CAtomic`, `JavaAtomic`, and `RbxAtomic`
|
27
|
+
- Automated [build process](https://github.com/ruby-concurrency/rake-compiler-dev-box)
|
28
|
+
- Fat binary releases for [multiple platforms](https://rubygems.org/gems/concurrent-ruby/versions) including Windows (32/64), Linux (32/64), OS X (64-bit), Solaris (64-bit), and JRuby
|
29
|
+
* C native `CAtomicBoolean`
|
30
|
+
* C native `CAtomicFixnum`
|
31
|
+
* Refactored intermittently failing tests
|
32
|
+
* Added `dataflow!` and `dataflow_with!` methods to match `Future#value!` method
|
33
|
+
* Better handling of timeout in `Agent`
|
34
|
+
* Actor Improvements
|
35
|
+
- Fine-grained implementation using chain of behaviors. Each behavior is responsible for single aspect like: `Termination`, `Pausing`, `Linking`, `Supervising`, etc. Users can create custom Actors easily based on their needs.
|
36
|
+
- Supervision was added. `RestartingContext` will pause on error waiting on its supervisor to decide what to do next ( options are `:terminate!`, `:resume!`, `:reset!`, `:restart!`). Supervising behavior also supports strategies `:one_for_one` and `:one_for_all`.
|
37
|
+
- Linking was added to be able to monitor actor's events like: `:terminated`, `:paused`, `:restarted`, etc.
|
38
|
+
- Dead letter routing added. Rejected envelopes are collected in a configurable actor (default: `Concurrent::Actor.root.ask!(:dead_letter_routing)`)
|
39
|
+
- Old `Actor` class removed and replaced by new implementation previously called `Actress`. `Actress` was kept as an alias for `Actor` to keep compatibility.
|
40
|
+
- `Utils::Broadcast` actor which allows Publish–subscribe pattern.
|
41
|
+
* More executors for managing serialized operations
|
42
|
+
- `SerializedExecution` mixin module
|
43
|
+
- `SerializedExecutionDelegator` for serializing *any* executor
|
44
|
+
* Updated `Async` with serialized execution
|
45
|
+
* Updated `ImmediateExecutor` and `PerThreadExecutor` with full executor service lifecycle
|
46
|
+
* Added a `Delay` to root `Actress` initialization
|
47
|
+
* Minor bug fixes to thread pools
|
48
|
+
* Refactored many intermittently failing specs
|
49
|
+
* Removed Java interop warning `executor.rb:148 warning: ambiguous Java methods found, using submit(java.lang.Runnable)`
|
50
|
+
* Fixed minor bug in `RubyCachedThreadPool` overflow policy
|
51
|
+
* Updated tests to use [RSpec 3.0](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3)
|
52
|
+
* Removed deprecated `Actor` class
|
53
|
+
* Better support for Rubinius
|
54
|
+
|
55
|
+
### Release v0.6.1 (14 June 2014)
|
56
|
+
|
57
|
+
* Many improvements to `Concurrent::Actress`
|
58
|
+
* Bug fixes to `Concurrent::RubyThreadPoolExecutor`
|
59
|
+
* Fixed several brittle tests
|
60
|
+
* Moved documentation to http://ruby-concurrency.github.io/concurrent-ruby/frames.html
|
61
|
+
|
62
|
+
### Release v0.6.0 (25 May 2014)
|
63
|
+
|
64
|
+
* Added `Concurrent::Observable` to encapsulate our thread safe observer sets
|
65
|
+
* Improvements to new `Channel`
|
66
|
+
* Major improvements to `CachedThreadPool` and `FixedThreadPool`
|
67
|
+
* Added `SingleThreadExecutor`
|
68
|
+
* Added `Current::timer` function
|
69
|
+
* Added `TimerSet` executor
|
70
|
+
* Added `AtomicBoolean`
|
71
|
+
* `ScheduledTask` refactoring
|
72
|
+
* Pure Ruby and JRuby-optimized `PriorityQueue` classes
|
73
|
+
* Updated `Agent` behavior to more closely match Clojure
|
74
|
+
* Observer sets support block callbacks to the `add_observer` method
|
75
|
+
* New algorithm for thread creation in `RubyThreadPoolExecutor`
|
76
|
+
* Minor API updates to `Event`
|
77
|
+
* Rewritten `TimerTask` now an `Executor` instead of a `Runnable`
|
78
|
+
* Fixed many brittle specs
|
79
|
+
* Renamed `FixedThreadPool` and `CachedThreadPool` to `RubyFixedThreadPool` and `RubyCachedThreadPool`
|
80
|
+
* Created JRuby optimized `JavaFixedThreadPool` and `JavaCachedThreadPool`
|
81
|
+
* Consolidated fixed thread pool tests into `spec/concurrent/fixed_thread_pool_shared.rb` and `spec/concurrent/cached_thread_pool_shared.rb`
|
82
|
+
* `FixedThreadPool` now subclasses `RubyFixedThreadPool` or `JavaFixedThreadPool` as appropriate
|
83
|
+
* `CachedThreadPool` now subclasses `RubyCachedThreadPool` or `JavaCachedThreadPool` as appropriate
|
84
|
+
* New `Delay` class
|
85
|
+
* `Concurrent::processor_count` helper function
|
86
|
+
* New `Async` module
|
87
|
+
* Renamed `NullThreadPool` to `PerThreadExecutor`
|
88
|
+
* Deprecated `Channel` (we are planning a new implementation based on [Go](http://golangtutorials.blogspot.com/2011/06/channels-in-go.html))
|
89
|
+
* Added gem-level [configuration](http://robots.thoughtbot.com/mygem-configure-block)
|
90
|
+
* Deprecated `$GLOBAL_THREAD_POOL` in lieu of gem-level configuration
|
91
|
+
* Removed support for Ruby [1.9.2](https://www.ruby-lang.org/en/news/2013/12/17/maintenance-of-1-8-7-and-1-9-2/)
|
92
|
+
* New `RubyThreadPoolExecutor` and `JavaThreadPoolExecutor` classes
|
93
|
+
* All thread pools now extend the appropriate thread pool executor classes
|
94
|
+
* All thread pools now support `:overflow_policy` (based on Java's [reject policies](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html))
|
95
|
+
* Deprecated `UsesGlobalThreadPool` in lieu of explicit `:executor` option (dependency injection) on `Future`, `Promise`, and `Agent`
|
96
|
+
* Added `Concurrent::dataflow_with(executor, *inputs)` method to support executor dependency injection for dataflow
|
97
|
+
* Software transactional memory with `TVar` and `Concurrent::atomically`
|
98
|
+
* First implementation of [new, high-performance](https://github.com/ruby-concurrency/concurrent-ruby/pull/49) `Channel`
|
99
|
+
* `Actor` is deprecated in favor of new experimental actor implementation [#73](https://github.com/ruby-concurrency/concurrent-ruby/pull/73). To avoid namespace collision it is living in `Actress` namespace until `Actor` is removed in next release.
|
100
|
+
|
101
|
+
### Release v0.5.0
|
102
|
+
|
103
|
+
This is the most significant release of this gem since its inception. This release includes many improvements and optimizations. It also includes several bug fixes. The major areas of focus for this release were:
|
104
|
+
|
105
|
+
* Stability improvements on Ruby versions with thread-level parallelism ([JRuby](http://jruby.org/) and [Rubinius](http://rubini.us/))
|
106
|
+
* Creation of new low-level concurrency abstractions
|
107
|
+
* Internal refactoring to use the new low-level abstractions
|
108
|
+
|
109
|
+
Most of these updates had no effect on the gem API. There are a few notable exceptions which were unavoidable. Please read the [release notes](API-Updates-in-v0.5.0) for more information.
|
110
|
+
|
111
|
+
Specific changes include:
|
112
|
+
|
113
|
+
* New class `IVar`
|
114
|
+
* New class `MVar`
|
115
|
+
* New class `ThreadLocalVar`
|
116
|
+
* New class `AtomicFixnum`
|
117
|
+
* New class method `dataflow`
|
118
|
+
* New class `Condition`
|
119
|
+
* New class `CountDownLatch`
|
120
|
+
* New class `DependencyCounter`
|
121
|
+
* New class `SafeTaskExecutor`
|
122
|
+
* New class `CopyOnNotifyObserverSet`
|
123
|
+
* New class `CopyOnWriteObserverSet`
|
124
|
+
* `Future` updated with `execute` API
|
125
|
+
* `ScheduledTask` updated with `execute` API
|
126
|
+
* New `Promise` API
|
127
|
+
* `Future` now extends `IVar`
|
128
|
+
* `Postable#post?` now returns an `IVar`
|
129
|
+
* Thread safety fixes to `Dereferenceable`
|
130
|
+
* Thread safety fixes to `Obligation`
|
131
|
+
* Thread safety fixes to `Supervisor`
|
132
|
+
* Thread safety fixes to `Event`
|
133
|
+
* Various other thread safety (race condition) fixes
|
134
|
+
* Refactored brittle tests
|
135
|
+
* Implemented pending tests
|
136
|
+
* Added JRuby and Rubinius as Travis CI build targets
|
137
|
+
* Added [CodeClimate](https://codeclimate.com/) code review
|
138
|
+
* Improved YARD documentation
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Concurrent Ruby
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/concurrent-ruby.
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/concurrent-ruby.svg)](http://badge.fury.io/rb/concurrent-ruby) [![Build Status](https://travis-ci.org/ruby-concurrency/concurrent-ruby.svg?branch=master)](https://travis-ci.org/ruby-concurrency/concurrent-ruby) [![Coverage Status](https://img.shields.io/coveralls/ruby-concurrency/concurrent-ruby/master.svg)](https://coveralls.io/r/ruby-concurrency/concurrent-ruby) [![Code Climate](https://codeclimate.com/github/ruby-concurrency/concurrent-ruby.svg)](https://codeclimate.com/github/ruby-concurrency/concurrent-ruby) [![Inline docs](http://inch-ci.org/github/ruby-concurrency/concurrent-ruby.svg)](http://inch-ci.org/github/ruby-concurrency/concurrent-ruby) [![Dependency Status](https://gemnasium.com/ruby-concurrency/concurrent-ruby.svg)](https://gemnasium.com/ruby-concurrency/concurrent-ruby) [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT) [![Gitter chat](http://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/ruby-concurrency/concurrent-ruby)
|
3
3
|
|
4
4
|
<table>
|
5
5
|
<tr>
|
@@ -30,12 +30,96 @@
|
|
30
30
|
</p>
|
31
31
|
</td>
|
32
32
|
<td align="right" valign="top">
|
33
|
-
<img src="https://raw.githubusercontent.com/
|
33
|
+
<img src="https://raw.githubusercontent.com/ruby-concurrency/concurrent-ruby/master/doc/logo/concurrent-ruby-logo-300x300.png"/>
|
34
34
|
</td>
|
35
35
|
</tr>
|
36
36
|
</table>
|
37
37
|
|
38
|
-
|
38
|
+
### Supported Ruby versions
|
39
|
+
|
40
|
+
MRI 1.9.3, 2.0, 2.1, JRuby (1.9 mode), and Rubinius 2.x are supported.
|
41
|
+
Although native code is used for performance optimizations on some platforms, all functionality
|
42
|
+
is available in pure Ruby. This gem should be fully compatible with any interpreter that is
|
43
|
+
compliant with Ruby 1.9.3 or newer.
|
44
|
+
|
45
|
+
## Features & Documentation
|
46
|
+
|
47
|
+
We have a roadmap guiding our work toward the [v1.0.0 release](https://github.com/ruby-concurrency/concurrent-ruby/wiki/v1.0-Roadmap).
|
48
|
+
|
49
|
+
The primary site for documentation is the automatically generated [API documentation](http://ruby-concurrency.github.io/concurrent-ruby/frames.html)
|
50
|
+
|
51
|
+
We also have a [mailing list](http://groups.google.com/group/concurrent-ruby).
|
52
|
+
|
53
|
+
This library contains a variety of concurrency abstractions at high and low levels. One of the high-level abstractions is likely to meet most common needs.
|
54
|
+
|
55
|
+
### High-level, general-purpose asynchronous concurrency abstractions
|
56
|
+
|
57
|
+
* [Actor](./doc/actor/main.md): Implements the Actor Model, where concurrent actors exchange messages.
|
58
|
+
* [Agent](./doc/agent.md): A single atomic value that represents an identity.
|
59
|
+
* [Async](./doc/async.md): A mixin module that provides simple asynchronous behavior to any standard class/object or object.
|
60
|
+
* [Future](./doc/future.md): An asynchronous operation that produces a value.
|
61
|
+
* [Dataflow](./doc/dataflow.md): Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
|
62
|
+
* [Promise](./doc/promise.md): Similar to Futures, with more features.
|
63
|
+
* [ScheduledTask](./doc/scheduled_task.md): Like a Future scheduled for a specific future time.
|
64
|
+
* [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TimerTask.html): A Thread that periodically wakes up to perform work at regular intervals.
|
65
|
+
|
66
|
+
|
67
|
+
### Java-inspired ThreadPools and other executors
|
68
|
+
|
69
|
+
* See [ThreadPool](./doc/thread_pools.md) overview, which also contains a list of other Executors available.
|
70
|
+
|
71
|
+
### Thread-safe Observers
|
72
|
+
|
73
|
+
* [Concurrent::Observable](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Observable.html) mixin module
|
74
|
+
* [CopyOnNotifyObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnNotifyObserverSet.html)
|
75
|
+
* [CopyOnWriteObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnWriteObserverSet.html)
|
76
|
+
|
77
|
+
### Thread synchronization classes and algorithms
|
78
|
+
Lower-level abstractions mainly used as building blocks.
|
79
|
+
|
80
|
+
* [condition](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Condition.html)
|
81
|
+
* [countdown latch](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CountDownLatch.html)
|
82
|
+
* [cyclic barrier](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CyclicBarrier.html)
|
83
|
+
* [event](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Event.html)
|
84
|
+
* [exchanger](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Exchanger.html)
|
85
|
+
* [timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method)
|
86
|
+
* [timer](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timer-class_method)
|
87
|
+
|
88
|
+
### Thread-safe variables
|
89
|
+
Lower-level abstractions mainly used as building blocks.
|
90
|
+
|
91
|
+
* [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicBoolean.html)
|
92
|
+
* [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicFixnum.html)
|
93
|
+
* AtomicReference (no docs currently available, check source)
|
94
|
+
* [I-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html) (IVar)
|
95
|
+
* [M-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MVar.html) (MVar)
|
96
|
+
* [thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html)
|
97
|
+
* [software transactional memory](./doc/tvar.md) (TVar)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
## Installing and Building
|
102
|
+
|
103
|
+
This gem includes several platform-specific optimizations. To reduce the possibility of
|
104
|
+
compilation errors, we provide pre-compiled gem packages for several platforms as well
|
105
|
+
as a pure-Ruby build. Installing the gem should be no different than installing any other
|
106
|
+
Rubygems-hosted gem. Rubygems will automatically detect your platform and install the
|
107
|
+
appropriate pre-compiled build. You should never see Rubygems attempt to compile the gem
|
108
|
+
on installation. Additionally, to ensure compatability with the largest possible number
|
109
|
+
of Ruby interpreters, the C extensions will *never* load under any Ruby other than MRI,
|
110
|
+
even when installed.
|
111
|
+
|
112
|
+
The following gem builds will be built at every release:
|
113
|
+
|
114
|
+
* concurrent-ruby-x.y.z.gem (pure Ruby)
|
115
|
+
* concurrent-ruby-x.y.z-java.gem (JRuby)
|
116
|
+
* concurrent-ruby-x.y.z-x86-linux.gem (Linux 32-bit)
|
117
|
+
* concurrent-ruby-x.y.z-x86_64-linux.gem (Linux 64-bit)
|
118
|
+
* concurrent-ruby-x.y.z-x86-mingw32.gem (Windows 32-bit)
|
119
|
+
* concurrent-ruby-x.y.z-x64-mingw32.gem (Windows 64-bit)
|
120
|
+
* concurrent-ruby-x.y.z-x86-solaris-2.11.gem (Solaris)
|
121
|
+
|
122
|
+
### Installing
|
39
123
|
|
40
124
|
```shell
|
41
125
|
gem install concurrent-ruby
|
@@ -49,86 +133,31 @@ gem 'concurrent-ruby'
|
|
49
133
|
|
50
134
|
and run `bundle install` from your shell.
|
51
135
|
|
52
|
-
|
136
|
+
### Building
|
53
137
|
|
54
|
-
|
138
|
+
Because we provide pre-compiled gem builds, users should never need to build the gem manually.
|
139
|
+
The build process for this gem is completely automated using open source tools. All of
|
140
|
+
the automation components are available in the [ruby-concurrency/rake-compiler-dev-box](https://github.com/ruby-concurrency/rake-compiler-dev-box)
|
141
|
+
GitHub repository.
|
55
142
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
into several general groups:
|
62
|
-
|
63
|
-
* Asynchronous concurrency abstractions including
|
64
|
-
[Async](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Async),
|
65
|
-
[Agent](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Agent),
|
66
|
-
[Future](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Future),
|
67
|
-
[Promise](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Promise),
|
68
|
-
[ScheduledTask](https://github.com/ruby-concurrency/concurrent-ruby/wiki/ScheduledTask),
|
69
|
-
and [TimerTask](https://github.com/ruby-concurrency/concurrent-ruby/wiki/TimerTask)
|
70
|
-
* Thread-safe variables including [M-Structures](https://github.com/ruby-concurrency/concurrent-ruby/wiki/MVar-(M-Structure)),
|
71
|
-
[I-Structures](https://github.com/ruby-concurrency/concurrent-ruby/wiki/IVar-(I-Structure)),
|
72
|
-
[thread-local variables](https://github.com/ruby-concurrency/concurrent-ruby/wiki/ThreadLocalVar),
|
73
|
-
atomic counters, and [software transactional memory](https://github.com/ruby-concurrency/concurrent-ruby/wiki/TVar-(STM))
|
74
|
-
* Thread synchronization classes and algorithms including [dataflow](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Dataflow),
|
75
|
-
timeout, condition, countdown latch, dependency counter, and event
|
76
|
-
* Java-inspired [thread pools](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Thread%20Pools)
|
77
|
-
* New fast light-weighted [Actor model](http://ruby-concurrency.github.io/concurrent-ruby/frames.html#!Concurrent/Actress.html) implementation.
|
78
|
-
* And many more...
|
79
|
-
|
80
|
-
### Semantic Versioning
|
81
|
-
|
82
|
-
This gem adheres to the rules of [semantic versioning](http://semver.org/).
|
143
|
+
This gem will compile native C code under MRI and native Java code under JRuby. It is
|
144
|
+
also possible to build a pure-Ruby version. All builds have identical functionality.
|
145
|
+
The only difference is performance. Additionally, pure-Ruby classes are always available,
|
146
|
+
even when using the native optimizations. Please see the [documentation](http://ruby-concurrency.github.io/concurrent-ruby/)
|
147
|
+
for more details.
|
83
148
|
|
84
|
-
|
149
|
+
To build and package the gem using MRI or JRuby, install the necessary build dependencies and run:
|
150
|
+
|
151
|
+
```shell
|
152
|
+
bundle exec rake compile
|
153
|
+
bundle exec rake build
|
154
|
+
```
|
155
|
+
|
156
|
+
To build and package a pure-Ruby gem, on *any* platform and interpreter
|
157
|
+
(including MRI and JRuby), run:
|
85
158
|
|
86
|
-
|
87
|
-
|
88
|
-
It should be fully compatible with any interpreter that is compliant with Ruby 1.9.3 or newer.
|
89
|
-
|
90
|
-
### Examples
|
91
|
-
|
92
|
-
Many more code examples can be found in the documentation for each class (linked above).
|
93
|
-
This one simple example shows some of the power of this gem.
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
require 'concurrent'
|
97
|
-
require 'thread' # for Queue
|
98
|
-
require 'open-uri' # for open(uri)
|
99
|
-
|
100
|
-
class Ticker
|
101
|
-
def get_year_end_closing(symbol, year)
|
102
|
-
uri = "http://ichart.finance.yahoo.com/table.csv?s=#{symbol}&a=11&b=01&c=#{year}&d=11&e=31&f=#{year}&g=m"
|
103
|
-
data = open(uri) {|f| f.collect{|line| line.strip } }
|
104
|
-
data[1].split(',')[4].to_f
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Future
|
109
|
-
price = Concurrent::Future.execute{ Ticker.new.get_year_end_closing('TWTR', 2013) }
|
110
|
-
price.state #=> :pending
|
111
|
-
sleep(1) # do other stuff
|
112
|
-
price.value #=> 63.65
|
113
|
-
price.state #=> :fulfilled
|
114
|
-
|
115
|
-
# Promise
|
116
|
-
prices = Concurrent::Promise.new{ puts Ticker.new.get_year_end_closing('AAPL', 2013) }.
|
117
|
-
then{ puts Ticker.new.get_year_end_closing('MSFT', 2013) }.
|
118
|
-
then{ puts Ticker.new.get_year_end_closing('GOOG', 2013) }.
|
119
|
-
then{ puts Ticker.new.get_year_end_closing('AMZN', 2013) }.execute
|
120
|
-
prices.state #=> :pending
|
121
|
-
sleep(1) # do other stuff
|
122
|
-
#=> 561.02
|
123
|
-
#=> 37.41
|
124
|
-
#=> 1120.71
|
125
|
-
#=> 398.79
|
126
|
-
|
127
|
-
# ScheduledTask
|
128
|
-
task = Concurrent::ScheduledTask.execute(2){ Ticker.new.get_year_end_closing('INTC', 2013) }
|
129
|
-
task.state #=> :pending
|
130
|
-
sleep(3) # do other stuff
|
131
|
-
task.value #=> 25.96
|
159
|
+
```shell
|
160
|
+
BUILD_PURE_RUBY='true' bundle exec rake build
|
132
161
|
```
|
133
162
|
|
134
163
|
## Maintainers
|
@@ -139,22 +168,6 @@ task.value #=> 25.96
|
|
139
168
|
* [Lucas Allan](https://github.com/lucasallan)
|
140
169
|
* [Petr Chalupa](https://github.com/pitr-ch)
|
141
170
|
|
142
|
-
### Contributors
|
143
|
-
|
144
|
-
* [Bill Dueber](https://github.com/billdueber)
|
145
|
-
* [Brian Shirai](https://github.com/brixen)
|
146
|
-
* [Chip Miller](https://github.com/chip-miller)
|
147
|
-
* [Giuseppe Capizzi](https://github.com/gcapizzi)
|
148
|
-
* [Jamie Hodge](https://github.com/jamiehodge)
|
149
|
-
* [Justin Lambert](https://github.com/mastfish)
|
150
|
-
* [Larry Lv](https://github.com/larrylv)
|
151
|
-
* [Maxim Chechel](https://github.com/maximchick)
|
152
|
-
* [Ravil Bayramgalin](https://github.com/brainopia)
|
153
|
-
* [René Föhring](https://github.com/rrrene)
|
154
|
-
* [Shane Wilton](https://github.com/ShaneWilton)
|
155
|
-
* [sheaney](https://github.com/sheaney)
|
156
|
-
* [Zander Hill](https://github.com/zph)
|
157
|
-
|
158
171
|
### Contributing
|
159
172
|
|
160
173
|
1. Fork it
|
data/lib/concurrent/actor.rb
CHANGED
@@ -5,11 +5,17 @@ require 'concurrent/logging'
|
|
5
5
|
require 'concurrent/atomic/synchronization'
|
6
6
|
|
7
7
|
module Concurrent
|
8
|
-
# TODO https://github.com/celluloid/celluloid/wiki/Supervision-Groups
|
8
|
+
# TODO https://github.com/celluloid/celluloid/wiki/Supervision-Groups ?
|
9
|
+
# TODO Remote actors using DRb
|
10
|
+
# TODO IO interoperation
|
11
|
+
# TODO un/become
|
9
12
|
|
10
13
|
# TODO doc
|
11
14
|
# - what happens if I try to supervise using a normal Context?
|
12
|
-
|
15
|
+
# - how to change behaviours
|
16
|
+
# - how to implement custom restarting?
|
17
|
+
# - pool for io operations using different executor
|
18
|
+
# - document guaranteed ordering
|
13
19
|
|
14
20
|
# {include:file:doc/actor/main.md}
|
15
21
|
module Actor
|
@@ -26,7 +32,7 @@ module Concurrent
|
|
26
32
|
|
27
33
|
require 'concurrent/actor/default_dead_letter_handler'
|
28
34
|
require 'concurrent/actor/root'
|
29
|
-
require 'concurrent/actor/
|
35
|
+
require 'concurrent/actor/utils'
|
30
36
|
|
31
37
|
# @return [Reference, nil] current executing actor if any
|
32
38
|
def self.current
|
@@ -61,13 +67,10 @@ module Concurrent
|
|
61
67
|
# @param args see {.spawn_optionify}
|
62
68
|
# @return [Reference] never the actual actor
|
63
69
|
def self.spawn(*args, &block)
|
64
|
-
experimental_acknowledged? or
|
65
|
-
warn '[EXPERIMENTAL] A full release of `Actor`, is expected in the 0.7.0 release.'
|
66
|
-
|
67
70
|
if Actor.current
|
68
71
|
Core.new(spawn_optionify(*args).merge(parent: Actor.current), &block).reference
|
69
72
|
else
|
70
|
-
root.ask([:spawn, spawn_optionify(*args), block]).value
|
73
|
+
root.ask([:spawn, spawn_optionify(*args), block]).value!
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
@@ -77,7 +80,7 @@ module Concurrent
|
|
77
80
|
end
|
78
81
|
|
79
82
|
# @overload spawn_optionify(context_class, name, *args)
|
80
|
-
# @param [
|
83
|
+
# @param [AbstractContext] context_class to be spawned
|
81
84
|
# @param [String, Symbol] name of the instance, it's used to generate the {Core#path} of the actor
|
82
85
|
# @param args for context_class instantiation
|
83
86
|
# @overload spawn_optionify(opts)
|
@@ -94,11 +97,7 @@ module Concurrent
|
|
94
97
|
|
95
98
|
# call this to disable experimental warning
|
96
99
|
def self.i_know_it_is_experimental!
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.experimental_acknowledged?
|
101
|
-
!!@experimental_acknowledged
|
100
|
+
warn 'Method Actor.i_know_it_is_experimental! is deprecated. The Actors are no longer experimental.'
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Concurrent
|
2
2
|
module Actor
|
3
3
|
module Behaviour
|
4
|
-
# Simply fails when message arrives here.
|
4
|
+
# Simply fails when message arrives here. It's usually the last behaviour.
|
5
5
|
class ErrorsOnUnknownMessage < Abstract
|
6
6
|
def on_envelope(envelope)
|
7
7
|
raise UnknownMessage, envelope
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Concurrent
|
2
2
|
module Actor
|
3
3
|
module Behaviour
|
4
|
-
# Delegates messages
|
4
|
+
# Delegates messages and events to {AbstractContext} instance
|
5
5
|
class ExecutesContext < Abstract
|
6
6
|
def on_envelope(envelope)
|
7
7
|
context.on_envelope envelope
|