Package io.pravega.common.concurrent
Class OrderedProcessor<ResultType>
- java.lang.Object
-
- io.pravega.common.concurrent.OrderedProcessor<ResultType>
-
- All Implemented Interfaces:
java.lang.AutoCloseable
@ThreadSafe public class OrderedProcessor<ResultType> extends java.lang.Object implements java.lang.AutoCloseableProcesses items in order, subject to capacity constraints.
-
-
Constructor Summary
Constructors Constructor Description OrderedProcessor(int capacity, @NonNull java.util.concurrent.Executor executor)Creates a new instance of theOrderedProcessorclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.util.concurrent.CompletableFuture<ResultType>execute(@NonNull java.util.function.Supplier<java.util.concurrent.CompletableFuture<ResultType>> toRun)Executes the given item.protected voidexecutionComplete(java.lang.Throwable exception)Callback that is invoked when an item has completed execution.
-
-
-
Constructor Detail
-
OrderedProcessor
public OrderedProcessor(int capacity, @NonNull @NonNull java.util.concurrent.Executor executor)Creates a new instance of theOrderedProcessorclass.- Parameters:
capacity- The maximum number of concurrent executions.executor- An Executor for async invocations.
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
execute
public java.util.concurrent.CompletableFuture<ResultType> execute(@NonNull @NonNull java.util.function.Supplier<java.util.concurrent.CompletableFuture<ResultType>> toRun)
Executes the given item. * IfhasCapacity()is true, the item will be executed immediately and the returned future is the actual result fromtoRun. * IfhasCapacity()is false, the item will be queued up and it will be processed when capacity allows, after all the items added before it have been executed (whether exceptionally or with a successful outcome). * This method guarantees ordered execution as long as its invocations are serial. That is, it only guarantees that the item has begun processing or an order assigned if the method returned successfully.- Parameters:
toRun- ASupplierthat, when invoked, will return aCompletableFuturewhich will indicate the outcome of the operation to execute.- Returns:
- A CompletableFuture that, when completed, will indicate that the item has been processed. This will contain the result of the processing function applied to this item.
-
executionComplete
protected void executionComplete(java.lang.Throwable exception)
Callback that is invoked when an item has completed execution.- Parameters:
exception- (Optional) An exception from the execution. If set, it indicates the item has not been processed successfully.
-
-