Class: DripDrop::ZMQSubHandler

Inherits:
ZMQBaseHandler show all
Includes:
ZMQReadableHandler
Defined in:
lib/dripdrop/handlers/zeromq.rb

Instance Attribute Summary collapse

Attributes included from ZMQReadableHandler

#message_class

Attributes inherited from ZMQBaseHandler

#connection

Instance Method Summary collapse

Methods included from ZMQReadableHandler

#decode_message

Methods inherited from ZMQBaseHandler

#address, #on_recv

Methods inherited from BaseHandler

#handle_error, #on_error, #print_exception

Constructor Details

#initialize(*args) ⇒ ZMQSubHandler

Returns a new instance of ZMQSubHandler.



133
134
135
136
# File 'lib/dripdrop/handlers/zeromq.rb', line 133

def initialize(*args)
  super(*args)
  self.topic_filter = @opts[:topic_filter]
end

Instance Attribute Details

#topic_filterObject

Returns the value of attribute topic_filter.



131
132
133
# File 'lib/dripdrop/handlers/zeromq.rb', line 131

def topic_filter
  @topic_filter
end

Instance Method Details

#on_readable(socket, messages) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/dripdrop/handlers/zeromq.rb', line 138

def on_readable(socket, messages)
  if @msg_format == :dripdrop
    unless messages.length == 2
      return false
    end
    topic = messages.shift.copy_out_string
    if @topic_filter.nil? || topic.match(@topic_filter)
      body  = messages.shift.copy_out_string
      @recv_cbak.call(decode_message(body))
    end
  else
    super(socket,messages)
  end
end

#post_setupObject



153
154
155
156
# File 'lib/dripdrop/handlers/zeromq.rb', line 153

def post_setup
  super
  @connection.socket.setsockopt(ZMQ::SUBSCRIBE, '')
end