Class AbstractBufferedStream<T,​R>

    • Constructor Detail

      • AbstractBufferedStream

        public AbstractBufferedStream​(String clientId,
                                      int bufferSize,
                                      int refillBatch)
        Parameters:
        clientId - the identifier of the client initiation this stream
        bufferSize - the size of this buffer
        refillBatch - the number of entries to be consumed prior to refilling this buffer
    • Method Detail

      • next

        public T next()
               throws InterruptedException
        Description copied from interface: ResultStream
        Consumes the next available element in the stream, waiting for an element to become available, or for the buffer to be closed.
        Specified by:
        next in interface ResultStream<T>
        Returns:
        the next available element in the stream, or null if none available
        Throws:
        InterruptedException - when the Thread is interrupted while waiting for an element to become available
        See Also:
        ResultStream.isClosed()
      • nextIfAvailable

        public T nextIfAvailable()
        Description copied from interface: ResultStream
        Consumes the next available element in the stream, if available. Will return null if no element is available immediately.
        Specified by:
        nextIfAvailable in interface ResultStream<T>
        Returns:
        the next available element in the stream, or null if none is available, or if the stream is closed
      • nextIfAvailable

        public T nextIfAvailable​(long timeout,
                                 TimeUnit unit)
                          throws InterruptedException
        Description copied from interface: ResultStream
        Consumes the next available element in the stream, waiting for at most timeout (in given unit) for an element to become available. If no element is available with the given timeout, or if the stream has been closed, it returns null.
        Specified by:
        nextIfAvailable in interface ResultStream<T>
        Parameters:
        timeout - the amount of time to wait for an element to become available
        unit - the unit of time in which the timeout is expressed
        Returns:
        the next available element in the stream, or null if none is available
        Throws:
        InterruptedException - when the Thread is interrupted while waiting for an element to become available
        See Also:
        ResultStream.isClosed()
      • onNext

        public void onNext​(T value)
        Specified by:
        onNext in interface io.grpc.stub.StreamObserver<T>
        Overrides:
        onNext in class FlowControlledBuffer<T,​R>
      • getError

        public Optional<Throwable> getError()
        Description copied from interface: ResultStream
        Returns an optional containing the exception reported by the Server, if any.

        Note that this method may return a non-empty response, even when ResultStream.isClosed() returns false, or if there are messages available for processing.

        Specified by:
        getError in interface ResultStream<T>
        Returns:
        an optional containing the exception reported by the Server, if any.
      • onCompleted

        public void onCompleted()
        Specified by:
        onCompleted in interface io.grpc.stub.StreamObserver<T>
        Overrides:
        onCompleted in class FlowControlledBuffer<T,​R>
      • peek

        public T peek()
        Description copied from class: FlowControlledBuffer
        Retrieves, but does not remove, the first entry of this buffer, or returns null if the buffer is empty.
        Specified by:
        peek in interface ResultStream<T>
        Overrides:
        peek in class FlowControlledBuffer<T,​R>
        Returns:
        the first entry of this buffer without removing it, or null if it is empty
      • onAvailable

        public void onAvailable​(Runnable callback)
        Description copied from interface: ResultStream
        Sets the given callback to execute when data is available for reading, or the stream has been closed. Note that any registration will replace the previous one.

        The callback is invoked in the publisher's thread. Invocations should be as short as possible, preferably delegating to a reader thead, instead of accessing the entries directly.

        Specified by:
        onAvailable in interface ResultStream<T>
        Parameters:
        callback - a {Runnable} to Runnable.run() when the next entry becomes available or null to disable callbacks
      • close

        public void close()
        Description copied from interface: ResultStream
        Requests the current stream to be closed. It is up to the publishing end of the stream to honor the request.

        Any elements received before closing are still available for reading.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface ResultStream<T>
        Overrides:
        close in class FlowControlledBuffer<T,​R>
      • onCloseRequested

        public void onCloseRequested​(Runnable handler)
        Adds the given handler to a collection of Runnables to be invoked when the stream is closed by the server. Note that data may still be buffered locally for processing.
        Parameters:
        handler - Runnable to invoke when the stream is closed by the server