def initialize(self): self.client = self.context.socket(zmq.DEALER) self.client.setsockopt(zmq.IDENTITY, self._id) get_connection(self.client, self.endpoint, self.ssh_server) self.client.linger = 0 self.sub_socket = self.context.socket(zmq.SUB) self.sub_socket.setsockopt(zmq.SUBSCRIBE, b'watcher.') self.sub_socket.connect(self.pubsub_endpoint) self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop) self.substream.on_recv(self.handle_recv)
def __init__(self, context=None, endpoint=DEFAULT_ENDPOINT_DEALER, timeout=5.0, ssh_server=None, ssh_keyfile=None): self._init_context(context) self.endpoint = endpoint self._id = uuid.uuid4().hex self.socket = self.context.socket(zmq.DEALER) self.socket.setsockopt(zmq.IDENTITY, self._id) self.socket.setsockopt(zmq.LINGER, 0) get_connection(self.socket, endpoint, ssh_server, ssh_keyfile) self._init_poller() self._timeout = timeout self.timeout = timeout * 1000
def __init__(self, context=None, endpoint=DEFAULT_ENDPOINT_DEALER, timeout=5.0, ssh_server=None, ssh_keyfile=None): self._init_context(context) self.endpoint = endpoint self._id = b(uuid.uuid4().hex) self.socket = self.context.socket(zmq.DEALER) self.socket.setsockopt(zmq.IDENTITY, self._id) self.socket.setsockopt(zmq.LINGER, 0) get_connection(self.socket, endpoint, ssh_server, ssh_keyfile) self._timeout = timeout self.timeout = timeout * 1000 self.stream = ZMQStream(self.socket, tornado.ioloop.IOLoop.instance())
def __init__(self, topics, context=None, endpoint=DEFAULT_ENDPOINT_SUB, ssh_server=None, timeout=1.): self.topics = topics self.keep_context = context is not None self._init_context(context) self.endpoint = endpoint self.pubsub_socket = self.context.socket(zmq.SUB) get_connection(self.pubsub_socket, self.endpoint, ssh_server) for topic in self.topics: self.pubsub_socket.setsockopt(zmq.SUBSCRIBE, b(topic)) self._init_poller() self.timeout = timeout
def __init__(self, context=None, endpoint=DEFAULT_ENDPOINT_DEALER, timeout=5.0, ssh_server=None): self.context = context or zmq.Context.instance() self.endpoint = endpoint self._id = uuid.uuid4().hex self.socket = self.context.socket(zmq.DEALER) self.socket.setsockopt(zmq.IDENTITY, self._id) self.socket.setsockopt(zmq.LINGER, 0) get_connection(self.socket, endpoint, ssh_server) self.poller = zmq.Poller() self.poller.register(self.socket, zmq.POLLIN) self._timeout = timeout self.timeout = timeout * 1000
def __init__(self, topics, loop, callback, context=None, endpoint=DEFAULT_ENDPOINT_SUB, ssh_server=None, timeout=1.): self.topics = topics self.keep_context = context is not None self.context = context or zmq.Context() self.endpoint = endpoint self.pubsub_socket = self.context.socket(zmq.SUB) get_connection(self.pubsub_socket, self.endpoint, ssh_server) for topic in self.topics: self.pubsub_socket.setsockopt_string(zmq.SUBSCRIBE, topic) self.stream = ZMQStream(self.pubsub_socket, loop) self.stream.on_recv(self.process_message) self.callback = callback self.timeout = timeout # Connection counter self.count = 0
def call(self, cmd, callback): if not isinstance(cmd, string_types): try: cmd = json.dumps(cmd) except ValueError as e: raise CallError(str(e)) socket = self.context.socket(zmq.DEALER) socket.setsockopt_string(zmq.IDENTITY, uuid.uuid4().hex) socket.setsockopt(zmq.LINGER, 0) get_connection(socket, self.endpoint, self.ssh_server, self.ssh_keyfile) if callback: stream = ZMQStream(socket, self.loop) def timeout_callback(): stream.stop_on_recv() stream.close() raise CallError('Call timeout for cmd', cmd) timeout = self.loop.add_timeout(timedelta(seconds=5), timeout_callback) def recv_callback(msg): self.loop.remove_timeout(timeout) stream.stop_on_recv() stream.close() callback(json.loads(msg[0].decode('utf-8'))) stream.on_recv(recv_callback) try: socket.send_string(cmd) except zmq.ZMQError as e: raise CallError(str(e)) if not callback: return json.loads(socket.recv().decode('utf-8'))
def call(self, cmd, callback): if not isinstance(cmd, string_types): try: cmd = json.dumps(cmd) except ValueError as e: raise CallError(str(e)) socket = self.context.socket(zmq.DEALER) socket.setsockopt(zmq.IDENTITY, uuid.uuid4().hex) socket.setsockopt(zmq.LINGER, 0) get_connection(socket, self.endpoint, self.ssh_server, self.ssh_keyfile) if callback: stream = ZMQStream(socket, self.loop) def timeout_callback(): stream.stop_on_recv() stream.close() raise CallError('Call timeout for cmd', cmd) timeout = self.loop.add_timeout(timedelta(seconds=5), timeout_callback) def recv_callback(msg): self.loop.remove_timeout(timeout) stream.stop_on_recv() stream.close() callback(json.loads(msg[0])) stream.on_recv(recv_callback) try: socket.send(cmd) except zmq.ZMQError as e: raise CallError(str(e)) if not callback: return json.loads(socket.recv())
def __init__(self, topics, loop, callback, context=None, endpoint=DEFAULT_ENDPOINT_SUB, ssh_server=None, timeout=1.): self.topics = topics self.keep_context = context is not None self.context = context or zmq.Context() self.endpoint = endpoint self.pubsub_socket = self.context.socket(zmq.SUB) get_connection(self.pubsub_socket, self.endpoint, ssh_server) for topic in self.topics: self.pubsub_socket.setsockopt(zmq.SUBSCRIBE, topic) self.stream = ZMQStream(self.pubsub_socket, loop) self.stream.on_recv(self.process_message) self.callback = callback self.timeout = timeout # Connection counter self.count = 0