An Actor is given by the combination of a Behavior and a context in which this behavior is executed.
An Actor is given by the combination of a Behavior and a context in which this behavior is executed. As per the Actor Model an Actor can perform the following actions when processing a message:
In Akka the first capability is accessed by using the !
or tell
method
on an ActorRef, the second is provided by ActorContext#spawn
and the third is implicit in the signature of Behavior in that the next
behavior is always returned from the message processing logic.
An ActorContext
in addition provides access to the Actor’s own identity (“self
”),
the ActorSystem it is part of, methods for querying the list of child Actors it
created, access to DeathWatch and timed message scheduling.
An ActorRef is the identity or address of an Actor instance.
An ActorRef is the identity or address of an Actor instance. It is valid only during the Actor’s lifetime and allows messages to be sent to that Actor instance. Sending a message to an Actor that has terminated before receiving the message will lead to that message being discarded; such messages are delivered to the akka.actor.DeadLetter channel of the akka.event.EventStream on a best effort basis (i.e. this delivery is not reliable).
An ActorSystem is home to a hierarchy of Actors.
An ActorSystem is home to a hierarchy of Actors. It is created using
ActorSystem$ apply
from a Props object that describes the root
Actor of this hierarchy and which will create all other Actors beneath it.
A system also implements the ActorRef type, and sending a message to
the system directs that message to the root Actor.
The behavior of an actor defines how it reacts to the messages that it receives.
The behavior of an actor defines how it reacts to the messages that it receives. The message may either be of the type that the Actor declares and which is part of the ActorRef signature, or it may be a system Signal that expresses a lifecycle event of either this actor or one of its child actors.
Behaviors can be formulated in a number of different ways, either by creating a derived class or by employing factory methods like the ones in the ScalaDSL$ object.
All tracked effects must extend implement this type.
All tracked effects must extend implement this type. It is deliberately not sealed in order to allow extensions.
An ActorContext for testing purposes that records the effects performed on it and otherwise stubs them out like a StubbedActorContext.
Lifecycle signal that is fired when a direct child actor fails.
Lifecycle signal that is fired when a direct child actor fails. The child actor will be suspended until its fate has been decided. The decision is communicated by calling the Failed#decide method. If this is not done then the default behavior is to escalate the failure, which amounts to failing this actor with the same exception that the child actor failed with.
Lifecycle signal that is fired upon restart of the Actor after replacing the behavior with the fresh one (i.e.
Lifecycle signal that is fired upon restart of the Actor after replacing the behavior with the fresh one (i.e. this signal is received within the fresh replacement behavior).
Lifecycle signal that is fired upon restart of the Actor before replacing the behavior with the fresh one (i.e.
Lifecycle signal that is fired upon restart of the Actor before replacing the behavior with the fresh one (i.e. this signal is received within the behavior that failed).
Props describe how to dress up a Behavior so that it can become an Actor.
Props describe how to dress up a Behavior so that it can become an Actor.
This trait is used to hide the !
method from Java code.
System signals are notifications that are generated by the system and delivered to the Actor behavior in a reliable fashion (i.e.
System signals are notifications that are generated by the system and delivered to the Actor behavior in a reliable fashion (i.e. they are guaranteed to arrive in contrast to the at-most-once semantics of normal Actor messages).
An ActorContext for synchronous execution of a Behavior that
provides only stubs for the effects an Actor can perform and replaces
created child Actors by a synchronous Inbox (see Inbox.sync
).
An ActorContext for synchronous execution of a Behavior that
provides only stubs for the effects an Actor can perform and replaces
created child Actors by a synchronous Inbox (see Inbox.sync
).
See EffectfulActorContext for more advanced uses.
Lifecycle signal that is fired when an Actor that was watched has terminated.
Lifecycle signal that is fired when an Actor that was watched has terminated.
Watching is performed by invoking the
akka.typed.ActorContext watch
method. The DeathWatch service is
idempotent, meaning that registering twice has the same effect as registering
once. Registration does not need to happen before the Actor terminates, a
notification is guaranteed to arrive after both registration and termination
have occurred. Termination of a remote Actor can also be effected by declaring
the Actor’s home system as failed (e.g. as a result of being unreachable).
The ask-pattern implements the initiator side of a request–reply protocol.
The ask-pattern implements the initiator side of a request–reply protocol.
The party that asks may be within or without an Actor, since the
implementation will fabricate a (hidden) ActorRef that is bound to a
scala.concurrent.Promise. This ActorRef will need to be injected in the
message that is sent to the target Actor in order to function as a reply-to
address, therefore the argument to the ask / ?
operator is not the message itself but a function that given the reply-to
address will create the message.
case class Request(msg: String, replyTo: ActorRef[Reply]) case class Reply(msg: String) implicit val timeout = Timeout(3.seconds) val target: ActorRef[Request] = ... val f: Future[Reply] = target ? (Request("hello", _))
The parent of an actor decides upon the fate of a failed child actor by encapsulating its next behavior in one of the four wrappers defined within this class.
The parent of an actor decides upon the fate of a failed child actor by encapsulating its next behavior in one of the four wrappers defined within this class.
Failure responses have an associated precedence that ranks them, which is in descending importance:
Import the contents of this object to retrofit the typed APIs onto the untyped akka.actor.ActorSystem, akka.actor.ActorContext and akka.actor.ActorRef.
Lifecycle signal that is fired after this actor and all its child actors (transitively) have terminated.
Lifecycle signal that is fired after this actor and all its child actors (transitively) have terminated. The Terminated signal is only sent to registered watchers after this signal has been processed.
IMPORTANT NOTE: if the actor terminated by switching to the
Stopped
behavior then this signal will be ignored (i.e. the
Stopped behavior will do nothing in reaction to it).
Lifecycle signal that is fired upon creation of the Actor.
Lifecycle signal that is fired upon creation of the Actor. This will be the first message that the actor processes.
Props describe how to dress up a Behavior so that it can become an Actor.
The actor can register for a notification in case no message is received within a given time window, and the signal that is raised in this case is this one.
The actor can register for a notification in case no message is received within a given time window, and the signal that is raised in this case is this one. See also ActorContext#setReceiveTimeout.
This object holds several behavior factories and combinators that can be used to construct Behavior instances.