Example #1
0
 def __init__(self, url):
     self._url = url
     self._futures = FutureCollection()
     self._event = Event()
     self._event.set()
     self._send_recieve_thread = _SendReceiveThread(url,
                                                    futures=self._futures,
                                                    ready_event=self._event)
     self._send_recieve_thread.daemon = True
     self._send_recieve_thread.start()
Example #2
0
 def __init__(self, url):
     self._url = url
     self._futures = FutureCollection()
     self._event = Event()
     self._event.set()
     error_queue = Queue()
     self._send_recieve_thread = _SendReceiveThread(url,
                                                    futures=self._futures,
                                                    ready_event=self._event,
                                                    error_queue=error_queue)
     self._send_recieve_thread.start()
     err = error_queue.get()
     if err is not _NO_ERROR:
         raise err
Example #3
0
 def __init__(self, url):
     self._url = url
     self._futures = FutureCollection()
     self._event = Event()
     self._event.set()
     error_queue = Queue()
     self._send_recieve_thread = _SendReceiveThread(
         url,
         futures=self._futures,
         ready_event=self._event,
         error_queue=error_queue)
     self._send_recieve_thread.start()
     err = error_queue.get()
     if err is not _NO_ERROR:
         raise err
Example #4
0
class Stream(object):
    def __init__(self, url):
        self._url = url
        self._futures = FutureCollection()
        self._event = Event()
        self._event.set()
        self._send_recieve_thread = _SendReceiveThread(url,
                                                       futures=self._futures,
                                                       ready_event=self._event)
        self._send_recieve_thread.daemon = True
        self._send_recieve_thread.start()

    @property
    def url(self):
        """ Get the url of the Stream object.
        """
        return self._url

    @property
    def zmq_id(self):
        return self._send_recieve_thread.identity

    def send(self, message_type, content):
        """Send a message to the validator

        :param: message_type(validator_pb2.Message.MessageType)
        :param: content(bytes)
        :return: (future.Future)
        :raises: (ValidatorConnectionError)
        """

        if not self._event.is_set():
            raise ValidatorConnectionError()
        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: validator_pb2.Message.MessageType enum value
        :param correlation_id: a random str internal to the validator
        :param content: protobuf bytes
        :raises (ValidatorConnectionError):
        """
        if not self._event.is_set():
            raise ValidatorConnectionError()
        message = validator_pb2.Message(message_type=message_type,
                                        correlation_id=correlation_id,
                                        content=content)
        self._send_recieve_thread.put_message(message)

    def receive(self):
        """
        Receive messages that are not responses
        :return: concurrent.futures.Future
        """
        return self._send_recieve_thread.get_message()

    def wait_for_ready(self):
        """Blocks until the background thread has recovered
        from a disconnect with the validator.
        """
        self._event.wait()

    def is_ready(self):
        """Whether the background thread has recovered from
        a disconnect with the validator

        :return: (bool) whether the background thread is ready
        """
        return self._event.is_set()

    def close(self):
        self._send_recieve_thread.shutdown()
Example #5
0
class Stream(object):
    def __init__(self, url):
        self._url = url
        self._futures = FutureCollection()
        self._event = Event()
        self._event.set()
        error_queue = Queue()
        self._send_recieve_thread = _SendReceiveThread(
            url,
            futures=self._futures,
            ready_event=self._event,
            error_queue=error_queue)
        self._send_recieve_thread.start()
        err = error_queue.get()
        if err is not _NO_ERROR:
            raise err

    @property
    def url(self):
        """ Get the url of the Stream object.
        """
        return self._url

    @property
    def zmq_id(self):
        return self._send_recieve_thread.identity

    def send(self, message_type, content):
        """Send a message to the validator

        :param: message_type(validator_pb2.Message.MessageType)
        :param: content(bytes)
        :return: (future.Future)
        :raises: (ValidatorConnectionError)
        """

        if not self._event.is_set():
            raise ValidatorConnectionError()
        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: validator_pb2.Message.MessageType enum value
        :param correlation_id: a random str internal to the validator
        :param content: protobuf bytes
        :raises (ValidatorConnectionError):
        """
        if not self._event.is_set():
            raise ValidatorConnectionError()
        message = validator_pb2.Message(
            message_type=message_type,
            correlation_id=correlation_id,
            content=content)
        self._send_recieve_thread.put_message(message)

    def receive(self):
        """
        Receive messages that are not responses
        :return: concurrent.futures.Future
        """
        return self._send_recieve_thread.get_message()

    def wait_for_ready(self):
        """Blocks until the background thread has recovered
        from a disconnect with the validator.
        """
        self._event.wait()

    def is_ready(self):
        """Whether the background thread has recovered from
        a disconnect with the validator

        :return: (bool) whether the background thread is ready
        """
        return self._event.is_set()

    def close(self):
        self._send_recieve_thread.shutdown()