Class Actor

java.lang.Object
io.camunda.zeebe.scheduler.Actor
All Implemented Interfaces:
AsyncClosable, ConcurrencyControl, AutoCloseable, Executor

public abstract class Actor extends Object implements AutoCloseable, AsyncClosable, ConcurrencyControl
  • Field Details

  • Constructor Details

    • Actor

      public Actor()
  • Method Details

    • createContext

      protected Map<String,String> createContext()
      Should be overwritten by sub classes to add more context where the actor is run.
      Returns:
      the context of the actor
    • getName

      public String getName()
    • getContext

      public Map<String,String> getContext()
      Returns:
      a map which defines the context where the actor is run. Per default it just returns a map with the actor name. Ideally sub classes add more context, like the partition id etc.
    • isActorClosed

      public boolean isActorClosed()
    • onActorStarting

      protected void onActorStarting()
    • onActorStarted

      protected void onActorStarted()
    • onActorClosing

      protected void onActorClosing()
    • onActorClosed

      protected void onActorClosed()
    • onActorCloseRequested

      protected void onActorCloseRequested()
    • wrap

      public static Actor wrap(Consumer<ActorControl> r)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • closeAsync

      public ActorFuture<Void> closeAsync()
      Description copied from interface: AsyncClosable
      Asynchronous closing. The implementation should close related resources and return a future, which is complete when closing is done.
      Specified by:
      closeAsync in interface AsyncClosable
      Returns:
      the future, which is completed when resources are closed
    • buildActorName

      public static String buildActorName(String name, int partitionId)
    • handleFailure

      protected void handleFailure(Throwable failure)
      Invoked when a task throws and the actor phase is not 'STARTING' and 'CLOSING'.
    • onActorFailed

      public void onActorFailed()
    • runOnCompletion

      public <T> void runOnCompletion(ActorFuture<T> future, BiConsumer<T,Throwable> callback)
      Description copied from interface: ConcurrencyControl
      Schedules a callback to be invoked after the future has completed
      Specified by:
      runOnCompletion in interface ConcurrencyControl
      Type Parameters:
      T - result type of the future
      Parameters:
      future - the future whose completion is awaited
      callback - the callback to call after the future has completed
    • runOnCompletion

      public <T> void runOnCompletion(Collection<ActorFuture<T>> actorFutures, Consumer<Throwable> callback)
      Description copied from interface: ConcurrencyControl
      Invoke the callback when the given futures are completed (successfully or exceptionally). This call does not block the actor.

      The callback is executed while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED

      Specified by:
      runOnCompletion in interface ConcurrencyControl
      Parameters:
      actorFutures - the futures to wait on
      callback - The throwable is null when all futures are completed successfully. Otherwise, it holds the exception of the last completed future.
    • run

      public void run(Runnable action)
      Description copied from interface: ConcurrencyControl
      Schedules an action to be invoked (must be called from an actor thread)
      Specified by:
      run in interface ConcurrencyControl
      Parameters:
      action - action to be invoked
    • call

      public <T> ActorFuture<T> call(Callable<T> callable)
      Description copied from interface: ConcurrencyControl
      Schedules a callable to be executed
      Specified by:
      call in interface ConcurrencyControl
      Type Parameters:
      T - type of the result
      Parameters:
      callable - callable to be executed
      Returns:
      a future with the result
    • schedule

      public ScheduledTimer schedule(Duration delay, Runnable runnable)
      Description copied from interface: ConcurrencyControl
      Schedule a task to be executed after a delay
      Specified by:
      schedule in interface ConcurrencyControl
    • newActor

      public static Actor.ActorBuilder newActor()