Class 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`.
    • 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: AsyncIterator
        Attempts 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 the AsyncIterator may get corrupted. Consider invoking AsyncIterator.asSequential(Executor) which will provide a thin wrapper on top of this instance that serializes calls to this method.
        Specified by:
        getNext in interface AsyncIterator<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.