Class AsyncPaginator<ReqT,ProgressParamT>
- java.lang.Object
-
- com.stackone.stackone_client_java.utils.pagination.AsyncPaginator<ReqT,ProgressParamT>
-
- Type Parameters:
ReqT- The type of the request objectProgressParamT- The type of the progression parameter (e.g., page number, offset, cursor)
- All Implemented Interfaces:
java.util.concurrent.Flow.Publisher<java.net.http.HttpResponse<Blob>>
public class AsyncPaginator<ReqT,ProgressParamT> extends java.lang.Object implements java.util.concurrent.Flow.Publisher<java.net.http.HttpResponse<Blob>>
A non-blocking generic pagination implementation that handles fetching and publishing paginated data. This class implements theFlow.Publisherinterface for asynchronous streaming of paginated responses. It uses a ProgressTrackerStrategy to process pagination metadata from responses and determine when to stop pagination.The pagination flow works as follows: 1. subscribe() creates a new subscription for the subscriber 2. The subscription fetches pages asynchronously using CompletableFuture 3. Each response is processed by the progress tracker to update pagination state 4. Pages are emitted to the subscriber until pagination is exhausted or cancelled
-
-
Constructor Summary
Constructors Constructor Description AsyncPaginator(ReqT initialRequest, ProgressTrackerStrategy<ProgressParamT> progressTracker, java.util.function.BiFunction<ReqT,ProgressParamT,ReqT> requestModifier, java.util.function.Function<ReqT,java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>>> asyncDataFetcher)Creates a new AsyncPaginator instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsubscribe(java.util.concurrent.Flow.Subscriber<? super java.net.http.HttpResponse<Blob>> subscriber)
-
-
-
Constructor Detail
-
AsyncPaginator
public AsyncPaginator(ReqT initialRequest, ProgressTrackerStrategy<ProgressParamT> progressTracker, java.util.function.BiFunction<ReqT,ProgressParamT,ReqT> requestModifier, java.util.function.Function<ReqT,java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>>> asyncDataFetcher)
Creates a new AsyncPaginator instance.- Parameters:
initialRequest- The initial request to use for the first pageprogressTracker- The handler that processes pagination metadata from responsesrequestModifier- Function that sets the pagination value in the requestasyncDataFetcher- Function that fetches the response for a given request asynchronously
-
-