def close(self): message = validator_pb2.Message(message_type='system/disconnect', correlation_id=_generate_id(), content='') self._send_queue.put(message) while not self._handle.done(): time.sleep(1)
def send(self, message_type, content): message = validator_pb2.Message(message_type=message_type, correlation_id=_generate_id(), content=content) future = Future(message.correlation_id) self._futures.put(future) self._send_recieve_thread.put_message(message) return future
def send_back(self, message_type, correlation_id, content): """ Return a response to a message. :param message_type: one of the strs on MessageType :param correlation_id: a random str internal to the validator :param content: protobuf bytes """ message = validator_pb2.Message(message_type=message_type, correlation_id=correlation_id, content=content) self._send_recieve_thread.put_message(message)
def _receive_message(self): """ internal coroutine that receives messages and puts them on the recv_queue """ with self._condition: self._condition.wait_for(lambda: self._sock is not None) while True: msg_bytes = yield from self._sock.recv() message = validator_pb2.Message() message.ParseFromString(msg_bytes) try: self._futures.set_result( message.correlation_id, FutureResult(message_type=message.message_type, content=message.content)) self._futures.remove(message.correlation_id) except FutureCollectionKeyError: # if we are getting an initial message, not a response self._recv_queue.put_nowait(message)
def send_back(self, message_type, correlation_id, content): message = validator_pb2.Message(message_type=message_type, correlation_id=correlation_id, content=content) self._send_queue.put(message)