Class: Parallizer
- Inherits:
-
Object
- Object
- Parallizer
- Includes:
- HangingMethods
- Defined in:
- lib/parallizer.rb,
lib/parallizer/proxy.rb,
lib/parallizer/worker.rb,
lib/parallizer/version.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_WORK_QUEUE_SIZE =
10
- VERSION =
"0.4.7"
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
- .in_parallizer_thread? ⇒ Boolean
- .work_queue ⇒ Object
- .work_queue_size ⇒ Object
- .work_queue_size=(work_queue_size) ⇒ Object
Instance Method Summary collapse
- #add_call(method_name, *args) ⇒ Object
- #all_call_results ⇒ 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.
41 42 43 44 45 |
# File 'lib/parallizer.rb', line 41 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.
39 40 41 |
# File 'lib/parallizer.rb', line 39 def call_infos @call_infos end |
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
39 40 41 |
# File 'lib/parallizer.rb', line 39 def calls @calls end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
39 40 41 |
# File 'lib/parallizer.rb', line 39 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
39 40 41 |
# File 'lib/parallizer.rb', line 39 def @options end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
39 40 41 |
# File 'lib/parallizer.rb', line 39 def proxy @proxy end |
Class Method Details
.in_parallizer_thread? ⇒ Boolean
34 35 36 |
# File 'lib/parallizer.rb', line 34 def in_parallizer_thread? Thread.current[:parallizer_thread] == true end |
.work_queue ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/parallizer.rb', line 23 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
15 16 17 |
# File 'lib/parallizer.rb', line 15 def work_queue_size @work_queue_size || DEFAULT_WORK_QUEUE_SIZE end |
.work_queue_size=(work_queue_size) ⇒ Object
19 20 21 |
# File 'lib/parallizer.rb', line 19 def work_queue_size=(work_queue_size) @work_queue_size = work_queue_size end |
Instance Method Details
#add_call(method_name, *args) ⇒ Object
51 52 53 |
# File 'lib/parallizer.rb', line 51 def add_call(method_name, *args) add.send(method_name, *args) end |
#all_call_results ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/parallizer.rb', line 63 def all_call_results proxy = create_proxy call_infos.keys.inject({}) do |result, method_name_and_args| result[method_name_and_args] = proxy.send(*method_name_and_args) result end end |
#create_proxy ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/parallizer.rb', line 55 def create_proxy raise ArgumentError, "Cannot create another proxy" if @proxy execute ::Parallizer::Proxy.new(client, call_infos) end |