M
- the type of Message contained in this streampublic interface MessageStream<M extends Message<?>> extends AutoCloseable
Messages
.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 hasNextAvailable()
true
immediately. If not it returns false
immediately.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.
Copyright © 2010–2018. All rights reserved.