Class: BlastBeat::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/blastbeat.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, nodename, threads = 1) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
11
# File 'lib/blastbeat.rb', line 6

def initialize(server, nodename, threads=1)
  @context = ZMQ::Context.create(threads)
  @socket = @context.socket(ZMQ::DEALER)
  @socket.setsockopt(ZMQ::IDENTITY, nodename)
  @socket.connect(server)
end

Instance Method Details

#recvObject



13
14
15
16
17
# File 'lib/blastbeat.rb', line 13

def recv
    parts = []
    @socket.recv_strings(parts)
    parts
end

#send(sid, msg_type, msg_body = '') ⇒ Object



19
20
21
# File 'lib/blastbeat.rb', line 19

def send(sid, msg_type, msg_body='')
  @socket.send_strings([sid, msg_type, msg_body])
end

#uwsgi(pkt) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/blastbeat.rb', line 23

def uwsgi(pkt)
  ulen, = pkt[1,2].unpack('v')
  pos = 4
  h = Hash.new
  while pos < ulen
    klen, = pkt[pos,2].unpack('v')
    k = pkt[pos+2, klen]
    pos += 2+klen
    vlen, = pkt[pos,2].unpack('v')
    v = pkt[pos+2, vlen]
    pos += 2+vlen
    h[k] = v
  end
  h
end