Example #1
0
class RoundRobinService(client.RoundRobinClient):

    def __init__(self, ctx, addr, ident=None):
        self.recvq = None
        self.ctx = ctx
        super(RoundRobinService, self).__init__(ctx, addr, ident)


    def register(self, target):
        self.send('register', target, {})
        style, topic, resp = self.recv()
        self.recv_addr = resp['address']
        self.recvq = QueueSocket(self.ctx, self.recv_addr, zmq.PULL, send=False, bind=False)


    def pull(self):
        assert self.recvq, "You need to register first."
        data = self.recvq.recv()
        data[-1] = pickle.loads(data[-1])
        return data

    def reply(self, client_id, style, target, data):
        self.outq.send([client_id, style, target, pickle.dumps(data)])

    def close(self):
        self.outq.close()
        self.recvq.close()
Example #2
0
class PubSubClient(object):

    def __init__(self, ctx, addr, ident):
        self.outq = QueueSocket(ctx, addr, zmq.XREQ,
                                recv=False, bind=False, ident=ident)

    def cast(self, target, data):
        self.outq.send(['cast', target, pickle.dumps(data)])

    def close(self):
        self.outq.close()
Example #3
0
class PubSubService(object):

    def __init__(self, ctx, addr, subscribe):
        self.inqueue = QueueSocket(ctx, addr, zmq.SUB, bind=False,
                                   send=False, subscribe=subscribe)

    def pull(self):
        data = self.inqueue.recv()
        data[-1] = pickle.loads(data[-1])
        return data

    def close(self):
        self.inqueue.close()
Example #4
0
class P2PConnection(object):

    def __init__(self, ctx, addr, ident, sock_type=zmq.XREQ):
        self.queue = QueueSocket(ctx, addr, sock_type, bind=False,
                                   ident=ident)

    def send(self, style, target, data):
        self.queue.send([style, target, pickle.dumps(data)])

    def recv(self):
        data = self.queue.recv()
        data[-1] = pickle.loads(data[-1])
        return data

    def call(self, target, data):
        self.send('call', target, data)
        return self.recv()

    def cast(self, target, data):
        self.send('cast', target, data)

    def reply(self, target, style, client_id, data):
        self.queue.send([target, style, client_id, pickle.dumps(data)])

    def close(self):
        self.queue.close()
Example #5
0
class RoundRobinClient(object):

    def __init__(self, ctx, addr, ident):
        self.outq = QueueSocket(ctx, addr, zmq.XREQ,
                                bind=False, ident=ident)

    def send(self, style, target, data):
        self.outq.send([style, target, pickle.dumps(data)])

    def recv(self):
        data = self.outq.recv()
        data[-1] = pickle.loads(data[-1])
        return data


    def call(self, target, data):
        self.send('call', target, data)
        return self.recv()

    def cast(self, target, data):
        self.send('cast', target, data)

    def close(self):
        self.outq.close()
Example #6
0
 def __init__(self, ctx, addr, ident):
     self.outq = QueueSocket(ctx, addr, zmq.XREQ,
                             bind=False, ident=ident)
Example #7
0
 def __init__(self, ctx, addr, ident, sock_type=zmq.XREQ):
     self.queue = QueueSocket(ctx, addr, sock_type, bind=False,
                                ident=ident)
Example #8
0
 def __init__(self, ctx, addr, subscribe):
     self.inqueue = QueueSocket(ctx, addr, zmq.SUB, bind=False,
                                send=False, subscribe=subscribe)
Example #9
0
 def register(self, target):
     self.send('register', target, {})
     style, topic, resp = self.recv()
     self.recv_addr = resp['address']
     self.recvq = QueueSocket(self.ctx, self.recv_addr, zmq.PULL, send=False, bind=False)