Class: ZMQMachine::Device::Queue::Handler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Handler.



70
71
72
73
74
75
# File 'lib/zm/devices/queue.rb', line 70

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

Instance Attribute Details

#socket_outObject

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



77
78
79
80
81
# File 'lib/zm/devices/queue.rb', line 77

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

#on_readable(socket, messages) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/zm/devices/queue.rb', line 87

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

  if @socket_out
    # FIXME: need to be able to handle EAGAIN/failed send
    rc = socket_out.send_messages messages
  end
end

#on_writable(socket) ⇒ Object



83
84
85
# File 'lib/zm/devices/queue.rb', line 83

def on_writable socket
  @reactor.deregister_writable socket
end