Skip to content

Commit e78e7d7

Browse files
committed
Merge branch 'master' into channels
Conflicts: lib/concurrent.rb
2 parents b8b0ab1 + 0592010 commit e78e7d7

23 files changed

+772
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ into several general groups:
5656
* Thread-safe variables including [M-Structures](https://github.com/jdantonio/concurrent-ruby/wiki/MVar-(M-Structure)),
5757
[I-Structures](https://github.com/jdantonio/concurrent-ruby/wiki/IVar-(I-Structure)),
5858
[thread-local variables](https://github.com/jdantonio/concurrent-ruby/wiki/ThreadLocalVar),
59-
and atomic counters
59+
atomic counters, and [software transactional memory](https://github.com/jdantonio/concurrent-ruby/wiki/TVar-(STM))
6060
* Thread synchronization classes and algorithms including [dataflow](https://github.com/jdantonio/concurrent-ruby/wiki/Dataflow),
6161
timeout, condition, countdown latch, dependency counter, and event
6262
* Java-inspired [thread pools](https://github.com/jdantonio/concurrent-ruby/wiki/Thread%20Pools)

lib/concurrent.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
require 'concurrent/channel/ring_buffer'
4040
require 'concurrent/channel/blocking_ring_buffer'
4141

42+
require 'concurrent/actor_context'
43+
require 'concurrent/simple_actor_ref'
44+
4245
require 'concurrent/cached_thread_pool'
4346
require 'concurrent/fixed_thread_pool'
4447
require 'concurrent/immediate_executor'

lib/concurrent/actor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def initialize(queue)
179179
#
180180
# @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
181181
def self.pool(count, *args, &block)
182+
warn '[DEPRECATED] `Actor` is deprecated and will be replaced with `ActorContext`.'
182183
raise ArgumentError.new('count must be greater than zero') unless count > 0
183184
mailbox = Queue.new
184185
actors = count.times.collect do
@@ -211,13 +212,15 @@ def self.pool(count, *args, &block)
211212
#
212213
# @!visibility public
213214
def act(*message)
215+
warn '[DEPRECATED] `Actor` is deprecated and will be replaced with `ActorContext`.'
214216
raise NotImplementedError.new("#{self.class} does not implement #act")
215217
end
216218

217219
# @!visibility private
218220
#
219221
# @deprecated +Actor+ is being replaced with a completely new framework prior to v1.0.0
220222
def on_run # :nodoc:
223+
warn '[DEPRECATED] `Actor` is deprecated and will be replaced with `ActorContext`.'
221224
queue.clear
222225
end
223226

lib/concurrent/actor_context.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'concurrent/simple_actor_ref'
2+
3+
module Concurrent
4+
5+
module ActorContext
6+
7+
def on_start
8+
end
9+
10+
def on_reset
11+
end
12+
13+
def on_shutdown
14+
end
15+
16+
def self.included(base)
17+
18+
class << base
19+
protected :new
20+
21+
def spawn(opts = {})
22+
args = opts.fetch(:args, [])
23+
Concurrent::SimpleActorRef.new(self.new(*args), opts)
24+
end
25+
end
26+
end
27+
end
28+
end

lib/concurrent/actor_ref.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'concurrent/copy_on_notify_observer_set'
2+
3+
module Concurrent
4+
5+
module ActorRef
6+
7+
#NOTE: Required API methods
8+
# Must be implemented in all subclasses
9+
#def post(*msg, &block)
10+
#def post!(*msg)
11+
#def running?
12+
#def shutdown?
13+
#def shutdown
14+
#def join(timeout = nil)
15+
16+
def <<(message)
17+
post(*message)
18+
self
19+
end
20+
21+
def add_observer(*args)
22+
@observers.add_observer(*args)
23+
end
24+
25+
def delete_observer(*args)
26+
@observers.delete_observer(*args)
27+
end
28+
29+
def delete_observers
30+
@observers.delete_observers
31+
end
32+
33+
protected
34+
35+
def observers
36+
@observers ||= CopyOnNotifyObserverSet.new
37+
end
38+
end
39+
end

lib/concurrent/atomic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def initialize(init = 0)
109109
allocate_storage(init)
110110
end
111111

112-
if defined? java.util
112+
if RUBY_PLATFORM == 'java'
113113
include JavaAtomicFixnum
114114
else
115115
include MutexAtomicFixnum

lib/concurrent/cached_thread_pool.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22

33
module Concurrent
44

5-
if defined? java.util
5+
if RUBY_PLATFORM == 'java'
66
require 'concurrent/java_cached_thread_pool'
77
# @!macro [attach] cached_thread_pool
88
# A thread pool that dynamically grows and shrinks to fit the current workload.
99
# New threads are created as needed, existing threads are reused, and threads
1010
# that remain idle for too long are killed and removed from the pool. These
1111
# pools are particularly suited to applications that perform a high volume of
1212
# short-lived tasks.
13-
#
13+
#
1414
# On creation a +CachedThreadPool+ has zero running threads. New threads are
1515
# created on the pool as new operations are +#post+. The size of the pool
1616
# will grow until +#max_length+ threads are in the pool or until the number
1717
# of threads exceeds the number of running and pending operations. When a new
1818
# operation is post to the pool the first available idle thread will be tasked
1919
# with the new operation.
20-
#
20+
#
2121
# Should a thread crash for any reason the thread will immediately be removed
2222
# from the pool. Similarly, threads which remain idle for an extended period
2323
# of time will be killed and reclaimed. Thus these thread pools are very
2424
# efficient at reclaiming unused resources.
25-
#
25+
#
2626
# The API and behavior of this class are based on Java's +CachedThreadPool+
2727
#
2828
# @note When running on the JVM (JRuby) this class will inherit from +JavaCachedThreadPool+.
2929
# On all other platforms it will inherit from +RubyCachedThreadPool+.
3030
#
3131
# @see Concurrent::RubyCachedThreadPool
3232
# @see Concurrent::JavaCachedThreadPool
33-
#
33+
#
3434
# @see http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html
3535
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html
3636
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html

lib/concurrent/fixed_thread_pool.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Concurrent
44

5-
if defined? java.util
5+
if RUBY_PLATFORM == 'java'
66
require 'concurrent/java_fixed_thread_pool'
77
# @!macro [attach] fixed_thread_pool
88
#
@@ -11,15 +11,15 @@ module Concurrent
1111
# tasks +#post+ to the thread pool are enqueued until a thread becomes available.
1212
# Should a thread crash for any reason the thread will immediately be removed
1313
# from the pool and replaced.
14-
#
14+
#
1515
# The API and behavior of this class are based on Java's +FixedThreadPool+
1616
#
1717
# @note When running on the JVM (JRuby) this class will inherit from +JavaFixedThreadPool+.
1818
# On all other platforms it will inherit from +RubyFixedThreadPool+.
1919
#
2020
# @see Concurrent::RubyFixedThreadPool
2121
# @see Concurrent::JavaFixedThreadPool
22-
#
22+
#
2323
# @see http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html
2424
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html
2525
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html

lib/concurrent/java_cached_thread_pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if defined? java.util
1+
if RUBY_PLATFORM == 'java'
22

33
require 'concurrent/java_thread_pool_executor'
44

lib/concurrent/java_fixed_thread_pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if defined? java.util
1+
if RUBY_PLATFORM == 'java'
22

33
require 'concurrent/java_thread_pool_executor'
44

0 commit comments

Comments
 (0)