Package io.axoniq.axonserver.connector
Interface ResultStream<T>
-
- Type Parameters:
T- the result type returned by thisResultStream
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
EventStream,PersistentStreamSegment
- All Known Implementing Classes:
AbstractBufferedStream,BufferedEventStream,BufferedPersistentStreamSegment,SubscriptionQueryUpdateBuffer
public interface ResultStream<T> extends AutoCloseable
Interface describing a stream of results to a request. This stream allows for blocking retrieval of elements, as well as a non-blocking approach using notifications when messages are available.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 anextIfAvailable()will yield the same message.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Requests the current stream to be closed.Optional<Throwable>getError()Returns an optional containing the exception reported by the Server, if any.booleanisClosed()Indicates whether the current stream is closed for further reading.Tnext()Consumes the next available element in the stream, waiting for an element to become available, or for the buffer to be closed.TnextIfAvailable()Consumes the next available element in the stream, if available.TnextIfAvailable(long timeout, TimeUnit unit)Consumes the next available element in the stream, waiting for at mosttimeout(in givenunit) for an element to become available.voidonAvailable(Runnable callback)Sets the givencallbackto execute when data is available for reading, or the stream has been closed.Tpeek()Returns the next available element in the stream, if available, without consuming it from the stream.
-
-
-
Method Detail
-
peek
T peek()
Returns the next available element in the stream, if available, without consuming it from the stream. Will returnnullwhen no element is available, or when the stream has been closed.- Returns:
- the next available element in the stream, or
nullif none is available, or if the stream is closed
-
nextIfAvailable
T nextIfAvailable()
Consumes the next available element in the stream, if available. Will returnnullif no element is available immediately.- Returns:
- the next available element in the stream, or
nullif none is available, or if the stream is closed
-
nextIfAvailable
T nextIfAvailable(long timeout, TimeUnit unit) throws InterruptedException
Consumes the next available element in the stream, waiting for at mosttimeout(in givenunit) for an element to become available. If no element is available with the given timeout, or if the stream has been closed, it returnsnull.- Parameters:
timeout- the amount of time to wait for an element to become availableunit- the unit of time in which the timeout is expressed- Returns:
- the next available element in the stream, or
nullif none is available - Throws:
InterruptedException- when the Thread is interrupted while waiting for an element to become available- See Also:
isClosed()
-
next
T next() throws InterruptedException
Consumes the next available element in the stream, waiting for an element to become available, or for the buffer to be closed.- Returns:
- the next available element in the stream, or
nullif none available - Throws:
InterruptedException- when the Thread is interrupted while waiting for an element to become availableStreamClosedException- when the stream is closed- See Also:
isClosed()
-
onAvailable
void onAvailable(Runnable callback)
Sets the givencallbackto 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.
- Parameters:
callback- a {Runnable} toRunnable.run()when the next entry becomes available ornullto disable callbacks
-
close
void close()
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:
closein interfaceAutoCloseable
-
isClosed
boolean isClosed()
Indicates whether the current stream is closed for further reading. Note that this method will also returnfalsein 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- Returns:
trueif the stream is closed for further reading, otherwisefalse- See Also:
getError()
-
getError
Optional<Throwable> getError()
Returns an optional containing the exception reported by the Server, if any.Note that this method may return a non-empty response, even when
isClosed()returnsfalse, or if there are messages available for processing.- Returns:
- an optional containing the exception reported by the Server, if any.
-
-