sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java
/**
   * This adapter handles using the continuation token to provide iteration over all the elements
   * returned by the Beam Fn State API using the supplied state client, state request for the first
   * chunk of the state stream, and a value decoder.
   *
   * <p>The first page, and only the first page, of the state request results is cached for
   * efficient re-iteration for small state requests while still allowing unboundedly large state
   * requests without unboundedly large memory consumption.
   *
   * @param beamFnStateClient A client for handling state requests.
   * @param stateRequestForFirstChunk A fully populated state request for the first (and possibly
   *     only) chunk of a state stream. This state request will be populated with a continuation
   *     token to request further chunks of the stream if required.
   * @param valueCoder A coder for decoding the state stream.
   */
This adapter handles using the continuation token to provide iteration over all the elements
returned by the Beam Fn State API using the supplied state client, state request for the first
chunk of the state stream, and a value decoder.

The first page, and only the first page, of the state request results is cached for
efficient re-iteration for small state requests while still allowing unboundedly large state
requests without unboundedly large memory consumption.

@param beamFnStateClient A client for handling state requests.
@param stateRequestForFirstChunk A fully populated state request for the first (and possibly
only) chunk of a state stream. This state request will be populated with a continuation
token to request further chunks of the stream if required.
@param valueCoder A coder for decoding the state stream.
This adapter handles using the continuation token to provide iteration over all the elements returned by the Beam Fn State API using the supplied state client state request for the first chunk of the state stream and a value decoder . The first page and only the first page of the state request results is cached for efficient re - iteration for small state requests while still allowing unboundedly large state requests without unboundedly large memory consumption . @param beamFnStateClient A client for handling state requests . @param stateRequestForFirstChunk A fully populated state request for the first ( and possibly only ) chunk of a state stream . This state request will be populated with a continuation token to request further chunks of the stream if required . @param valueCoder A coder for decoding the state stream .
public static <T> Iterable<T> readAllAndDecodeStartingFrom(
      BeamFnStateClient beamFnStateClient,
      StateRequest stateRequestForFirstChunk,
      Coder<T> valueCoder) {
    FirstPageAndRemainder firstPageAndRemainder =
        new FirstPageAndRemainder(beamFnStateClient, stateRequestForFirstChunk);
    return Iterables.concat(
        new LazyCachingIteratorToIterable<T>(
            new DataStreams.DataStreamDecoder<>(
                valueCoder,
                DataStreams.inbound(
                    new LazySingletonIterator<>(firstPageAndRemainder::firstPage)))),
        () ->
            new DataStreams.DataStreamDecoder<>(
                valueCoder, DataStreams.inbound(firstPageAndRemainder.remainder())));
  }
public static < T > Iterable < T > readAllAndDecodeStartingFrom ( BeamFnStateClient beamFnStateClient , StateRequest stateRequestForFirstChunk , Coder < T > valueCoder ) { FirstPageAndRemainder firstPageAndRemainder = new FirstPageAndRemainder ( beamFnStateClient , stateRequestForFirstChunk ) ; return Iterables . concat ( new LazyCachingIteratorToIterable < T > ( new DataStreams . DataStreamDecoder < > ( valueCoder , DataStreams . inbound ( new LazySingletonIterator < > ( firstPageAndRemainder :: firstPage ) ) ) ) , ( ) -> new DataStreams . DataStreamDecoder < > ( valueCoder , DataStreams . inbound ( firstPageAndRemainder . remainder ( ) ) ) ) ; }
This adapter handles using the continuation token to provide iteration over all the elements
 returned by the Beam Fn State API using the supplied state client, state request for the first
 chunk of the state stream, and a value decoder.
This adapter handles using the continuation token to provide iteration over all the elements returned by the Beam Fn State API using the supplied state client state request for the first chunk of the state stream and a value decoder .