Package org.infinispan.util.concurrent
Class ActionSequencer
- java.lang.Object
-
- org.infinispan.util.concurrent.ActionSequencer
-
public class ActionSequencer extends Object
Orders multiple actions/tasks based on a key.It has the following properties:
- If multiple actions have disjoint ordering keys, they are execute in parallel.
- If multiple actions have the same ordering keys, deadlocks are avoided between them.
- An action is only executed after the previous one is completed.
- Since:
- 10.0
- Author:
- Pedro Ruivo
-
-
Constructor Summary
Constructors Constructor Description ActionSequencer(ExecutorService executor, boolean forceExecutor, TimeService timeService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getAverageQueueTimeNanos()
long
getAverageRunningTimeNanos()
int
getMapSize()
long
getPendingActions()
long
getRunningActions()
<T> CompletionStage<T>
orderOnKey(Object key, Callable<? extends CompletionStage<T>> action)
<T> CompletionStage<T>
orderOnKeys(Collection<?> keys, Callable<? extends CompletionStage<T>> action)
It order a non-blocking action.void
resetStatistics()
void
setStatisticEnabled(boolean enable)
-
-
-
Constructor Detail
-
ActionSequencer
public ActionSequencer(ExecutorService executor, boolean forceExecutor, TimeService timeService)
- Parameters:
executor
- Executor to run submitted actions.forceExecutor
- Iffalse
, run submitted actions on the submitter thread if possible. Iftrue
, always run submitted actions on the executor.
-
-
Method Detail
-
orderOnKeys
public <T> CompletionStage<T> orderOnKeys(Collection<?> keys, Callable<? extends CompletionStage<T>> action)
It order a non-blocking action.It assumes the
action
does not block the invoked thread and it may execute it in this thread or, if there is one or more pending actions, in a separate thread (provided by theexecutor
).- Type Parameters:
T
- The return value type.- Parameters:
keys
- The ordering keys.action
- TheCallable
to invoke.- Returns:
- A
CompletableFuture
that is completed with the return value of resultingCompletableFuture
. - Throws:
NullPointerException
- if any of the parameter is null.
-
orderOnKey
public <T> CompletionStage<T> orderOnKey(Object key, Callable<? extends CompletionStage<T>> action)
-
getPendingActions
public long getPendingActions()
-
getRunningActions
public long getRunningActions()
-
resetStatistics
public void resetStatistics()
-
getAverageQueueTimeNanos
public long getAverageQueueTimeNanos()
-
getAverageRunningTimeNanos
public long getAverageRunningTimeNanos()
-
setStatisticEnabled
public void setStatisticEnabled(boolean enable)
-
getMapSize
public int getMapSize()
-
-