Class: ZMQMachine::Device::Forwarder::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/devices/forwarder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reactor, address, verbose = false) ⇒ Handler

Returns a new instance of Handler.



68
69
70
71
72
# File 'lib/zm/devices/forwarder.rb', line 68

def initialize reactor, address, verbose = false
  @reactor = reactor
  @address = address
  @verbose = verbose
end

Instance Attribute Details

#socket_outObject

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



74
75
76
77
78
79
80
# File 'lib/zm/devices/forwarder.rb', line 74

def on_attach socket
  socket.identity = "forwarder.#{Kernel.rand(999_999_999)}"
  rc = socket.bind @address
  #FIXME: error handling!

  socket.subscribe_all if :sub == socket.kind
end

#on_readable(socket, messages) ⇒ Object



86
87
88
89
90
# File 'lib/zm/devices/forwarder.rb', line 86

def on_readable socket, messages
  messages.each { |msg| puts "[fwd] [#{msg.copy_out_string}]" } if @verbose

  socket_out.send_messages messages if @socket_out
end

#on_writable(socket) ⇒ Object



82
83
84
# File 'lib/zm/devices/forwarder.rb', line 82

def on_writable socket
  @reactor.deregister_writable socket
end