Object

akka.actor.typed.javadsl

Behaviors

Related Doc: package javadsl

Permalink

object Behaviors

Factories for akka.actor.typed.Behavior.

Annotations
@ApiMayChange()
Source
Behaviors.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Behaviors
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait Receive[T] extends ExtensibleBehavior[T]

    Permalink

    A specialized "receive" behavior that is implemented using message matching builders.

    A specialized "receive" behavior that is implemented using message matching builders.

    Annotations
    @DoNotInherit()
  2. final class Supervise[T] extends AnyRef

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def empty[T]: Behavior[T]

    Permalink

    A behavior that treats every incoming message as unhandled.

  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. def ignore[T]: Behavior[T]

    Permalink

    A behavior that ignores every incoming message and returns “same”.

  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. def monitor[T](clazz: Class[T], monitor: ActorRef[T], behavior: Behavior[T]): Behavior[T]

    Permalink

    Behavior decorator that copies all received message to the designated monitor akka.actor.typed.ActorRef before invoking the wrapped behavior.

    Behavior decorator that copies all received message to the designated monitor akka.actor.typed.ActorRef before invoking the wrapped behavior. The wrapped behavior can evolve (i.e. return different behavior) without needing to be wrapped in a monitor call again.

  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. def receive[T](type: Class[T]): BehaviorBuilder[T]

    Permalink

    Constructs an actor behavior builder that can build a behavior that can react to both incoming messages and lifecycle signals.

    Constructs an actor behavior builder that can build a behavior that can react to both incoming messages and lifecycle signals.

    This constructor is called immutable because the behavior instance does not need and in fact should not use (close over) mutable variables, but instead return a potentially different behavior encapsulating any state changes. If no change is desired, use #same.

    type

    the supertype of all messages accepted by this behavior

    returns

    the behavior builder

  19. def receive[T](onMessage: Function2[ActorContext[T], T, Behavior[T]], onSignal: Function2[ActorContext[T], Signal, Behavior[T]]): Behavior[T]

    Permalink

    Construct an actor behavior that can react to both incoming messages and lifecycle signals.

    Construct an actor behavior that can react to both incoming messages and lifecycle signals. After spawning this actor from another actor (or as the guardian of an akka.actor.typed.ActorSystem) it will be executed within an ActorContext that allows access to the system, spawning and watching other actors, etc.

    This constructor is called immutable because the behavior instance doesn't have or close over any mutable state. Processing the next message results in a new behavior that can potentially be different from this one. State is updated by returning a new behavior that holds the new immutable state.

  20. def receive[T](onMessage: Function2[ActorContext[T], T, Behavior[T]]): Behavior[T]

    Permalink

    Construct an actor behavior that can react to incoming messages but not to lifecycle signals.

    Construct an actor behavior that can react to incoming messages but not to lifecycle signals. After spawning this actor from another actor (or as the guardian of an akka.actor.typed.ActorSystem) it will be executed within an ActorContext that allows access to the system, spawning and watching other actors, etc.

    This constructor is called immutable because the behavior instance doesn't have or close over any mutable state. Processing the next message results in a new behavior that can potentially be different from this one. State is updated by returning a new behavior that holds the new immutable state.

  21. def receiveMessage[T](onMessage: Function[T, Behavior[T]]): Behavior[T]

    Permalink

    Simplified version of receive with only a single argument - the message to be handled.

    Simplified version of receive with only a single argument - the message to be handled. Useful for when the context is already accessible by other means, like being wrapped in an setup or similar.

    Construct an actor behavior that can react to incoming messages but not to lifecycle signals. After spawning this actor from another actor (or as the guardian of an akka.actor.typed.ActorSystem) it will be executed within an ActorContext that allows access to the system, spawning and watching other actors, etc.

    This constructor is called immutable because the behavior instance doesn't have or close over any mutable state. Processing the next message results in a new behavior that can potentially be different from this one. State is updated by returning a new behavior that holds the new immutable state.

  22. def receiveSignal[T](handler: Function2[ActorContext[T], Signal, Behavior[T]]): Behavior[T]

    Permalink

    Construct an actor behavior that can react to lifecycle signals only.

  23. def same[T]: Behavior[T]

    Permalink

    Return this behavior from message processing in order to advise the system to reuse the previous behavior.

    Return this behavior from message processing in order to advise the system to reuse the previous behavior. This is provided in order to avoid the allocation overhead of recreating the current behavior where that is not necessary.

  24. def setup[T](factory: Function[ActorContext[T], Behavior[T]]): Behavior[T]

    Permalink

    setup is a factory for a behavior.

    setup is a factory for a behavior. Creation of the behavior instance is deferred until the actor is started, as opposed to Behaviors#receive that creates the behavior instance immediately before the actor is running. The factory function pass the ActorContext as parameter and that can for example be used for spawning child actors.

    setup is typically used as the outer most behavior when spawning an actor, but it can also be returned as the next behavior when processing a message or signal. In that case it will be started immediately after it is returned, i.e. next message will be processed by the started behavior.

  25. def stopped[T](postStop: Behavior[T]): Behavior[T]

    Permalink

    Return this behavior from message processing to signal that this actor shall terminate voluntarily.

    Return this behavior from message processing to signal that this actor shall terminate voluntarily. If this actor has created child actors then these will be stopped as part of the shutdown procedure.

    The PostStop signal that results from stopping this actor will be passed to the given postStop behavior. All other messages and signals will effectively be ignored.

  26. def stopped[T]: Behavior[T]

    Permalink

    Return this behavior from message processing to signal that this actor shall terminate voluntarily.

    Return this behavior from message processing to signal that this actor shall terminate voluntarily. If this actor has created child actors then these will be stopped as part of the shutdown procedure.

    The PostStop signal that results from stopping this actor will be passed to the current behavior. All other messages and signals will effectively be ignored.

  27. def supervise[T](wrapped: Behavior[T]): Supervise[T]

    Permalink

    Wrap the given behavior such that it is restarted (i.e.

    Wrap the given behavior such that it is restarted (i.e. reset to its initial state) whenever it throws an exception of the given class or a subclass thereof. Exceptions that are not subtypes of Thr will not be caught and thus lead to the termination of the actor.

    It is possible to specify different supervisor strategies, such as restart, resume, backoff.

    The SupervisorStrategy is only invoked for "non fatal" (see scala.util.control.NonFatal) exceptions.

    Example:

    final Behavior[DbCommand] dbConnector = ...
    
    final Behavior[DbCommand] dbRestarts =
       Behaviors.supervise(dbConnector)
         .onFailure(SupervisorStrategy.restart) // handle all NonFatal exceptions
    
    final Behavior[DbCommand] dbSpecificResumes =
       Behaviors.supervise(dbConnector)
         .onFailure[IndexOutOfBoundsException](SupervisorStrategy.resume) // resume for IndexOutOfBoundsException exceptions
  28. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  29. def tap[T](clazz: Class[T], onMessage: Procedure2[ActorContext[T], T], onSignal: Procedure2[ActorContext[T], Signal], behavior: Behavior[T]): Behavior[T]

    Permalink

    This type of Behavior wraps another Behavior while allowing you to perform some action upon each received message or signal.

    This type of Behavior wraps another Behavior while allowing you to perform some action upon each received message or signal. It is most commonly used for logging or tracing what a certain Actor does.

  30. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  31. def unhandled[T]: Behavior[T]

    Permalink

    Return this behavior from message processing in order to advise the system to reuse the previous behavior, including the hint that the message has not been handled.

    Return this behavior from message processing in order to advise the system to reuse the previous behavior, including the hint that the message has not been handled. This hint may be used by composite behaviors that delegate (partial) handling to other behaviors.

  32. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. def widened[T, U](behavior: Behavior[T], selector: Function[PFBuilder[U, T], PFBuilder[U, T]]): Behavior[U]

    Permalink

    Widen the wrapped Behavior by placing a funnel in front of it: the supplied PartialFunction decides which message to pull in (those that it is defined at) and may transform the incoming message to place them into the wrapped Behavior’s type hierarchy.

    Widen the wrapped Behavior by placing a funnel in front of it: the supplied PartialFunction decides which message to pull in (those that it is defined at) and may transform the incoming message to place them into the wrapped Behavior’s type hierarchy. Signals are not transformed.

    Example:

    Behavior<String> s = Behaviors.receive((ctx, msg) -> {
        System.out.println(msg);
        return Behaviors.same();
      });
    Behavior<Number> n = Behaviors.widened(s, pf -> pf.
            match(BigInteger.class, i -> "BigInteger(" + i + ")").
            match(BigDecimal.class, d -> "BigDecimal(" + d + ")")
            // drop all other kinds of Number
        );

    Scheduled messages via TimerScheduler can currently not be used together with widen, see issue #25318.

    behavior

    the behavior that will receive the selected messages

    selector

    a partial function builder for describing the selection and transformation

    returns

    a behavior of the widened type

  36. def withMdc[T](staticMdc: Map[String, Any], mdcForMessage: Function[T, Map[String, Any]], behavior: Behavior[T]): Behavior[T]

    Permalink

    Combination of static and per message MDC (Mapped Diagnostic Context).

    Combination of static and per message MDC (Mapped Diagnostic Context).

    Each message will get the static MDC plus the MDC returned for the message. If the same key are in both the static and the per message MDC the per message one overwrites the static one in the resulting log entries.

    * The staticMdc or mdcForMessage may be empty.

    staticMdc

    A static MDC applied for each message

    mdcForMessage

    Is invoked before each message is handled, allowing to setup MDC, MDC is cleared after each message processing by the inner behavior is done.

    behavior

    The actual behavior handling the messages, the MDC is used for the log entries logged through ActorContext.log See also akka.actor.typed.Logger.withMdc

  37. def withMdc[T](staticMdc: Map[String, Any], behavior: Behavior[T]): Behavior[T]

    Permalink

    Static MDC (Mapped Diagnostic Context)

    Static MDC (Mapped Diagnostic Context)

    staticMdc

    This MDC is setup in the logging context for every message

    behavior

    The actual behavior handling the messages, the MDC is used for the log entries logged through ActorContext.log See also akka.actor.typed.Logger.withMdc

  38. def withMdc[T](mdcForMessage: Function[T, Map[String, Any]], behavior: Behavior[T]): Behavior[T]

    Permalink

    Per message MDC (Mapped Diagnostic Context) logging.

    Per message MDC (Mapped Diagnostic Context) logging.

    mdcForMessage

    Is invoked before each message is handled, allowing to setup MDC, MDC is cleared after each message processing by the inner behavior is done.

    behavior

    The actual behavior handling the messages, the MDC is used for the log entries logged through ActorContext.log See also akka.actor.typed.Logger.withMdc

  39. def withTimers[T](factory: Function[TimerScheduler[T], Behavior[T]]): Behavior[T]

    Permalink

    Support for scheduled self messages in an actor.

    Support for scheduled self messages in an actor. It takes care of the lifecycle of the timers such as cancelling them when the actor is restarted or stopped.

    See also

    TimerScheduler

Inherited from AnyRef

Inherited from Any

Ungrouped