Package org.apache.pekko.actor.typed
Class Behavior<T>
java.lang.Object
org.apache.pekko.actor.typed.Behavior<T>
- Direct Known Subclasses:
BehaviorImpl.DeferredBehavior,BehaviorImpl.FailedBehavior,BehaviorImpl.SameBehavior$,BehaviorImpl.UnhandledBehavior$,ExtensibleBehavior,SuperviseBehavior
The behavior of an actor defines how it reacts to the messages that it
receives. The message may either be of the type that the Actor declares
and which is part of the
ActorRef signature, or it may be a system
Signal that expresses a lifecycle event of either this actor or one of
its child actors.
Behaviors can be formulated in a number of different ways, either by
using the DSLs in pekko.actor.typed.scaladsl.Behaviors and pekko.actor.typed.javadsl.Behaviors
or extending the abstract ExtensibleBehavior class.
Closing over ActorContext makes a Behavior immobile: it cannot be moved to another context and executed there, and therefore it cannot be replicated or forked either.
This base class is not meant to be extended by user code. If you do so, you may lose binary compatibility.
Not for user extension.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final <Inner> Behavior.BehaviorDecorators<Inner>BehaviorDecorators(Behavior<Inner> behavior) static <T> Behavior<T>canonicalize(Behavior<T> behavior, Behavior<T> current, TypedActorContext<T> ctx) Given a possibly special behavior (same or unhandled) and a “current” behavior (which defines the meaning of encountering asamebehavior) this method computes the next behavior, suitable for passing a message or signal.static <T> booleanexistsInStack(Behavior<T> behavior, scala.Function1<Behavior<T>, Object> p) Go through the behavior stack and apply a predicate to see if any nested behavior satisfies it.static <T> Behavior<T>interpretMessage(Behavior<T> behavior, TypedActorContext<T> ctx, T msg) Execute the behavior with the given message.static <T> Behavior<T>interpretSignal(Behavior<T> behavior, TypedActorContext<T> ctx, Signal signal) Execute the behavior with the given signal.static <T> booleanReturns true if the given behavior is not stopped.static <T> booleanisDeferred(Behavior<T> behavior) Returns true if the given behavior is deferred.static <T> booleanisUnhandled(Behavior<T> behavior) Returns true if the given behavior is the specialunhandledmarker.narrow()Narrow the type of this Behavior, which is always a safe operation.static <T> Behavior<T>start(Behavior<T> behavior, TypedActorContext<T> ctx) Starts deferred behavior and nested deferred behaviors until all deferred behaviors in the stack are started and then the resulting behavior is returned.static <T> Behavior<T>validateAsInitial(Behavior<T> behavior) Validate the given behavior as a suitable initial actor behavior; most notably the behavior can neither besamenorunhandled.
-
Constructor Details
-
Behavior
public Behavior(int _tag)
-
-
Method Details
-
BehaviorDecorators
public static final <Inner> Behavior.BehaviorDecorators<Inner> BehaviorDecorators(Behavior<Inner> behavior) -
canonicalize
public static <T> Behavior<T> canonicalize(Behavior<T> behavior, Behavior<T> current, TypedActorContext<T> ctx) Given a possibly special behavior (same or unhandled) and a “current” behavior (which defines the meaning of encountering asamebehavior) this method computes the next behavior, suitable for passing a message or signal. -
start
Starts deferred behavior and nested deferred behaviors until all deferred behaviors in the stack are started and then the resulting behavior is returned. -
existsInStack
public static <T> boolean existsInStack(Behavior<T> behavior, scala.Function1<Behavior<T>, Object> p) Go through the behavior stack and apply a predicate to see if any nested behavior satisfies it. The stack must not contain any unstarted deferred behavior or anIllegalArgumentExceptionwill be thrown. -
validateAsInitial
Validate the given behavior as a suitable initial actor behavior; most notably the behavior can neither besamenorunhandled. Starting out with aStoppedbehavior is allowed, though. -
isAlive
Returns true if the given behavior is not stopped. -
isUnhandled
Returns true if the given behavior is the specialunhandledmarker. -
isDeferred
Returns true if the given behavior is deferred. -
interpretMessage
public static <T> Behavior<T> interpretMessage(Behavior<T> behavior, TypedActorContext<T> ctx, T msg) Execute the behavior with the given message. -
interpretSignal
public static <T> Behavior<T> interpretSignal(Behavior<T> behavior, TypedActorContext<T> ctx, Signal signal) Execute the behavior with the given signal. -
narrow
Narrow the type of this Behavior, which is always a safe operation. This method is necessary to implement the contravariant nature of Behavior (which cannot be expressed directly due to type inference problems).
-