Class: ZMQMachine::Device::Forwarder::Handler
- Inherits:
-
Object
- Object
- ZMQMachine::Device::Forwarder::Handler
- Defined in:
- lib/zm/devices/forwarder.rb
Instance Attribute Summary collapse
-
#socket_out ⇒ Object
Returns the value of attribute socket_out.
Instance Method Summary collapse
-
#initialize(reactor, address, 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, opts = {}) ⇒ Handler
Returns a new instance of Handler.
68 69 70 71 72 73 74 75 |
# File 'lib/zm/devices/forwarder.rb', line 68 def initialize reactor, address, opts = {} @reactor = reactor @address = address @verbose = opts[:verbose] || false @opts = opts @messages = [] end |
Instance Attribute Details
#socket_out ⇒ Object
Returns the value of attribute socket_out.
66 67 68 |
# File 'lib/zm/devices/forwarder.rb', line 66 def socket_out @socket_out end |
Instance Method Details
#on_attach(socket) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/zm/devices/forwarder.rb', line 77 def on_attach socket socket.identity = "forwarder.#{Kernel.rand(999_999_999)}" socket rc = socket.bind @address #FIXME: error handling! socket.subscribe_all if :sub == socket.kind end |
#on_readable(socket, messages) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/zm/devices/forwarder.rb', line 89 def on_readable socket, .each { |msg| @reactor.log(:device, "[fwd] [#{msg.copy_out_string}]") } if @verbose if @socket_out rc = socket_out. .each { || .close } end end |
#on_writable(socket) ⇒ Object
85 86 87 |
# File 'lib/zm/devices/forwarder.rb', line 85 def on_writable socket @reactor.deregister_writable socket end |
#set_options(socket) ⇒ Object
98 99 100 101 |
# File 'lib/zm/devices/forwarder.rb', line 98 def socket socket.raw_socket.setsockopt ZMQ::HWM, (@opts[:hwm] || 1) socket.raw_socket.setsockopt ZMQ::LINGER, (@opts[:linger] || 0) end |