Class: ModSpox::Monitors::Boolean
- Inherits:
-
Object
- Object
- ModSpox::Monitors::Boolean
- Defined in:
- lib/mod_spox/Monitors.rb
Overview
The Boolean is a boolean based monitor (thus the “Boolean” part of the name)
Instance Method Summary collapse
-
#initialize ⇒ Boolean
constructor
Create a new Boolean Monitor.
-
#remove_thread(thread) ⇒ Object
Removes a thread from the list of waiting.
-
#thread_waiting?(thread) ⇒ Boolean
Returns if a thread is currently waiting in this monitor.
-
#wait ⇒ Object
Start waiting.
-
#wakeup ⇒ Object
Stop waiting.
Constructor Details
#initialize ⇒ Boolean
Create a new Boolean Monitor
36 37 38 |
# File 'lib/mod_spox/Monitors.rb', line 36 def initialize @threads = [] end |
Instance Method Details
#remove_thread(thread) ⇒ Object
Removes a thread from the list of waiting. Will be removed automatically if thread has been killed on next call to wakeup
70 71 72 |
# File 'lib/mod_spox/Monitors.rb', line 70 def remove_thread(thread) @threads.delete(thread) if @threads.include?(thread) end |
#thread_waiting?(thread) ⇒ Boolean
Returns if a thread is currently waiting in this monitor
64 65 66 |
# File 'lib/mod_spox/Monitors.rb', line 64 def thread_waiting?(thread) return @threads.include?(thread) end |
#wait ⇒ Object
Start waiting
57 58 59 60 61 |
# File 'lib/mod_spox/Monitors.rb', line 57 def wait @threads << Thread.current Logger.log("Stopping execution of thread: #{Thread.current}", 5) Thread.stop end |
#wakeup ⇒ Object
Stop waiting
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mod_spox/Monitors.rb', line 41 def wakeup return if @threads.empty? @threads.each do |thread| if(thread.status == 'sleep') Logger.log("Sending wakeup for thread: #{thread}", 5) thread.run Logger.log("Status of thread to wakeup: #{thread.status}", 5) Logger.log("Calling thread is: #{Thread.current}", 5) else Logger.log("Thread to wakeup has been killed: #{thread}") end @threads.delete(thread) end end |