Class Pipelining<E>

java.lang.Object
com.loomcache.client.Pipelining<E>
Type Parameters:
E - result type produced by the tracked asynchronous operations

public final class Pipelining<E> extends Object
Bounded in-flight helper for batching asynchronous client operations from one caller thread.

The pipeline applies backpressure at add(CompletionStage) time: if the configured depth is already in flight, the caller blocks until one tracked stage completes. Use add(Supplier) when the async operation itself should not be started until capacity is available.

  • Constructor Details

    • Pipelining

      public Pipelining(int depth)
      Create a bounded pipeline.
      Parameters:
      depth - maximum number of in-flight operations, must be positive
  • Method Details

    • withDepth

      public static <E> Pipelining<E> withDepth(int depth)
    • add

      public void add(CompletionStage<? extends E> stage)
      Add an already-created asynchronous operation, blocking when the pipeline is at capacity.
    • add

      public CompletableFuture<? extends E> add(Supplier<? extends CompletionStage<? extends E>> stageSupplier)
      Add an asynchronous operation supplier, starting it only after pipeline capacity is available.
      Returns:
      the tracked future created by the supplier
    • results

      public List<E> results()
      Wait for every added operation and return results in add order.
    • results

      public List<E> results(Duration timeout)
      Wait for every added operation up to the supplied timeout and return results in add order.
    • depth

      public int depth()
    • size

      public int size()
    • inFlight

      public int inFlight()