Interface PageSource<T>
- All Known Implementing Classes:
AsyncPageSource,EagerPageSource
public interface PageSource<T>
Strategy answering "where do page items come from" for a paginator.
EagerPageSource
serves an in-memory list synchronously; AsyncPageSource loads pages on demand through
an AsyncPageSupplier.-
Method Summary
Modifier and TypeMethodDescriptionelements()default voidClears any cached pages.booleanvoidrequest(PageRequest request, BiConsumer<PageResult<T>, Throwable> onSettle) Requests the page described byrequest.intboolean
-
Method Details
-
request
Requests the page described byrequest.Contract for implementations:
onSettleis invoked at most once per request, with exactly one of result/error non-null — and possibly never (a superseded request).- It MAY be invoked synchronously inside this method and MAY be invoked on any thread.
- A request superseded by a newer one MUST NOT be settled.
isLoading()must returnfalseonce the latest request settled.
- Parameters:
request- the page to load, never nullonSettle- receives the result or the failure, never null
-
totalElements
int totalElements()- Returns:
- the total number of elements in the backing store;
0until known for async sources
-
totalsKnown
boolean totalsKnown()- Returns:
trueoncetotalElements()reflects the real store size — always for eager sources, after the first successful settle for async sources
-
isLoading
boolean isLoading()- Returns:
truewhile the latest request has not settled
-
lastError
Throwable lastError()- Returns:
- the failure of the most recently settled request, or
null; cleared when a new request is dispatched
-
elements
- Returns:
- the elements currently held locally — the full backing list for eager sources, the items of the most recently applied page for async sources
-
invalidate
default void invalidate()Clears any cached pages. No-op by default.
-