Class PagedAsyncStream<T>

  • Type Parameters:
    T - The type of element in the page.
    All Implemented Interfaces:
    com.azure.android.core.util.AsyncStream<T>, com.azure.android.core.util.paging.PagedAsyncStreamCore<java.lang.String,​T,​PagedResponse<T>>

    public final class PagedAsyncStream<T>
    extends java.lang.Object
    implements com.azure.android.core.util.paging.PagedAsyncStreamCore<java.lang.String,​T,​PagedResponse<T>>
    PagedAsyncStream provides the ability to asynchronously enumerate paginated REST responses of type PagedResponse and individual elements in such pages. When processing the response by page each response will contain the elements in the page as well as the REST response details such as status code and headers.
    • Constructor Summary

      Constructors 
      Constructor Description
      PagedAsyncStream​(com.azure.android.core.util.Function<java.lang.String,​com.azure.android.core.util.AsyncStream<PagedResponse<T>>> streamRetriever, com.azure.android.core.logging.ClientLogger logger)
      Creates an instance of PagedAsyncStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.azure.android.core.util.AsyncStream<PagedResponse<T>> byPage()
      com.azure.android.core.util.AsyncStream<PagedResponse<T>> byPage​(java.lang.String startPageId)
      com.azure.android.core.util.CancellationToken forEach​(com.azure.android.core.util.AsyncStreamHandler<T> handler)
      Enumerate the PagedAsyncStream by signaling each page element across all pages to the handler.onNext.
      com.azure.android.core.util.AsyncStream<T> from​(java.lang.String startPageId)
      void getPage​(java.lang.String pageId, com.azure.android.core.util.BiConsumer<PagedResponse<T>,​java.lang.Throwable> pageHandler)
      Retrieve a page with given id pageId.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PagedAsyncStream

        public PagedAsyncStream​(com.azure.android.core.util.Function<java.lang.String,​com.azure.android.core.util.AsyncStream<PagedResponse<T>>> streamRetriever,
                                com.azure.android.core.logging.ClientLogger logger)
        Creates an instance of PagedAsyncStream. The constructor takes a streamRetriever. The pageRetriever returns AsyncStream of pages when invoked with the id of the page to retrieve.
        Parameters:
        streamRetriever - The function to retrieve source AsyncStream to back this stream.
        logger - The logger to log.
    • Method Detail

      • forEach

        public com.azure.android.core.util.CancellationToken forEach​(com.azure.android.core.util.AsyncStreamHandler<T> handler)
        Enumerate the PagedAsyncStream by signaling each page element across all pages to the handler.onNext. All the elements will be enumerated as long as there is no cancellation requested and there is no error while retrieving the page (e.g. auth error, network error). The CancellationToken returned can be used to cancel the enumeration
        Specified by:
        forEach in interface com.azure.android.core.util.AsyncStream<T>
        Parameters:
        handler - The enumeration handler.
        Returns:
        CancellationToken to signal the enumeration cancel.
      • byPage

        public com.azure.android.core.util.AsyncStream<PagedResponse<T>> byPage()
        Specified by:
        byPage in interface com.azure.android.core.util.paging.PagedAsyncStreamCore<java.lang.String,​T,​PagedResponse<T>>
      • byPage

        public com.azure.android.core.util.AsyncStream<PagedResponse<T>> byPage​(java.lang.String startPageId)
        Specified by:
        byPage in interface com.azure.android.core.util.paging.PagedAsyncStreamCore<java.lang.String,​T,​PagedResponse<T>>
      • from

        public com.azure.android.core.util.AsyncStream<T> from​(java.lang.String startPageId)
        Specified by:
        from in interface com.azure.android.core.util.paging.PagedAsyncStreamCore<java.lang.String,​T,​PagedResponse<T>>
      • getPage

        public void getPage​(java.lang.String pageId,
                            com.azure.android.core.util.BiConsumer<PagedResponse<T>,​java.lang.Throwable> pageHandler)
        Retrieve a page with given id pageId. A null value for pageId indicate the initial page.
        Specified by:
        getPage in interface com.azure.android.core.util.paging.PagedAsyncStreamCore<java.lang.String,​T,​PagedResponse<T>>
        Parameters:
        pageId - The id of the page to retrieve.
        pageHandler - The handler to signal the retrieved page or any error during the page retrieval.