T - the result type returned by this ResultStreampublic interface ResultStream<T> extends AutoCloseable
While the ResultStream itself is safe for multi-threaded use, some methods may only provide best-effort estimates. In
such case, for example, there is no guarantee that a peek() followed by a nextIfAvailable() will
yield the same message.
| 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()
Indicates whether the current stream is closed for further reading.
|
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. |
T |
peek()
Returns the next available element in the stream, if available, without consuming it from the stream.
|
T peek()
null when no element is available, or when the stream has been closed.null if none is available, or if the stream is
closedT nextIfAvailable()
null if no element is
available immediately.null if none is available, or if the stream is
closedT nextIfAvailable(long timeout, TimeUnit unit) throws InterruptedException
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.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 availableisClosed()T next() throws InterruptedException
null if none availableInterruptedException - when the Thread is interrupted while waiting
for an element to become availableStreamClosedException - when the stream is closedisClosed()void onAvailable(Runnable callback)
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.
callback - a {Runnable} to Runnable.run() when the next entry becomes available or
null to disable callbacksvoid close()
Any elements received before closing are still available for reading.
close in interface AutoCloseableboolean isClosed()
false in case the stream is closed by the element provider, but there are still elements awaiting consumption.
Check getError() to check whether the stream was closed because of an error
true if the stream is closed for further reading, otherwise falsegetError()Optional<Throwable> getError()
Note that this method may return a non-empty response, even when isClosed() returns false, or
if there are messages available for processing.
Copyright © 2020–2022 AxonIQ BV. All rights reserved.