Class AbstractBehavior<T>
Behavior can be implemented by extending this class and implement the
abstract method createReceive(). 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 in Behaviors, for example
Behaviors.receiveMessage.
Instances of this behavior should be created via Behaviors.setup and
the ActorContext should 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 Behavior to another AbstractBehavior the original ActorContext
can be used as the context parameter instead of wrapping in a new Behaviors.setup,
but it wouldn't be wrong to use context from Behaviors.setup since that is the same
ActorContext instance.
It must not be created with an ActorContext of another actor, such as the parent actor.
Such mistake will be detected at runtime and throw IllegalStateException when the
first message is received.
- See Also:
-
Behaviors.setup
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.pekko.actor.typed.Behavior
Behavior.BehaviorDecorators<Inner>, Behavior.BehaviorDecorators$ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionImplement this to define how messages and signals are processed.protected ActorContext<T>protected ReceiveBuilder<T>Create a newReceiveBuilderto define the message dispatch of theBehavior.receive(TypedActorContext<T> ctx, T msg) Process an incoming message and return the next behavior.receiveSignal(TypedActorContext<T> ctx, Signal msg) Process an incomingSignaland return the next behavior.Methods inherited from class org.apache.pekko.actor.typed.Behavior
BehaviorDecorators, canonicalize, existsInStack, interpretMessage, interpretSignal, isAlive, isDeferred, isUnhandled, narrow, start, validateAsInitial
-
Constructor Details
-
AbstractBehavior
-
-
Method Details
-
createReceive
Implement this to define how messages and signals are processed. Use theAbstractBehavior.newReceiveBuilderto define the message dispatch. -
getContext
-
newReceiveBuilder
Create a newReceiveBuilderto define the message dispatch of theBehavior. Typically used fromAbstractBehavior.createReceive. -
receive
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:
Exception
-
receiveSignal
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:
Exception
-