Package io.pravega.common.concurrent
Class MultiKeySequentialProcessor<KeyType>
- java.lang.Object
-
- io.pravega.common.concurrent.MultiKeySequentialProcessor<KeyType>
-
- Type Parameters:
KeyType- Type of the Key.
- All Implemented Interfaces:
java.lang.AutoCloseable
@ThreadSafe public class MultiKeySequentialProcessor<KeyType> extends java.lang.Object implements java.lang.AutoCloseableConcurrent async processor that allows parallel execution of tasks with different keys, but serializes the execution of tasks with the same key.
-
-
Constructor Summary
Constructors Constructor Description MultiKeySequentialProcessor(java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <ReturnType>
java.util.concurrent.CompletableFuture<ReturnType>add(java.util.Collection<KeyType> keys, java.util.function.Supplier<java.util.concurrent.CompletableFuture<? extends ReturnType>> toRun)Queues up a new task to execute, subject to the given dependency Keys.<ReturnType>
java.util.concurrent.CompletableFuture<ReturnType>addWithFilter(java.util.function.Predicate<KeyType> keyFilter, java.util.function.Supplier<java.util.concurrent.CompletableFuture<? extends ReturnType>> toRun)Queues up a new task to execute, subject to the dependency keys that match the given filter.voidclose()intgetCurrentTaskCount()Gets the number of concurrent tasks currently executing.
-
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
getCurrentTaskCount
public int getCurrentTaskCount()
Gets the number of concurrent tasks currently executing.- Returns:
- task count
-
add
public <ReturnType> java.util.concurrent.CompletableFuture<ReturnType> add(java.util.Collection<KeyType> keys, java.util.function.Supplier<java.util.concurrent.CompletableFuture<? extends ReturnType>> toRun)
Queues up a new task to execute, subject to the given dependency Keys. This task will not begin execution until all previous tasks for the given dependency Keys have finished. In addition, no subsequent task for any of the given dependency Keys will begin executing until this task has finished executing.- Type Parameters:
ReturnType- Return type.- Parameters:
keys- A Collection of KeyType objects representing the Keys that this task is dependent on.toRun- A Supplier that will be invoked when it is this task's turn to run. It will return a CompletableFuture that will complete when this task completes.- Returns:
- A CompletableFuture that will complete with the result from the CompletableFuture returned by toRun, when toRun completes executing.
-
addWithFilter
public <ReturnType> java.util.concurrent.CompletableFuture<ReturnType> addWithFilter(java.util.function.Predicate<KeyType> keyFilter, java.util.function.Supplier<java.util.concurrent.CompletableFuture<? extends ReturnType>> toRun)
Queues up a new task to execute, subject to the dependency keys that match the given filter. This task will not begin execution until all previous tasks whose keys match the given filter have finished. In addition, no subsequent task for any key that matches the given filter will begin executing until this task has finished executing.- Type Parameters:
ReturnType- Return type.- Parameters:
keyFilter- A Predicate defining the filter that determines which keys this task will depend on.toRun- A Supplier that will be invoked when it is this task's turn to run. It will return a CompletableFuture that will complete when this task completes.- Returns:
- A CompletableFuture that will complete with the result from the CompletableFuture returned by toRun, when toRun completes executing.
-
-