Class PagedAsyncStream<T>
- java.lang.Object
-
- com.azure.android.core.rest.util.paging.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 typePagedResponse
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 ofPagedAsyncStream
.
-
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 thePagedAsyncStream
by signaling each page element across all pages to thehandler.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 idpageId
.
-
-
-
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 ofPagedAsyncStream
. The constructor takes astreamRetriever
. ThepageRetriever
returnsAsyncStream
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 thePagedAsyncStream
by signaling each page element across all pages to thehandler.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). TheCancellationToken
returned can be used to cancel the enumeration- Specified by:
forEach
in interfacecom.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 interfacecom.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 interfacecom.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 interfacecom.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 idpageId
. Anull
value forpageId
indicate the initial page.- Specified by:
getPage
in interfacecom.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.
-
-