T - the type of results this stream implementation buffersR - the type of message used for flow control on this streampublic abstract class AbstractBufferedStream<T,R> extends FlowControlledBuffer<T,R> implements ResultStream<T>
FlowControlledBuffer and ResultStream implementation, used to provide a buffered stream
of results of T when receiving a request of type R.| Constructor and Description |
|---|
AbstractBufferedStream(String clientId,
int bufferSize,
int refillBatch)
Constructs an
AbstractBufferedStream |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Requests the current stream to be closed.
|
Optional<Throwable> |
getError()
Returns an optional containing the exception reported by the Server, if any.
|
boolean |
isClosed()
Check whether this buffer has been closed off
|
T |
next()
Consumes the next available element in the stream, waiting for an element to become available, or for the buffer
to be closed.
|
T |
nextIfAvailable()
Consumes the next available element in the stream, if available.
|
T |
nextIfAvailable(long timeout,
TimeUnit unit)
Consumes the next available element in the stream, waiting for at most
timeout (in given unit)
for an element to become available. |
void |
onAvailable(Runnable callback)
Sets the given
callback to execute when data is available for reading, or the stream has been closed. |
void |
onCloseRequested(Runnable handler)
Adds the given
handler to a collection of Runnables to be invoked when the stream is closed by
the server. |
void |
onCompleted() |
void |
onError(Throwable t) |
void |
onNext(T value) |
T |
peek()
Retrieves, but does not remove, the first entry of this buffer, or returns
null if the buffer is empty. |
beforeStart, getErrorResult, take, terminalMessage, tryTake, tryTake, tryTake, tryTakeNowbuildFlowControlMessage, buildInitialFlowControlMessage, enableFlowControl, markConsumed, outboundStreampublic AbstractBufferedStream(String clientId, int bufferSize, int refillBatch)
AbstractBufferedStreamclientId - the identifier of the client initiation this streambufferSize - the size of this bufferrefillBatch - the number of entries to be consumed prior to refilling this bufferpublic T next() throws InterruptedException
ResultStreamnext in interface ResultStream<T>null if none availableInterruptedException - when the Thread is interrupted while waiting
for an element to become availableResultStream.isClosed()public T nextIfAvailable()
ResultStreamnull if no element is
available immediately.nextIfAvailable in interface ResultStream<T>null if none is available, or if the stream is
closedpublic T nextIfAvailable(long timeout, TimeUnit unit) throws InterruptedException
ResultStreamtimeout (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.nextIfAvailable in interface ResultStream<T>timeout - the amount of time to wait for an element to become availableunit - the unit of time in which the timeout is expressednull if none is availableInterruptedException - when the Thread is interrupted while waiting for an element to become availableResultStream.isClosed()public void onNext(T value)
onNext in interface io.grpc.stub.StreamObserver<T>onNext in class FlowControlledBuffer<T,R>public void onError(Throwable t)
onError in interface io.grpc.stub.StreamObserver<T>onError in class FlowControlledBuffer<T,R>public Optional<Throwable> getError()
ResultStream
Note that this method may return a non-empty response, even when ResultStream.isClosed() returns false, or
if there are messages available for processing.
getError in interface ResultStream<T>public void onCompleted()
onCompleted in interface io.grpc.stub.StreamObserver<T>onCompleted in class FlowControlledBuffer<T,R>public T peek()
FlowControlledBuffernull if the buffer is empty.peek in interface ResultStream<T>peek in class FlowControlledBuffer<T,R>null if it is emptypublic void onAvailable(Runnable callback)
ResultStreamcallback 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.
onAvailable in interface ResultStream<T>callback - a {Runnable} to Runnable.run() when the next entry becomes available or
null to disable callbackspublic boolean isClosed()
FlowControlledBufferisClosed in interface ResultStream<T>isClosed in class FlowControlledBuffer<T,R>true if this buffer is closed, false otherwiseResultStream.getError()public void close()
ResultStreamAny elements received before closing are still available for reading.
close in interface ResultStream<T>close in interface AutoCloseableclose in class FlowControlledBuffer<T,R>public void onCloseRequested(Runnable handler)
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.handler - Runnable to invoke when the stream is closed by the serverCopyright © 2020–2022 AxonIQ BV. All rights reserved.