Package io.pravega.common.util
Class ContinuationTokenAsyncIterator<Token,T>
- java.lang.Object
-
- io.pravega.common.util.ContinuationTokenAsyncIterator<Token,T>
-
- All Implemented Interfaces:
AsyncIterator<T>
@ThreadSafe public class ContinuationTokenAsyncIterator<Token,T> extends java.lang.Object implements AsyncIterator<T>
This is a continuation token based async iterator implementation. This class takes a function that when completed will have next batch of results with continuation token. This class determines when to call the next iteration of function (if all existing results have been exhausted) and ensures there is only one outstanding call.
-
-
Constructor Summary
Constructors Constructor Description ContinuationTokenAsyncIterator(@NonNull java.util.function.Function<Token,java.util.concurrent.CompletableFuture<java.util.Map.Entry<Token,java.util.Collection<T>>>> function, Token tokenIdentity)Constructor takes a Function of token which when applied will return a tuple of new token and collection of elements of type `T`.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<T>getNext()Attempts to get the next element in the iteration.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.pravega.common.util.AsyncIterator
asIterator, asSequential, collectRemaining, forEachRemaining, thenApply, thenCompose
-
-
-
-
Constructor Detail
-
ContinuationTokenAsyncIterator
public ContinuationTokenAsyncIterator(@NonNull @NonNull java.util.function.Function<Token,java.util.concurrent.CompletableFuture<java.util.Map.Entry<Token,java.util.Collection<T>>>> function, Token tokenIdentity)Constructor takes a Function of token which when applied will return a tuple of new token and collection of elements of type `T`. This function is called whenever the local queue is empty. It is called with last received token and updates the local queue of elements with the result received from the function call.- Parameters:
function- Function of token which when applied will return a tuple of new token and collection of elements of type `T`.tokenIdentity- Token identity which is used while making the very first function call.
-
-
Method Detail
-
getNext
public java.util.concurrent.CompletableFuture<T> getNext()
Description copied from interface:AsyncIteratorAttempts to get the next element in the iteration. Note: since this is an async call, it is possible to invoke this method before the previous call to it completed; in this case the behavior is undefined and, depending on the actual implementation, the internal state of theAsyncIteratormay get corrupted. Consider invokingAsyncIterator.asSequential(Executor)which will provide a thin wrapper on top of this instance that serializes calls to this method.- Specified by:
getNextin interfaceAsyncIterator<Token>- Returns:
- A CompletableFuture that, when completed, will contain the next element in the iteration. If the iteration has reached its end, this will complete with null. If an exception occurred, this will be completed exceptionally with the causing exception, and the iteration will end.
-
-