Class ActionSequencer


  • public class ActionSequencer
    extends java.lang.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​(java.util.concurrent.ExecutorService executor)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getMapSize()  
      long getPendingActions()  
      <T> java.util.concurrent.CompletionStage<T> orderOnKey​(java.lang.Object key, java.util.concurrent.Callable<? extends java.util.concurrent.CompletionStage<T>> action)  
      <T> java.util.concurrent.CompletionStage<T> orderOnKeys​(java.util.Collection<?> keys, java.util.concurrent.Callable<? extends java.util.concurrent.CompletionStage<T>> action)
      It order a non-blocking action.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ActionSequencer

        public ActionSequencer​(java.util.concurrent.ExecutorService executor)
    • Method Detail

      • orderOnKeys

        public <T> java.util.concurrent.CompletionStage<T> orderOnKeys​(java.util.Collection<?> keys,
                                                                       java.util.concurrent.Callable<? extends java.util.concurrent.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 the executor).

        Type Parameters:
        T - The return value type.
        Parameters:
        keys - The ordering keys.
        action - The Callable to invoke.
        Returns:
        A CompletableFuture that is completed with the return value of resulting CompletableFuture.
        Throws:
        java.lang.NullPointerException - if any of the parameter is null.
      • orderOnKey

        public <T> java.util.concurrent.CompletionStage<T> orderOnKey​(java.lang.Object key,
                                                                      java.util.concurrent.Callable<? extends java.util.concurrent.CompletionStage<T>> action)
      • getPendingActions

        public long getPendingActions()
      • getMapSize

        public int getMapSize()