Class ActorControl

java.lang.Object
io.camunda.zeebe.util.sched.ActorControl
All Implemented Interfaces:
ConcurrencyControl

public class ActorControl extends Object implements ConcurrencyControl
  • Constructor Details

    • ActorControl

      public ActorControl(Actor actor)
  • Method Details

    • current

      public static ActorControl current()
    • setSchedulingHints

      public void setSchedulingHints(int hints)
      changes the actor's scheduling hints. For example, this makes it possible to transform a cpu-bound actor into an io-bound actor and vice versa.
      Parameters:
      hints - the changed scheduling hints
    • consume

      public ChannelSubscription consume(ConsumableChannel channel, Runnable consumer)
      Consumers are called while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Parameters:
      channel -
      consumer -
    • 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 <T> ActorFuture<T> call(Callable<T> callable)
      Callables actions are called while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Parameters:
      callable -
      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:
    • runUntilDone

      public void runUntilDone(Runnable runnable)
      Run the provided runnable repeatedly until it calls done(). To be used for jobs which may experience backpressure.
    • runDelayed

      public ScheduledTimer runDelayed(Duration delay, Runnable runnable)
      The runnable is is executed while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED
      Parameters:
      delay -
      runnable -
      Returns:
    • runAtFixedRate

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

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

      Parameters:
      delay -
      runnable -
      Returns:
    • 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 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 -
    • submit

      public void submit(Runnable action)
      Like run(Runnable) but submits the runnable to the end end of the actor's queue such that other 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 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 called.

      The callback is 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 is executed while the actor is in the following actor lifecycle phases: ActorTask.ActorLifecyclePhase.STARTED

      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()
    • done

      public void done()
    • isClosing

      public boolean isClosing()
    • isClosed

      public boolean isClosed()
    • setPriority

      public void setPriority(ActorPriority priority)
    • getLifecyclePhase

      public ActorTask.ActorLifecyclePhase getLifecyclePhase()
    • isCalledFromWithinActor

      public boolean isCalledFromWithinActor(ActorJob job)
    • fail

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