public class BlockingQueueMessageIterator extends Object implements MessageIterator, MessageHandler
MessageIterator that is backed by a LinkedBlockingQueue.| Constructor and Description |
|---|
BlockingQueueMessageIterator() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this subscription iterator.
|
boolean |
hasNext()
Returns
true if this iterator is open. |
Message |
next()
Returns the next
Message sent by the Nats server. |
Message |
next(long timeout,
TimeUnit unit)
Returns the next
Message sent by the Nats server within the specified time limit. |
void |
onMessage(Message message) |
void |
remove()
Throws an
UnsupportedOperationException since you obviously can't remove a message after it has been
received. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic void close()
MessageIteratorClosing the subscription associated with this iterator will close this iterator.
close in interface AutoCloseableclose in interface MessageIteratorpublic boolean hasNext()
MessageIteratortrue if this iterator is open. We do not know if/when the Nats server will publish another
message so we assume another message is pending so, this method always returns true unless this iterator has
been closed.
Closing the subscription associated with this iterator will close this iterator.
hasNext in interface Iterator<Message>hasNext in interface MessageIteratortrue unless this iterator has been closed.public Message next() throws NatsClosedException, NatsInterruptedException, NoSuchElementException
MessageIteratorMessage sent by the Nats server.next in interface Iterator<Message>next in interface MessageIteratorMessage sent by the Nats server.NatsClosedException - thrown if the iterator closes while waiting for a message.NatsInterruptedExceptionNoSuchElementExceptionpublic Message next(long timeout, TimeUnit unit) throws NatsClosedException, NatsInterruptedException, NoSuchElementException
MessageIteratorMessage sent by the Nats server within the specified time limit.next in interface MessageIteratortimeout - the maximum time to wait for a messageunit - the time unit of the timeout argumentMessage sent by the Nats server or null if a message didn't arrive within the
specified time limit.NatsClosedException - thrown if the iterator closes while waiting for a message.NatsInterruptedExceptionNoSuchElementExceptionpublic void remove()
throws UnsupportedOperationException
MessageIteratorUnsupportedOperationException since you obviously can't remove a message after it has been
received.remove in interface Iterator<Message>remove in interface MessageIteratorUnsupportedOperationExceptionpublic void onMessage(Message message)
onMessage in interface MessageHandlerCopyright © 2015. All Rights Reserved.