Class: ZMQMachine::Device::Queue::Handler
- Inherits:
-
Object
- Object
- ZMQMachine::Device::Queue::Handler
- Defined in:
- lib/zm/devices/queue.rb
Instance Attribute Summary collapse
-
#socket_out ⇒ Object
Returns the value of attribute socket_out.
Instance Method Summary collapse
-
#initialize(reactor, address, dir, opts = {}) ⇒ Handler
constructor
A new instance of Handler.
- #on_attach(socket) ⇒ Object
- #on_readable(socket, messages) ⇒ Object
- #on_writable(socket) ⇒ Object
- #set_options(socket) ⇒ Object
Constructor Details
#initialize(reactor, address, dir, opts = {}) ⇒ Handler
Returns a new instance of Handler.
70 71 72 73 74 75 76 |
# File 'lib/zm/devices/queue.rb', line 70 def initialize reactor, address, dir, opts = {} @reactor = reactor @address = address @verbose = opts[:verbose] || false @opts = opts @dir = dir end |
Instance Attribute Details
#socket_out ⇒ Object
Returns the value of attribute socket_out.
68 69 70 |
# File 'lib/zm/devices/queue.rb', line 68 def socket_out @socket_out end |
Instance Method Details
#on_attach(socket) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/zm/devices/queue.rb', line 78 def on_attach socket socket.identity = "queue.#{Kernel.rand(999_999_999)}" socket rc = socket.bind @address #FIXME: error handling! end |
#on_readable(socket, messages) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/zm/devices/queue.rb', line 89 def on_readable socket, .each { |msg| @reactor.log(:device, "[Q#{@dir}] [#{msg.copy_out_string}]") } if @verbose if @socket_out # FIXME: need to be able to handle EAGAIN/failed send rc = socket_out. .each { || .close } end end |
#on_writable(socket) ⇒ Object
85 86 87 |
# File 'lib/zm/devices/queue.rb', line 85 def on_writable socket @reactor.deregister_writable socket end |
#set_options(socket) ⇒ Object
99 100 101 102 |
# File 'lib/zm/devices/queue.rb', line 99 def socket socket.raw_socket.setsockopt ZMQ::HWM, (@opts[:hwm] || 1) socket.raw_socket.setsockopt ZMQ::LINGER, (@opts[:linger] || 0) end |