Class AbstractBehavior<T>
- java.lang.Object
-
- akka.actor.typed.Behavior<T>
-
- akka.actor.typed.ExtensibleBehavior<T>
-
- akka.actor.typed.scaladsl.AbstractBehavior<T>
-
- Direct Known Subclasses:
InitialGroupRouterImpl,PoolRouterImpl
public abstract class AbstractBehavior<T> extends ExtensibleBehavior<T>
An actorBehaviorcan be implemented by extending this class and implement the abstract methodonMessage(T)and optionally overrideonSignal(). Mutable state can be defined as instance variables of the class.This is an Object-oriented style of defining a
Behavior. A more functional style alternative is provided by the factory methods inBehaviors, for exampleBehaviors.receiveMessage.Instances of this behavior should be created via
Behaviors.setupand theActorContextshould be passed as a constructor parameter from the factory function. This is important because a new instance should be created when restart supervision is used.When switching
Behaviorto anotherAbstractBehaviorthe originalActorContextcan be used as thecontextparameter instead of wrapping in a newBehaviors.setup, but it wouldn't be wrong to usecontextfromBehaviors.setupsince that is the sameActorContextinstance.It must not be created with an
ActorContextof another actor, such as the parent actor. Such mistake will be detected at runtime and throwIllegalStateExceptionwhen the first message is received.- See Also:
Behaviors.setup
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class akka.actor.typed.Behavior
Behavior.BehaviorDecorators<Inner>, Behavior.BehaviorDecorators$
-
-
Constructor Summary
Constructors Constructor Description AbstractBehavior(ActorContext<T> context)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected ActorContext<T>context()abstract Behavior<T>onMessage(T msg)Implement this method to process an incoming message and return the next behavior.scala.PartialFunction<Signal,Behavior<T>>onSignal()Override this method to process an incomingSignaland return the next behavior.Behavior<T>receive(TypedActorContext<T> ctx, T msg)Process an incoming message and return the next behavior.Behavior<T>receiveSignal(TypedActorContext<T> ctx, Signal msg)Process an incomingSignaland return the next behavior.-
Methods inherited from class akka.actor.typed.Behavior
BehaviorDecorators, canonicalize, existsInStack, interpretMessage, interpretSignal, isAlive, isDeferred, isUnhandled, narrow, start, validateAsInitial
-
-
-
-
Constructor Detail
-
AbstractBehavior
public AbstractBehavior(ActorContext<T> context)
-
-
Method Detail
-
context
protected ActorContext<T> context()
-
onMessage
public abstract Behavior<T> onMessage(T msg) throws java.lang.Exception
Implement this method to process an incoming message and return the next behavior.The returned behavior can in addition to normal behaviors be one of the canned special objects:
- returning
stoppedwill terminate this Behavior - returning
thisorsamedesignates to reuse the current Behavior - returning
unhandledkeeps the same Behavior and signals that the message was not yet handled
- Throws:
java.lang.Exception
- returning
-
onSignal
public scala.PartialFunction<Signal,Behavior<T>> onSignal() throws java.lang.Exception
Override this method to process an incomingSignaland return the next behavior. This means that all lifecycle hooks, ReceiveTimeout, Terminated and Failed messages can initiate a behavior change.The returned behavior can in addition to normal behaviors be one of the canned special objects:
* returning
stoppedwill terminate this Behavior * returningthisorsamedesignates to reuse the current Behavior * returningunhandledkeeps the same Behavior and signals that the message was not yet handledBy default, partial function is empty and does not handle any signals.
- Throws:
java.lang.Exception
-
receive
public final Behavior<T> receive(TypedActorContext<T> ctx, T msg) throws java.lang.Exception
Description copied from class:ExtensibleBehaviorProcess an incoming message and return the next behavior.The returned behavior can in addition to normal behaviors be one of the canned special objects:
* returning
stoppedwill terminate this Behavior * returningsamedesignates to reuse the current Behavior * returningunhandledkeeps the same Behavior and signals that the message was not yet handledCode calling this method should use
Behavior$canonicalizeto replace the special objects with real Behaviors.- Specified by:
receivein classExtensibleBehavior<T>- Throws:
java.lang.Exception
-
receiveSignal
public final Behavior<T> receiveSignal(TypedActorContext<T> ctx, Signal msg) throws java.lang.Exception
Description copied from class:ExtensibleBehaviorProcess an incomingSignaland return the next behavior. This means that all lifecycle hooks, ReceiveTimeout, Terminated and Failed messages can initiate a behavior change.The returned behavior can in addition to normal behaviors be one of the canned special objects:
* returning
stoppedwill terminate this Behavior * returningsamedesignates to reuse the current Behavior * returningunhandledkeeps the same Behavior and signals that the message was not yet handledCode calling this method should use
Behavior$canonicalizeto replace the special objects with real Behaviors.- Specified by:
receiveSignalin classExtensibleBehavior<T>- Throws:
java.lang.Exception
-
-