Package akka.actor.typed
Class Behavior<T>
- java.lang.Object
-
- akka.actor.typed.Behavior<T>
-
- Direct Known Subclasses:
BehaviorImpl.DeferredBehavior
,BehaviorImpl.FailedBehavior
,BehaviorImpl.SameBehavior$
,BehaviorImpl.UnhandledBehavior$
,ExtensibleBehavior
public abstract class Behavior<T> extends java.lang.Object
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 theActorRef
signature, or it may be a systemSignal
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
Behaviors
andBehaviors
or extending the abstractExtensibleBehavior
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 Classes Modifier and Type Class Description static class
Behavior.BehaviorDecorators<Inner>
static class
Behavior.BehaviorDecorators$
-
Constructor Summary
Constructors Constructor Description Behavior(int _tag)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <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 asame
behavior) this method computes the next behavior, suitable for passing a message or signal.static <T> boolean
existsInStack(Behavior<T> behavior, scala.Function1<Behavior<T>,java.lang.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> boolean
isAlive(Behavior<T> behavior)
Returns true if the given behavior is not stopped.static <T> boolean
isDeferred(Behavior<T> behavior)
Returns true if the given behavior is deferred.static <T> boolean
isUnhandled(Behavior<T> behavior)
Returns true if the given behavior is the specialunhandled
marker.<U extends T>
Behavior<U>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 besame
norunhandled
.
-
-
-
Method Detail
-
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 asame
behavior) this method computes the next behavior, suitable for passing a message or signal.
-
start
public 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.
-
existsInStack
public static <T> boolean existsInStack(Behavior<T> behavior, scala.Function1<Behavior<T>,java.lang.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 anIllegalArgumentException
will be thrown.
-
validateAsInitial
public static <T> Behavior<T> validateAsInitial(Behavior<T> behavior)
Validate the given behavior as a suitable initial actor behavior; most notably the behavior can neither besame
norunhandled
. Starting out with aStopped
behavior is allowed, though.
-
isAlive
public static <T> boolean isAlive(Behavior<T> behavior)
Returns true if the given behavior is not stopped.
-
isUnhandled
public static <T> boolean isUnhandled(Behavior<T> behavior)
Returns true if the given behavior is the specialunhandled
marker.
-
isDeferred
public static <T> boolean isDeferred(Behavior<T> behavior)
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.
-
-