Class: DripDrop::ZMQBaseHandler

Inherits:
BaseHandler show all
Defined in:
lib/dripdrop/handlers/zeromq.rb

Direct Known Subclasses

ZMQPubHandler, ZMQPullHandler, ZMQPushHandler, ZMQSubHandler, ZMQXRepHandler, DripDrop::ZMQXRepHandler::Response, ZMQXReqHandler

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ZMQBaseHandler) initialize(zaddress, zm_reactor, socket_ctype, opts = {})

A new instance of ZMQBaseHandler



14
15
16
17
18
19
20
21
# File 'lib/dripdrop/handlers/zeromq.rb', line 14

def initialize(zaddress,zm_reactor,socket_ctype,opts={})
  @zaddress     = zaddress
  @address      = @zaddress.to_s
  @zm_reactor   = zm_reactor
  @socket_ctype = socket_ctype # :bind or :connect
  @debug        = opts[:debug] # TODO: Start actually using this
  @opts         = opts
end

Instance Attribute Details

- (Object) address (readonly)

Returns the value of attribute address



12
13
14
# File 'lib/dripdrop/handlers/zeromq.rb', line 12

def address
  @address
end

- (Object) socket (readonly)

Returns the value of attribute socket



12
13
14
# File 'lib/dripdrop/handlers/zeromq.rb', line 12

def socket
  @socket
end

- (Object) socket_ctype (readonly)

Returns the value of attribute socket_ctype



12
13
14
# File 'lib/dripdrop/handlers/zeromq.rb', line 12

def socket_ctype
  @socket_ctype
end

Instance Method Details

- (Object) on_attach(socket)



23
24
25
26
27
28
29
30
31
32
# File 'lib/dripdrop/handlers/zeromq.rb', line 23

def on_attach(socket)
  @socket = socket
  if    @socket_ctype == :bind
    socket.bind(@zaddress)
  elsif @socket_ctype == :connect
    socket.connect(@zaddress)
  else
    raise "Unsupported socket ctype '#{@socket_ctype}'. Expected :bind or :connect"
  end
end

- (Object) on_recv(msg_format = :dripdrop, &block)



34
35
36
37
38
# File 'lib/dripdrop/handlers/zeromq.rb', line 34

def on_recv(msg_format=:dripdrop,&block)
  @msg_format = msg_format
  @recv_cbak = block
  self
end