Class: Parallizer
- Inherits:
-
Object
- Object
- Parallizer
- Defined in:
- lib/parallizer.rb,
lib/parallizer/proxy.rb,
lib/parallizer/worker.rb,
lib/parallizer/version.rb,
lib/parallizer/method_call_notifier.rb
Defined Under Namespace
Classes: MethodCallNotifier, Proxy, Worker
Constant Summary collapse
- DEFAULT_WORK_QUEUE_SIZE =
10
- VERSION =
"0.4.0"
Instance Attribute Summary collapse
-
#call_infos ⇒ Object
readonly
Returns the value of attribute call_infos.
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Class Method Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
- #add_call(method_name, *args) ⇒ Object
- #create_proxy ⇒ Object
-
#initialize(client, options = {}) ⇒ Parallizer
constructor
A new instance of Parallizer.
Constructor Details
#initialize(client, options = {}) ⇒ Parallizer
Returns a new instance of Parallizer.
32 33 34 35 36 |
# File 'lib/parallizer.rb', line 32 def initialize(client, = {}) @client = client @options = {:retries => 0}.merge() @call_infos = {} end |
Instance Attribute Details
#call_infos ⇒ Object (readonly)
Returns the value of attribute call_infos.
30 31 32 |
# File 'lib/parallizer.rb', line 30 def call_infos @call_infos end |
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
30 31 32 |
# File 'lib/parallizer.rb', line 30 def calls @calls end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
30 31 32 |
# File 'lib/parallizer.rb', line 30 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/parallizer.rb', line 30 def @options end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
30 31 32 |
# File 'lib/parallizer.rb', line 30 def proxy @proxy end |
Class Method Details
.work_queue ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/parallizer.rb', line 18 def work_queue # TODO: share the work queue among calling threads?? queue = Thread.current[:parallizer_work_queue] if queue.nil? || Thread.current[:parallizer_work_queue_size] != work_queue_size queue = Thread.current[:parallizer_work_queue] = ::Parallizer::Worker.pool(:size => work_queue_size) Thread.current[:parallizer_work_queue_size] = work_queue_size end queue end |
.work_queue_size ⇒ Object
10 11 12 |
# File 'lib/parallizer.rb', line 10 def work_queue_size @work_queue_size || DEFAULT_WORK_QUEUE_SIZE end |
.work_queue_size=(work_queue_size) ⇒ Object
14 15 16 |
# File 'lib/parallizer.rb', line 14 def work_queue_size=(work_queue_size) @work_queue_size = work_queue_size end |
Instance Method Details
#add ⇒ Object
38 39 40 41 42 |
# File 'lib/parallizer.rb', line 38 def add ::Parallizer::MethodCallNotifier.new do |*args| add_call(*args) end end |
#add_call(method_name, *args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/parallizer.rb', line 48 def add_call(method_name, *args) raise ArgumentError, "Cannot add calls after proxy has been generated" if @proxy method_name_and_args = [method_name.to_sym, *args] return if call_infos[method_name_and_args] call_info = { :future => ::Parallizer::work_queue.future(:run, @client, method_name, args, ), :result => nil, :exception => nil } call_infos[method_name_and_args] = call_info end |
#create_proxy ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/parallizer.rb', line 62 def create_proxy raise ArgumentError, "Cannot create another proxy" if @proxy execute ::Parallizer::Proxy.new(client, call_infos) end |