Class AbstractMatchingBehavior<T>
Behavior can be implemented by extending this class and implementing the abstract
method onMessage(T). 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.
An alternative object-oriented style is found in AbstractBehavior, which uses builders to
define the Behavior. In contrast to extending AbstractBehavior, extending this class
should have reduced overhead, though depending on the complexity of the protocol handled by
this actor and on the Java version in use, the onMessage and onSignal methods may be overly
complex.
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 behavior which requires a context, the original ActorContext can
be used or a Behaviors.setup can be used: either will end up using the same ActorContext instance.
It must not be created with an ActorContext of another actor (e.g. the parent actor). Doing so
will be detected at runtime and throw an 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 TypeMethodDescriptionprotected final ActorContext<T>Implement this to define how messages are processed.Override this to handle a signal.receive(TypedActorContext<T> ctx, T msg) Process an incoming message and return the next behavior.receiveSignal(TypedActorContext<T> ctx, Signal signal) 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
-
AbstractMatchingBehavior
-
-
Method Details
-
getContext
-
onMessage
Implement this to define how messages are processed. To indicate no change in behavior beyond changes due to updating instance variables of this class, one may return eitherthisorBehaviors.same.- Throws:
Exception
-
onSignal
Override this to handle a signal. The default implementation handles onlyMessageAdaptionFailureand otherwise ignores the signal.- Throws:
Exception
-
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
-