Class: Sappho::Heatmiser::Proxy::CommandQueue
- Inherits:
-
Object
- Object
- Sappho::Heatmiser::Proxy::CommandQueue
- Includes:
- LogUtilities, Singleton
- Defined in:
- lib/sappho-heatmiser-proxy/command_queue.rb
Instance Method Summary collapse
- #completed ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ CommandQueue
constructor
A new instance of CommandQueue.
- #push(clientIP, command) ⇒ Object
Constructor Details
#initialize ⇒ CommandQueue
Returns a new instance of CommandQueue.
18 19 20 21 22 |
# File 'lib/sappho-heatmiser-proxy/command_queue.rb', line 18 def initialize @queue = [] @mutex = Mutex.new @log = Sappho::ApplicationAutoFlushLog.instance end |
Instance Method Details
#completed ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/sappho-heatmiser-proxy/command_queue.rb', line 46 def completed @mutex.synchronize do if @queue.size > 0 queue = @queue[0] @log.info "client #{queue[:clientIP]} command completed: #{hexString queue[:command]}" @queue.shift end end end |
#get ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sappho-heatmiser-proxy/command_queue.rb', line 34 def get command = nil @mutex.synchronize do if @queue.size > 0 queue = @queue[0] command = queue[:command].dup @log.info "client #{queue[:clientIP]} command executing: #{hexString command}" end end command end |
#push(clientIP, command) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/sappho-heatmiser-proxy/command_queue.rb', line 24 def push clientIP, command @log.info "client #{clientIP} requests command: #{hexString command}" @mutex.synchronize do @queue << { :clientIP => clientIP, :command => command.dup } end end |