object Behaviors
- Alphabetic
- By Inheritance
- Behaviors
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def empty[T]: Behavior[T]
A behavior that treats every incoming message as unhandled.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def ignore[T]: Behavior[T]
A behavior that ignores every incoming message and returns “same”.
- def intercept[O, I](behaviorInterceptor: Supplier[BehaviorInterceptor[O, I]], behavior: Behavior[I]): Behavior[O]
Intercept messages and signals for a
behavior
by first passing them to a akka.actor.typed.BehaviorInterceptorIntercept messages and signals for a
behavior
by first passing them to a akka.actor.typed.BehaviorInterceptorWhen a behavior returns a new behavior as a result of processing a signal or message and that behavior already contains the same interceptor (defined by the akka.actor.typed.BehaviorInterceptor#isSame method) only the innermost interceptor is kept. This is to protect against stack overflow when recursively defining behaviors.
The interceptor is created with a factory function in case it has state and should not be shared. If the interceptor has no state the same instance can be returned from the factory to avoid unnecessary object creation.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def logMessages[T](logOptions: LogOptions, behavior: Behavior[T]): Behavior[T]
Behavior decorator that logs all messages to the akka.actor.typed.Behavior using the provided akka.actor.typed.LogOptions configuration before invoking the wrapped behavior.
Behavior decorator that logs all messages to the akka.actor.typed.Behavior using the provided akka.actor.typed.LogOptions configuration before invoking the wrapped behavior. To include an MDC context then first wrap
logMessages
withwithMDC
. - def logMessages[T](behavior: Behavior[T]): Behavior[T]
Behavior decorator that logs all messages to the akka.actor.typed.Behavior using the provided akka.actor.typed.LogOptions default configuration before invoking the wrapped behavior.
Behavior decorator that logs all messages to the akka.actor.typed.Behavior using the provided akka.actor.typed.LogOptions default configuration before invoking the wrapped behavior. To include an MDC context then first wrap
logMessages
withwithMDC
. - def monitor[T](interceptMessageClass: Class[T], monitor: ActorRef[T], behavior: Behavior[T]): Behavior[T]
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.- interceptMessageClass
Ensures that the messages of this class or a subclass thereof will be sent to the
monitor
. Other message types (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior.- monitor
The messages will also be sent to this
ActorRef
- behavior
The inner behavior that is decorated
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def receive[T](type: Class[T]): BehaviorBuilder[T]
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.
Compared to using AbstractBehavior this factory is a more functional style of defining the
Behavior
. Processing the next message results in a new behavior that can potentially be different from this one. State is maintained by returning a new behavior that holds the new immutable state.- type
the supertype of all messages accepted by this behavior
- returns
the behavior builder
- def receive[T](onMessage: Function2[ActorContext[T], T, Behavior[T]], onSignal: Function2[ActorContext[T], Signal, Behavior[T]]): Behavior[T]
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.
Compared to using AbstractBehavior this factory is a more functional style of defining the
Behavior
. Processing the next message results in a new behavior that can potentially be different from this one. State is maintained by returning a new behavior that holds the new immutable state. - def receive[T](onMessage: Function2[ActorContext[T], T, Behavior[T]]): Behavior[T]
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.
Compared to using AbstractBehavior this factory is a more functional style of defining the
Behavior
. Processing the next message results in a new behavior that can potentially be different from this one. State is maintained by returning a new behavior that holds the new immutable state. - def receiveMessage[T](onMessage: Function[T, Behavior[T]]): Behavior[T]
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.
Compared to using AbstractBehavior this factory is a more functional style of defining the
Behavior
. Processing the next message results in a new behavior that can potentially be different from this one. State is maintained by returning a new behavior that holds the new immutable state. - def receiveSignal[T](handler: Function2[ActorContext[T], Signal, Behavior[T]]): Behavior[T]
Construct an actor behavior that can react to lifecycle signals only.
- def same[T]: Behavior[T]
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.
- def setup[T](factory: Function[ActorContext[T], Behavior[T]]): Behavior[T]
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. Thefactory
function pass theActorContext
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. - def stopped[T](postStop: Effect): Behavior[T]
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 first be passed to the current behavior and then the providedpostStop
callback will be invoked. All other messages and signals will effectively be ignored.An example of when the callback can be useful compared to the
PostStop
signal if you want to send a reply to the message that initiated a graceful stop. - def stopped[T]: Behavior[T]
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. - def supervise[T](wrapped: Behavior[T]): Supervise[T]
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
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def transformMessages[Outer, Inner](interceptMessageClass: Class[Outer], behavior: Behavior[Inner], selector: Function[PFBuilder[Outer, Inner], PFBuilder[Outer, Inner]]): Behavior[Outer]
Transform the incoming messages by placing a funnel in front of the wrapped
Behavior
: 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.Transform the incoming messages by placing a funnel in front of the wrapped
Behavior
: 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) -> { return Behaviors.same(); }); Behavior<Number> n = Behaviors.transformMessages(Number.class, s, pf -> pf .match(BigInteger.class, i -> "BigInteger(" + i + ")") .match(BigDecimal.class, d -> "BigDecimal(" + d + ")") // drop all other kinds of Number );
- interceptMessageClass
Ensures that only messages of this class or a subclass thereof will be intercepted. Other message types (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior untouched.
- 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
Outer
type
- def unhandled[T]: Behavior[T]
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.
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def withMdc[T](interceptMessageClass: Class[T], staticMdc: Map[String, String], mdcForMessage: Function[T, Map[String, String]], behavior: Behavior[T]): Behavior[T]
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
ormdcForMessage
may be empty.- interceptMessageClass
Ensures that only messages of this class or a subclass thereof will be intercepted. Other message types (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior untouched.
- 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
- def withMdc[T](interceptMessageClass: Class[T], staticMdc: Map[String, String], behavior: Behavior[T]): Behavior[T]
Static MDC (Mapped Diagnostic Context)
Static MDC (Mapped Diagnostic Context)
- interceptMessageClass
Ensures that only messages of this class or a subclass thereof will be intercepted. Other message types (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior untouched.
- 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
- def withMdc[T](interceptMessageClass: Class[T], mdcForMessage: Function[T, Map[String, String]], behavior: Behavior[T]): Behavior[T]
Per message MDC (Mapped Diagnostic Context) logging.
Per message MDC (Mapped Diagnostic Context) logging.
- interceptMessageClass
Ensures that only messages of this class or a subclass thereof will be intercepted. Other message types (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior untouched.
- 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
- def withStash[T](capacity: Int, factory: Function[StashBuffer[T], Behavior[T]]): Behavior[T]
Support for stashing messages to unstash at a later time.
- def withTimers[T](factory: Function[TimerScheduler[T], Behavior[T]]): Behavior[T]
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