M
- the type of Message
contained in this streampublic interface BlockingStream<M> extends AutoCloseable
Modifier and Type | Method and Description |
---|---|
default Stream<M> |
asStream()
Returns this MessageStream as a
Stream of Messages. |
void |
close() |
default boolean |
hasNextAvailable()
Checks whether or not the next message in the stream is available.
|
boolean |
hasNextAvailable(int timeout,
TimeUnit unit)
Checks whether or not the next message in the stream is available.
|
M |
nextAvailable()
Returns the next available message in the stream.
|
Optional<M> |
peek()
Checks whether or not the next message in the stream is immediately available.
|
default boolean |
setOnAvailableCallback(Runnable callback)
Set a
callback to be invoked once new messages are available on this stream. |
default void |
skipMessagesWithPayloadTypeOf(M ignoredMessage)
Report the stream that a specific message was ignored by the consumer.
|
default boolean hasNextAvailable()
true
immediately. If not it returns false
immediately.
Note that if this
BlockingStream
has only recently been constructed, the chance is high there are
no events present yet. Hence, it is recommended to use hasNextAvailable(int, TimeUnit)
with a
reasonable time window or setOnAvailableCallback(Runnable)
instead.
Optional<M> peek()
boolean hasNextAvailable(int timeout, TimeUnit unit) throws InterruptedException
true
or until the given timeout
expires, returning false
.
To check if the stream has messages available now, pass a zero timeout
.
timeout
- the maximum number of time units to wait for messages to become availableunit
- the time unit for the timeoutInterruptedException
- when the thread is interrupted before the indicated time is upM nextAvailable() throws InterruptedException
hasNextAvailable()
with or without a timeout to check if the stream has available messages before calling this method.InterruptedException
- when the thread is interrupted before the next message is returnedvoid close()
close
in interface AutoCloseable
default Stream<M> asStream()
Stream
of 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.
default void skipMessagesWithPayloadTypeOf(M ignoredMessage)
ignoredMessage
- the message containing the payload to exclude from the streamdefault boolean setOnAvailableCallback(Runnable callback)
callback
to be invoked once new messages are available on this stream. Returns true
if this
functionality is supported and false
otherwise. When true
is returned, the callee can expect the
callback
to be invoked immediately.
Note that returning false
does not define the given callback
is never invoked. If the callee
needs to be certain the callback
is never invoked in case of false
, a no-op Runnable
should be provided.
callback
- a Runnable
true
if on available callback is supported and can thus be waited on, false otherwise
Copyright © 2010–2024. All rights reserved.