Class: Wakame::CommandQueue
- Inherits:
-
Object
- Object
- Wakame::CommandQueue
- Defined in:
- lib/wakame/command_queue.rb
Instance Attribute Summary collapse
-
#master ⇒ Object
readonly
Returns the value of attribute master.
Instance Method Summary collapse
- #deq_cmd ⇒ Object
- #enq_result(res) ⇒ Object
-
#initialize(master) ⇒ CommandQueue
constructor
A new instance of CommandQueue.
- #send_cmd(cmd) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(master) ⇒ CommandQueue
Returns a new instance of CommandQueue.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wakame/command_queue.rb', line 13 def initialize(master) @master = master @queue = Queue.new @result_queue = Queue.new cmdsv_uri = URI.parse(Wakame.config.http_command_server_uri) @thin_server = Thin::Server.new(cmdsv_uri.host, cmdsv_uri.port, Adapter.new(self)) @thin_server.threaded = true @thin_server.start end |
Instance Attribute Details
#master ⇒ Object (readonly)
Returns the value of attribute master.
11 12 13 |
# File 'lib/wakame/command_queue.rb', line 11 def master @master end |
Instance Method Details
#deq_cmd ⇒ Object
29 30 31 |
# File 'lib/wakame/command_queue.rb', line 29 def deq_cmd() @queue.deq end |
#enq_result(res) ⇒ Object
33 34 35 |
# File 'lib/wakame/command_queue.rb', line 33 def enq_result(res) @result_queue.enq(res) end |
#send_cmd(cmd) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wakame/command_queue.rb', line 37 def send_cmd(cmd) begin #cmd = Marshal.load(cmd) @queue.enq(cmd) ED.fire_event(Event::CommandReceived.new(cmd)) return @result_queue.deq() rescue => e Wakame.log.error("#{self.class}:") Wakame.log.error(e) end end |
#shutdown ⇒ Object
25 26 27 |
# File 'lib/wakame/command_queue.rb', line 25 def shutdown @thin_server.stop end |