Package org.axonframework.common.stream
Interface BlockingStream<M>
- Type Parameters:
M- the type ofMessagecontained in this stream
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
TrackingEventStream
- All Known Implementing Classes:
EventBuffer
Interface for a stream that can be polled for information using (optionally blocking) pull operations.
- Since:
- 3.0
- Author:
- Rene de Waele, Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptionasStream()Returns this MessageStream as aStreamof Messages.voidclose()default booleanChecks whether or not the next message in the stream is available.booleanhasNextAvailable(int timeout, TimeUnit unit) Checks whether or not the next message in the stream is available.Returns the next available message in the stream.peek()Checks whether or not the next message in the stream is immediately available.default booleansetOnAvailableCallback(Runnable callback) Set acallbackto be invoked once new messages are available on this stream.default voidskipMessagesWithPayloadTypeOf(M ignoredMessage) Report the stream that a specific message was ignored by the consumer.
-
Method Details
-
hasNextAvailable
default boolean hasNextAvailable()Checks whether or not the next message in the stream is available. If so this method returnstrueimmediately. If not it returnsfalseimmediately.Note that if
thisBlockingStreamhas only recently been constructed, the chance is high there are no events present yet. Hence, it is recommended to usehasNextAvailable(int, TimeUnit)with a reasonable time window orsetOnAvailableCallback(Runnable)instead.- Returns:
- true if a message is available or becomes available before the given timeout, false otherwise
-
peek
Checks whether or not the next message in the stream is immediately available. If so, an Optional with the next message is returned (without moving the stream pointer), otherwise an empty Optional is returned.- Returns:
- the next event if immediately available
-
hasNextAvailable
Checks whether or not the next message in the stream is available. If a message is available when this method is invoked this method returns immediately. If not, this method will block until a message becomes available, returningtrueor until the giventimeoutexpires, returningfalse.To check if the stream has messages available now, pass a zero
timeout.- Parameters:
timeout- the maximum number of time units to wait for messages to become availableunit- the time unit for the timeout- Returns:
- true if a message is available or becomes available before the given timeout, false otherwise
- Throws:
InterruptedException- when the thread is interrupted before the indicated time is up
-
nextAvailable
Returns the next available message in the stream. Note that this method blocks for as long as there are no available messages in the stream. In case this blocking behavior is not desired usehasNextAvailable()with or without a timeout to check if the stream has available messages before calling this method.- Returns:
- the next available message
- Throws:
InterruptedException- when the thread is interrupted before the next message is returned
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-
asStream
Returns this MessageStream as aStreamof Messages. Note that the returned Stream will start at the current position of this instance.Note that iterating over the returned Stream may affect this MessageStream and vice versa. It is therefore not recommended to use this MessageStream after invoking this method.
- Returns:
- This MessageStream as a Stream of Messages
-
skipMessagesWithPayloadTypeOf
Report the stream that a specific message was ignored by the consumer. Stream implementation can use this information for instance to filter messages with the same type of payload.- Parameters:
ignoredMessage- the message containing the payload to exclude from the stream
-
setOnAvailableCallback
Set acallbackto be invoked once new messages are available on this stream. Returnstrueif this functionality is supported andfalseotherwise. Whentrueis returned, the callee can expect thecallbackto be invoked immediately.Note that returning
falsedoes not define the givencallbackis never invoked. If the callee needs to be certain thecallbackis never invoked in case offalse, a no-opRunnableshould be provided.- Parameters:
callback- aRunnable- Returns:
trueif on available callback is supported and can thus be waited on,false otherwise
-