Class Pipelining<E>
java.lang.Object
com.loomcache.client.Pipelining<E>
- Type Parameters:
E- result type produced by the tracked asynchronous operations
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(CompletionStage<? extends E> stage) Add an already-created asynchronous operation, blocking when the pipeline is at capacity.CompletableFuture<? extends E> add(Supplier<? extends CompletionStage<? extends E>> stageSupplier) Add an asynchronous operation supplier, starting it only after pipeline capacity is available.intdepth()intinFlight()results()Wait for every added operation and return results in add order.Wait for every added operation up to the supplied timeout and return results in add order.intsize()static <E> Pipelining<E> withDepth(int depth)
-
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
-
add
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
-
results
-
depth
public int depth() -
size
public int size() -
inFlight
public int inFlight()
-