Class: RightScale::SingleThreadBundleQueue
- Inherits:
-
BundleQueue
- Object
- BundleQueue
- RightScale::SingleThreadBundleQueue
- Defined in:
- lib/instance/single_thread_bundle_queue.rb
Constant Summary
Constants inherited from BundleQueue
BundleQueue::FINAL_BUNDLE, BundleQueue::SHUTDOWN_BUNDLE
Instance Attribute Summary collapse
-
#thread_name ⇒ Object
readonly
Returns the value of attribute thread_name.
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(thread_name = ::RightScale::AgentConfig.default_thread_name, &continuation) ⇒ SingleThreadBundleQueue
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(thread_name = ::RightScale::AgentConfig.default_thread_name, &continuation) ⇒ SingleThreadBundleQueue
Set continuation block to be called after ‘close’ is called
Block
continuation block
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 33 def initialize(thread_name = ::RightScale::AgentConfig.default_thread_name, &continuation) super(&continuation) @active = false @thread = nil @thread_name = thread_name @pid = nil @mutex = Mutex.new @queue = Queue.new @sequence_finished = ConditionVariable.new end |
Instance Attribute Details
#thread_name ⇒ Object (readonly)
Returns the value of attribute thread_name.
27 28 29 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 27 def thread_name @thread_name 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
59 60 61 62 63 64 65 66 67 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 59 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
48 49 50 51 52 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 48 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
73 74 75 76 77 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 73 def busy? busy = false @mutex.synchronize { busy = !!@busy } busy end |
#clear ⇒ Object
Clear queue content
Return
- true
-
Always return true
92 93 94 95 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 92 def clear @queue.clear true end |
#close ⇒ Object
Close queue so that further call to ‘push’ will be ignored
Return
- true
-
Always return true
101 102 103 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 101 def close push(FINAL_BUNDLE) end |
#push(context) ⇒ Object
Push new context to bundle queue and run next bundle
Return
- true
-
Always return true
83 84 85 86 |
# File 'lib/instance/single_thread_bundle_queue.rb', line 83 def push(context) @queue << context true end |