Exemple #1
0
class ExtractStream(object):
    """Used to receive messages outside of an operator.

    Args:
        read_stream (ReadStream): the stream from which to read messages.
    """
    def __init__(self, read_stream):
        self._py_extract_stream = PyExtractStream(read_stream._py_read_stream)

    def is_closed(self):
        """Whether the stream is closed.

        Returns True if the a top watermark message was sent or the
        ExtractStream was unable to successfully set up.
        """
        return self._py_extract_stream.is_closed()

    def read(self):
        """Blocks until a message is read from the stream."""
        return _parse_message(self._py_extract_stream.read())

    def try_read(self):
        """Tries to read a mesage from the stream.

        Returns None if no messages are available at the moment.
        """
        internal_msg = self._py_extract_stream.try_read()
        if internal_msg is None:
            return None
        return _parse_message(internal_msg)
Exemple #2
0
 def __init__(self,
              read_stream: ReadStream,
              _name: Union[str, None] = None):
     if not isinstance(read_stream, ReadStream):
         raise ValueError(
             "ExtractStream needs to be initialized with a ReadStream. "
             "Received a {}".format(type(read_stream)))
     self._py_extract_stream = PyExtractStream(
         read_stream._py_read_stream,
         _name,
     )
Exemple #3
0
class ExtractStream:
    """An :py:class:`ExtractStream` enables drivers to read data from a
    running ERDOS applications.

    The driver can initialize a new :py:class:`ExtractStream` by passing the
    instance of :py:class:`OperatorStream` returned by the :code:`connect`
    family of functions. Similar to a :py:class:`ReadStream`, an
    :py:class:`ExtractStream` provides :py:meth:`.read` and
    :py:meth:`.try_read` for reading data published on the corresponding
    :py:class:`OperatorStream`.

    Args:
        stream: The stream from which to read messages.
    """
    def __init__(self, stream: OperatorStream):
        if not isinstance(stream, OperatorStream):
            raise ValueError(
                "ExtractStream needs to be initialized with a Stream. "
                "Received a {}".format(type(stream)))
        self._py_extract_stream = PyExtractStream(stream._internal_stream)

    @property
    def name(self) -> str:
        """The name of the stream. The stream ID if no name was given."""
        return self._py_extract_stream.name()

    @property
    def id(self) -> str:
        """The id of the ExtractStream."""
        return uuid.UUID(self._py_extract_stream.id())

    def is_closed(self) -> bool:
        """Whether the stream is closed.

        Returns True if the a top watermark message was sent or the
        :py:class:`ExtractStream` was unable to successfully set up.
        """
        return self._py_extract_stream.is_closed()

    def read(self) -> Message:
        """Blocks until a message is read from the stream."""
        return _parse_message(self._py_extract_stream.read())

    def try_read(self) -> Union[Message, None]:
        """Tries to read a mesage from the stream.

        Returns :code:`None` if no messages are available at the moment.
        """
        internal_msg = self._py_extract_stream.try_read()
        if internal_msg is None:
            return None
        return _parse_message(internal_msg)
Exemple #4
0
 def __init__(self, stream: OperatorStream[T]) -> None:
     if not isinstance(stream, OperatorStream) or not isinstance(
             stream._internal_stream, PyOperatorStream):
         raise ValueError(
             "ExtractStream needs to be initialized with a Stream. "
             "Received a {}".format(type(stream)))
     self._py_extract_stream: PyExtractStream = PyExtractStream(
         stream._internal_stream)
Exemple #5
0
class ExtractStream(object):
    """Used to receive messages outside of an operator.

    Args:
        read_stream (ReadStream): the stream from which to read messages.
    """
    def __init__(self, read_stream):
        self._py_extract_stream = PyExtractStream(read_stream._py_read_stream)

    def read(self):
        """Blocks until a message is read from the stream."""
        return _parse_message(self._py_extract_stream.read())

    def try_read(self):
        """Tries to read a mesage from the stream.

        Returns None if no messages are available at the moment.
        """
        internal_msg = self._py_extract_stream.try_read()
        if internal_msg is None:
            return None
        return _parse_message(internal_msg)
Exemple #6
0
 def __init__(self, read_stream):
     self._py_extract_stream = PyExtractStream(read_stream._py_read_stream)