Class ActorControl

java.lang.Object
io.camunda.zeebe.scheduler.ActorControl
All Implemented Interfaces:
ConcurrencyControl, Executor

public class ActorControl extends Object implements ConcurrencyControl
  • Constructor Details

    • ActorControl

      public ActorControl(Actor actor)
  • Method Details

    • current

      public static ActorControl current()
    • onCondition

      public ActorCondition onCondition(String conditionName, Runnable conditionAction)
      Conditional actions are called while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Parameters:
      conditionName -
      conditionAction -
      Returns:
    • call

      public ActorFuture<Void> call(Runnable action)
      Callables actions are called while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Parameters:
      action -
      Returns:
    • runAtFixedRate

      public ScheduledTimer runAtFixedRate(Duration delay, Runnable runnable)
      Scheduled a repeating timer

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

      Parameters:
      delay -
      runnable -
      Returns:
    • runAt

      public ScheduledTimer runAt(long timestamp, Runnable runnable)
      Schedule a timer task at (or after) a timestamp.

      The runnable is executed while the actor is in the following actor lifecycle phases: invalid input: '{@link *' ActorLifecyclePhase#STARTED}

      This provides no guarantees that the timer task is run at the timestamp. It's likely that the timer task is run shortly after the timestamp. We guarantee that the runnable won't run before the timestamp.

      Parameters:
      timestamp - A unix epoch timestamp in milliseconds
      runnable - The runnable to run at (or after) the timestamp
      Returns:
      A handle to the scheduled timer task
    • runOnCompletion

      public <T> void runOnCompletion(ActorFuture<T> future, BiConsumer<T,Throwable> callback)
      Invoke the callback when the given future is completed (successfully or exceptionally). This call does not block the actor. If close is requested the actor will not wait on this future, in this case the callback is never called.

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

      Specified by:
      runOnCompletion in interface ConcurrencyControl
      Type Parameters:
      T - result type of the future
      Parameters:
      future - the future to wait on
      callback - the callback that handle the future's result. The throwable is null when the future is completed successfully.
    • run

      public void run(Runnable action)
      Runnables submitted by the actor itself are executed while the actor is in any of its lifecycle phases.

      Runnables submitted externally are executed while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED

      Specified by:
      run in interface ConcurrencyControl
      Parameters:
      action -
    • call

      public <T> ActorFuture<T> call(Callable<T> callable)
      Callables actions are called while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Specified by:
      call in interface ConcurrencyControl
      Type Parameters:
      T - type of the result
      Parameters:
      callable -
      Returns:
    • schedule

      public ScheduledTimer schedule(Duration delay, Runnable runnable)
      The runnable is executed while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Specified by:
      schedule in interface ConcurrencyControl
      Parameters:
      delay -
      runnable -
      Returns:
    • submit

      public void submit(Runnable action)
      Like run(Runnable) but submits the runnable to the end of the actor's queue such that other actions may be executed before this. This method is useful in case an actor is in a (potentially endless) loop, and it should be able to interrupt it.

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

      Parameters:
      action - the action to run.
    • runOnCompletionBlockingCurrentPhase

      public <T> void runOnCompletionBlockingCurrentPhase(ActorFuture<T> future, BiConsumer<T,Throwable> callback)
      Invoke the callback when the given future is completed (successfully or exceptionally). This call does not block the actor. If close is requested the actor will wait on this future and not change the phase, in this case the callback will eventually be called.

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

      Parameters:
      future - the future to wait on
      callback - the callback that handle the future's result. The throwable is null when the future is completed successfully.
    • runOnCompletion

      public <T> void runOnCompletion(Collection<ActorFuture<T>> futures, Consumer<Throwable> callback)
      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:
      futures - 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.
    • yieldThread

      public void yieldThread()
      can be called by the actor to yield the thread
    • close

      public ActorFuture<Void> close()
    • isClosing

      public boolean isClosing()
    • isClosed

      public boolean isClosed()
    • getLifecyclePhase

      public ActorTask.ActorLifecyclePhase getLifecyclePhase()
    • isCalledFromWithinActor

      public boolean isCalledFromWithinActor(ActorJob job)
    • fail

      public void fail(Throwable error)
      Mark actor as failed. This sets the lifecycle phase to 'FAILED' and discards all jobs.