Class: Hope::Source::Sub

Inherits:
Base show all
Defined in:
lib/hope/source/sub.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #options

Instance Method Summary collapse

Methods inherited from Base

event_types, #parse, #serializable_hash, #to_json

Constructor Details

#initialize(name, opts = {}) ⇒ Sub

Returns a new instance of Sub.



7
8
9
10
11
12
13
14
15
# File 'lib/hope/source/sub.rb', line 7

def initialize name, opts={}
  @name = name
  @socket = opts["socket"] || "ipc://hope"
  @event_type = opts["event_type"]
  @received = { :success => 0, :errors => 0, :latest_error => "" }
  @sub = Hope.ctx.connect ZMQ::SUB, @socket, self
  @sub.subscribe name
  Hope::Source.register self
end

Instance Attribute Details

#receivedObject (readonly)

Returns the value of attribute received.



5
6
7
# File 'lib/hope/source/sub.rb', line 5

def received
  @received
end

Instance Method Details

#on_readable(socket, messages) ⇒ Object



17
18
19
20
21
# File 'lib/hope/source/sub.rb', line 17

def on_readable(socket, messages)
  @received[:success] += 1
  src, evt = messages.map &:copy_out_string
  Hope.pub.send_msg src, { "data" => evt, "type" => @event_type }.to_json
end