lib/pigato/client.rb in pigato-0.2.20 vs lib/pigato/client.rb in pigato-0.2.21

- old
+ new

@@ -1,7 +1,9 @@ require 'thread' +$PIGATO_zmq_ctx = 0 + class Pigato::Client def initialize broker, conf = {} @broker = broker @ctxs = {} @@ -23,11 +25,11 @@ pid = "#" + Process.pid.to_s pid end def get_thread_id - tid = get_proc_id() + "|" + Thread.current.object_id.to_s + tid = "#" + get_proc_id() + "#" + Thread.current.object_id.to_s tid end def request service, request, opts = {} return nil if @sockets[get_thread_id()] == nil @@ -85,16 +87,14 @@ end end def reconnect_to_broker stop - ctx = @ctxs[get_proc_id()] - if ctx == nil - ctx = ZMQ::Context.new - ctx.linger = 0 - @ctxs[get_proc_id()] = ctx + if $PIGATO_zmq_ctx == nil + $PIGATO_zmq_ctx = ZMQ::Context.new + $PIGATO_zmq_ctx.linger = 0 end - socket = ctx.socket ZMQ::DEALER + socket = $PIGATO_zmq_ctx.socket ZMQ::DEALER socket.identity = SecureRandom.uuid socket.connect @broker @sockets[get_thread_id()] = socket end end