Class: RightScale::MultiThreadBundleQueue
- Inherits:
-
BundleQueue
- Object
- BundleQueue
- RightScale::MultiThreadBundleQueue
- Defined in:
- lib/instance/multi_thread_bundle_queue.rb
Constant Summary collapse
- THREAD_QUEUE_CLOSED_BUNDLE =
'thread queue closed'
Constants inherited from BundleQueue
BundleQueue::FINAL_BUNDLE, BundleQueue::SHUTDOWN_BUNDLE
Instance Method Summary collapse
-
#activate ⇒ Object
Activate queue for execution, idempotent Any pending bundle will be run sequentially in order.
-
#active? ⇒ Boolean
Determines if queue is active.
-
#busy? ⇒ Boolean
Determines if queue is busy.
-
#clear ⇒ Object
Clear queue content.
-
#close ⇒ Object
Close queue so that further call to ‘push’ will be ignored.
-
#initialize(&continuation) ⇒ MultiThreadBundleQueue
constructor
Set continuation block to be called after ‘close’ is called.
-
#push(context) ⇒ Object
Push new context to bundle queue and run next bundle.
Constructor Details
#initialize(&continuation) ⇒ MultiThreadBundleQueue
Set continuation block to be called after ‘close’ is called
Block
continuation block
33 34 35 36 37 38 39 40 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 33 def initialize(&continuation) super(&continuation) @active = false @thread = nil @mutex = Mutex.new @queue = Queue.new @thread_name_to_queue = {} end |
Instance Method Details
#activate ⇒ Object
Activate queue for execution, idempotent Any pending bundle will be run sequentially in order
Return
- true
-
Always return true
57 58 59 60 61 62 63 64 65 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 57 def activate @mutex.synchronize do unless @active @thread = Thread.new { run } @active = true end end true end |
#active? ⇒ Boolean
Determines if queue is active
Return
- active(Boolean)
-
true if queue is active
46 47 48 49 50 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 46 def active? active = false @mutex.synchronize { active = @active } return active end |
#busy? ⇒ Boolean
Determines if queue is busy
Return
- active(Boolean)
-
true if queue is busy
71 72 73 74 75 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 71 def busy? busy = false @mutex.synchronize { busy = @thread_name_to_queue.any? { |_, q| q.busy? } } busy end |
#clear ⇒ Object
Clear queue content
Return
- true
-
Always return true
90 91 92 93 94 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 90 def clear @queue.clear @mutex.synchronize { @thread_name_to_queue.each_value { |queue| queue.clear } } true end |
#close ⇒ Object
Close queue so that further call to ‘push’ will be ignored
Return
- true
-
Always return true
100 101 102 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 100 def close push(FINAL_BUNDLE) end |
#push(context) ⇒ Object
Push new context to bundle queue and run next bundle
Return
- true
-
Always return true
81 82 83 84 |
# File 'lib/instance/multi_thread_bundle_queue.rb', line 81 def push(context) @queue << context true end |