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 Details

    • request

      void request(PageRequest request, BiConsumer<PageResult<T>,Throwable> onSettle)
      Requests the page described by request.

      Contract for implementations:

      • onSettle is 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 return false once the latest request settled.
      Parameters:
      request - the page to load, never null
      onSettle - receives the result or the failure, never null
    • totalElements

      int totalElements()
      Returns:
      the total number of elements in the backing store; 0 until known for async sources
    • totalsKnown

      boolean totalsKnown()
      Returns:
      true once totalElements() reflects the real store size — always for eager sources, after the first successful settle for async sources
    • isLoading

      boolean isLoading()
      Returns:
      true while 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

      List<T> 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.