Class ReaderImpl<T>
- java.lang.Object
-
- com.turtlequeue.ReaderImpl<T>
-
- All Implemented Interfaces:
Reader<T>,Closeable,AutoCloseable
public class ReaderImpl<T> extends Object implements Reader<T>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()CompletableFuture<Void>closeAsync()Asynchronously close the reader and stop the broker to push more messages.TopicgetTopic()CompletableFuture<Boolean>hasMessageAvailable()Asynchronously check if there is any message available to read from the current position.booleanhasReachedEndOfTopic()Return true if the topic was terminated and this reader has reached the end of the topic.booleanisConnected()CompletableFuture<Message<T>>readNext()Read asynchronously the next message in the topic.CompletableFuture<Void>seek(long timestamp)Reset the subscription associated with this reader to a specific message publish time.CompletableFuture<Void>seek(MessageId messageId)Reset the subscription associated with this reader to a specific message id.CompletableFuture<Reader<T>>subscribeReturn()StringtoString()
-
-
-
Method Detail
-
getTopic
public Topic getTopic()
-
readNext
public CompletableFuture<Message<T>> readNext()
Description copied from interface:ReaderRead asynchronously the next message in the topic.readNextAsync()should be called subsequently once returnedCompletableFuturegets complete with received message. Else it creates backlog of receive requests in the application.The returned future can be cancelled before completion by calling
.cancel(false)(CompletableFuture.cancel(boolean)) to remove it from the the backlog of receive requests. Another choice for ensuring a proper clean up of the returned future is to use the CompletableFuture.orTimeout method which is available on JDK9+. That would remove it from the backlog of receive requests if receiving exceeds the timeout.
-
closeAsync
public CompletableFuture<Void> closeAsync()
Description copied from interface:ReaderAsynchronously close the reader and stop the broker to push more messages.- Specified by:
closeAsyncin interfaceReader<T>- Returns:
- a future that can be used to track the completion of the operation
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
hasReachedEndOfTopic
public boolean hasReachedEndOfTopic()
Description copied from interface:ReaderReturn true if the topic was terminated and this reader has reached the end of the topic.Note that this only applies to a "terminated" topic (where the topic is "sealed" and no more messages can be published) and not just that the reader is simply caught up with the publishers. Use
Reader.hasMessageAvailable()to check for for that.- Specified by:
hasReachedEndOfTopicin interfaceReader<T>
-
hasMessageAvailable
public CompletableFuture<Boolean> hasMessageAvailable()
Description copied from interface:ReaderAsynchronously check if there is any message available to read from the current position.This check can be used by an application to scan through a topic and stop when the reader reaches the current last published message.
Even if this call returns true, that will not guarantee that a subsequent call to
Reader.readNext()will not block.- Specified by:
hasMessageAvailablein interfaceReader<T>- Returns:
- a future that will yield true if the are messages available to be read, false otherwise, or a
PulsarClientExceptionif there was any error in the operation
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin interfaceReader<T>- Returns:
- Whether the reader is connected to the broker
-
seek
public CompletableFuture<Void> seek(MessageId messageId)
Description copied from interface:ReaderReset the subscription associated with this reader to a specific message id.The message id can either be a specific message or represent the first or last messages in the topic.
MessageId.earliest: Reset the reader on the earliest message available in the topicMessageId.latest: Reset the reader on the latest message in the topic
Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on the individual partitions.
-
seek
public CompletableFuture<Void> seek(long timestamp)
Description copied from interface:ReaderReset the subscription associated with this reader to a specific message publish time.Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on the individual partitions.
-
subscribeReturn
public CompletableFuture<Reader<T>> subscribeReturn()
-
-