Class: Kymera::SZMQ

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSZMQ

Returns a new instance of SZMQ.



6
7
8
9
# File 'lib/kymera/szmq/szmq.rb', line 6

def initialize()
  SZMQ.context

end

Class Method Details

.contextObject



11
12
13
# File 'lib/kymera/szmq/szmq.rb', line 11

def self.context
  @context ||= ZMQ::Context.new
end

Instance Method Details

#socket(address, type) ⇒ Object

returns a SSocket object



16
17
18
# File 'lib/kymera/szmq/szmq.rb', line 16

def socket(address, type)
  SSocket.new(address, type)
end

#start_proxy(frontend_socket, backend_socket) ⇒ Object

Takes two SSocket objects. One representing the client and other representing the worker. Upon receiving a INT command (ctrl + c), the proxy still be shut down and the frontend and backend sockets will be closed



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kymera/szmq/szmq.rb', line 22

def start_proxy(frontend_socket, backend_socket)

  trap ("INT") do
    puts "\nStopping proxy..."
    frontend_socket.close
    backend_socket.close
    @close = true
  end

  frontend_socket.bind
  backend_socket.bind

  ZMQ::Device.new(frontend_socket.send(:get_socket), backend_socket.send(:get_socket))
  #ZMQ::Device.new(backend_socket.send(:get_socket), frontend_socket.send(:get_socket))

  #while !@close do
  #  text = "\r"
  #  text << "Online"
  #  space = " "
  #  0.upto(2) do
  #    STDOUT.print text
  #    sleep 0.5
  #    STDOUT.print "\r#{space * (text.length - 1)}"
  #    sleep 0.5
  #  end
  #end
end

#start_pub_sub_proxy(front_end, back_end) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kymera/szmq/szmq.rb', line 50

def start_pub_sub_proxy(front_end, back_end)
  trap ("INT") do
    puts "\nStopping proxy..."
    front_end.close
    back_end.close
    @close = true
  end

  front_end.bind
  back_end.bind

  ZMQ::Device.new(front_end.send(:get_socket), back_end.send(:get_socket))


end