lib/pigato/client.rb in pigato-0.2.19 vs lib/pigato/client.rb in pigato-0.2.20
- old
+ new
@@ -1,13 +1,12 @@
require 'thread'
-$PIGATO_zmq_ctx = nil
-
class Pigato::Client
def initialize broker, conf = {}
@broker = broker
+ @ctxs = {}
@sockets = {}
@conf = {
:autostart => false,
:timeout => 2500
@@ -86,15 +85,16 @@
end
end
def reconnect_to_broker
stop
- if $PIGATO_zmq_ctx == nil
+ ctx = @ctxs[get_proc_id()]
+ if ctx == nil
ctx = ZMQ::Context.new
ctx.linger = 0
- $PIGATO_zmq_ctx = ctx
+ @ctxs[get_proc_id()] = ctx
end
- socket = $PIGATO_zmq_ctx.socket ZMQ::DEALER
+ socket = ctx.socket ZMQ::DEALER
socket.identity = SecureRandom.uuid
socket.connect @broker
@sockets[get_thread_id()] = socket
end
end