Class AbstractBehavior<T>


  • public abstract class AbstractBehavior<T>
    extends ExtensibleBehavior<T>
    An actor 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 if the ActorContext is needed it can be passed as a constructor parameter from the factory function.

    See Also:
    Behaviors.setup
    • Constructor Detail

      • AbstractBehavior

        public AbstractBehavior()
    • Method Detail

      • createReceive

        public abstract Receive<T> createReceive()
        Implement this to define how messages and signals are processed. Use the AbstractBehavior.newReceiveBuilder to define the message dispatch.
        Returns:
        (undocumented)
      • newReceiveBuilder

        public ReceiveBuilder<T> newReceiveBuilder()
        Create a new ReceiveBuilder to define the message dispatch of the Behavior. Typically used from AbstractBehavior.createReceive.
        Returns:
        (undocumented)
      • receive

        public final Behavior<T> receive​(TypedActorContext<T> ctx,
                                         T msg)
                                  throws java.lang.Exception
        Description copied from class: ExtensibleBehavior
        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 stopped will terminate this Behavior * returning same designates to reuse the current Behavior * returning unhandled keeps the same Behavior and signals that the message was not yet handled

        Code calling this method should use Behavior$ canonicalize to replace the special objects with real Behaviors.

        Specified by:
        receive in class ExtensibleBehavior<T>
        Parameters:
        ctx - (undocumented)
        msg - (undocumented)
        Returns:
        (undocumented)
        Throws:
        java.lang.Exception
      • receiveSignal

        public final Behavior<T> receiveSignal​(TypedActorContext<T> ctx,
                                               Signal msg)
                                        throws java.lang.Exception
        Description copied from class: ExtensibleBehavior
        Process an incoming Signal and 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 stopped will terminate this Behavior * returning same designates to reuse the current Behavior * returning unhandled keeps the same Behavior and signals that the message was not yet handled

        Code calling this method should use Behavior$ canonicalize to replace the special objects with real Behaviors.

        Specified by:
        receiveSignal in class ExtensibleBehavior<T>
        Parameters:
        ctx - (undocumented)
        msg - (undocumented)
        Returns:
        (undocumented)
        Throws:
        java.lang.Exception