trait ActorContext[T] extends TypedActorContext[T] with ClassicActorContextProvider
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:
- send a finite number of messages to other Actors it knows
- create a finite number of Actors
- designate the behavior for the next message
In Akka the first capability is accessed by using the 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 (“getSelf
”),
the ActorSystem it is part of, methods for querying the list of child Actors it
created, access to Terminated and timed message scheduling.
Not for user extension.
- Annotations
- @DoNotInherit()
- Source
- ActorContext.scala
- Alphabetic
- By Inheritance
- ActorContext
- ClassicActorContextProvider
- TypedActorContext
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def asJava: ActorContext[T]
Get the
javadsl
of thisActorContext
.Get the
javadsl
of thisActorContext
.- Definition Classes
- TypedActorContext
- abstract def asScala: scaladsl.ActorContext[T]
Get the
scaladsl
of thisActorContext
.Get the
scaladsl
of thisActorContext
.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- Definition Classes
- ActorContext → TypedActorContext
- abstract def ask[Req, Res](resClass: Class[Res], target: RecipientRef[Req], responseTimeout: Duration, createRequest: Function[ActorRef[Res], Req], applyToResponse: Function2[Res, Throwable, T]): Unit
Perform a single request-response message interaction with another actor, and transform the messages back to the protocol of this actor.
Perform a single request-response message interaction with another actor, and transform the messages back to the protocol of this actor.
The interaction has a timeout (to avoid a resource leak). If the timeout hits without any response it will be passed as an java.util.concurrent.TimeoutException to the
applyToResponse
function.For other messaging patterns with other actors, see ActorContext#messageAdapter.
This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- Req
The request protocol, what the other actor accepts
- Res
The response protocol, what the other actor sends back
- createRequest
A function that creates a message for the other actor, containing the provided
ActorRef[Res]
that the other actor can send a message back through.- applyToResponse
Transforms the response from the
target
into a message this actor understands. Will be invoked with either the response message or an AskTimeoutException failed or potentially another exception if the remote actor is classic and sent a akka.actor.Status.Failure as response. The returned message of typeT
is then fed into this actor as a message. Should be a pure function but is executed inside the actor when the response arrives so can safely touch the actor internals. If this function throws an exception it is just as if the normal message receiving logic would throw.
- abstract def askWithStatus[Req, Res](resClass: Class[Res], target: RecipientRef[Req], responseTimeout: Duration, createRequest: Function[ActorRef[StatusReply[Res]], Req], applyToResponse: Function2[Res, Throwable, T]): Unit
The same as ask but only for requests that result in a response of type akka.pattern.StatusReply.
The same as ask but only for requests that result in a response of type akka.pattern.StatusReply. If the response is a akka.pattern.StatusReply#success the returned future is completed successfully with the wrapped response. If the status response is a akka.pattern.StatusReply#error the returned future will be failed with the exception in the error (normally a akka.pattern.StatusReply.ErrorMessage).
- abstract def cancelReceiveTimeout(): Unit
Cancel the sending of receive timeout notifications.
Cancel the sending of receive timeout notifications.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def delegate(delegator: Behavior[T], msg: T): Behavior[T]
Delegate message and signal's execution by given akka.actor.typed.Behavior using Behavior.interpretMessage or Behavior.interpretSignal
Delegate message and signal's execution by given akka.actor.typed.Behavior using Behavior.interpretMessage or Behavior.interpretSignal
note: if given akka.actor.typed.Behavior resulting Behaviors.same that will cause context switching to the given behavior and if result is Behaviors.unhandled that will trigger the akka.actor.typed.scaladsl.ActorContext.onUnhandled then switching to the given behavior.
- abstract def getChild(name: String): Optional[ActorRef[Void]]
The named child Actor if it is alive.
The named child Actor if it is alive.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def getChildren: List[ActorRef[Void]]
The list of child Actors created by this Actor during its lifetime that are still alive, in no particular order.
The list of child Actors created by this Actor during its lifetime that are still alive, in no particular order.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def getExecutionContext: ExecutionContextExecutor
This Actor’s execution context.
This Actor’s execution context. It can be used to run asynchronous tasks like scala.concurrent.Future combinators.
This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def getLog: Logger
An actor specific logger.
An actor specific logger.
The logger name will be an estimated source class for the actor which is calculated when the logger is first used (the logger is lazily created upon first use). If this yields the wrong class or another class is preferred this can be changed with
setLoggerName
.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def getSelf: ActorRef[T]
The identity of this Actor, bound to the lifecycle of this Actor instance.
The identity of this Actor, bound to the lifecycle of this Actor instance. An Actor with the same name that lives before or after this instance will have a different ActorRef.
This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def getSystem: ActorSystem[Void]
The ActorSystem to which this Actor belongs.
The ActorSystem to which this Actor belongs.
This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def messageAdapter[U](messageClass: Class[U], f: Function[U, T]): ActorRef[U]
Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.
Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.
You can register several message adapters for different message classes. It's only possible to have one message adapter per message class to make sure that the number of adapters are not growing unbounded if registered repeatedly. That also means that a registered adapter will replace an existing adapter for the same message class.
A message adapter will be used if the message class matches the given class or is a subclass thereof. The registered adapters are tried in reverse order of their registration order, i.e. the last registered first.
A message adapter (and the returned
ActorRef
) has the same lifecycle as this actor. It's recommended to register the adapters in a top levelBehaviors.setup
or constructor ofAbstractBehavior
but it's possible to register them later also if needed. Message adapters don't have to be stopped since they consume no resources other than an entry in an internalMap
and the number of adapters are bounded since it's only possible to have one per message class.The function is running in this actor and can safely access state of it.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def pipeToSelf[Value](future: CompletionStage[Value], applyToResult: Function2[Value, Throwable, T]): Unit
Sends the result of the given
CompletionStage
to this Actor (“self
”), after adapted it with the given function.Sends the result of the given
CompletionStage
to this Actor (“self
”), after adapted it with the given function.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def scheduleOnce[U](delay: Duration, target: ActorRef[U], msg: U): Cancellable
Schedule the sending of the given message to the given target Actor after the given time period has elapsed.
Schedule the sending of the given message to the given target Actor after the given time period has elapsed. The scheduled action can be cancelled by invoking akka.actor.Cancellable#cancel on the returned handle.
For scheduling messages to the actor itself, use Behaviors.withTimers
This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def setLoggerName(clazz: Class[_]): Unit
Replace the current logger (or initialize a new logger if the logger was not touched before) with one that has ghe given class name as logger name.
Replace the current logger (or initialize a new logger if the logger was not touched before) with one that has ghe given class name as logger name. Logger source MDC entry "akkaSource" will be the actor path.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def setLoggerName(name: String): Unit
Replace the current logger (or initialize a new logger if the logger was not touched before) with one that has ghe given name as logger name.
Replace the current logger (or initialize a new logger if the logger was not touched before) with one that has ghe given name as logger name. Logger source MDC entry "akkaSource" will be the actor path.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def setReceiveTimeout(timeout: Duration, msg: T): Unit
Schedule the sending of a notification in case no other message is received during the given period of time.
Schedule the sending of a notification in case no other message is received during the given period of time. The timeout starts anew with each received message. Use
cancelReceiveTimeout
to switch off this mechanism.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def spawn[U](behavior: Behavior[U], name: String, props: Props): ActorRef[U]
Create a child Actor from the given akka.actor.typed.Behavior and with the given name.
Create a child Actor from the given akka.actor.typed.Behavior and with the given name.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def spawn[U](behavior: Behavior[U], name: String): ActorRef[U]
Create a child Actor from the given akka.actor.typed.Behavior and with the given name.
Create a child Actor from the given akka.actor.typed.Behavior and with the given name.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def spawnAnonymous[U](behavior: Behavior[U], props: Props): ActorRef[U]
Create a child Actor from the given akka.actor.typed.Behavior under a randomly chosen name.
Create a child Actor from the given akka.actor.typed.Behavior under a randomly chosen name. It is good practice to name Actors wherever practical.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def spawnAnonymous[U](behavior: Behavior[U]): ActorRef[U]
Create a child Actor from the given akka.actor.typed.Behavior under a randomly chosen name.
Create a child Actor from the given akka.actor.typed.Behavior under a randomly chosen name. It is good practice to name Actors wherever practical.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def stop[U](child: ActorRef[U]): Unit
Force the child Actor under the given name to terminate after it finishes processing its current message.
Force the child Actor under the given name to terminate after it finishes processing its current message. Nothing happens if the ActorRef is a child that is already stopped.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- Exceptions thrown
IllegalArgumentException
if the given actor ref is not a direct child of this actor
- abstract def unwatch[U](other: ActorRef[U]): Unit
Revoke the registration established by
watch
.Revoke the registration established by
watch
. A Terminated notification will not subsequently be received for the referenced Actor.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def watch[U](other: ActorRef[U]): Unit
Register for Terminated notification once the Actor identified by the given ActorRef terminates.
Register for Terminated notification once the Actor identified by the given ActorRef terminates. This message is also sent when the watched actor is on a node that has been removed from the cluster when using Akka Cluster.
watch
is idempotent if it is not mixed withwatchWith
.It will fail with an IllegalStateException if the same subject was watched before using
watchWith
. To clear the termination message, unwatch first.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
- abstract def watchWith[U](other: ActorRef[U], msg: T): Unit
Register for termination notification with a custom message once the Actor identified by the given ActorRef terminates.
Register for termination notification with a custom message once the Actor identified by the given ActorRef terminates. This message is also sent when the watched actor is on a node that has been removed from the cluster when using Akka Cluster.
watchWith
is idempotent if it is called with the samemsg
and not mixed withwatch
.It will fail with an IllegalStateException if the same subject was watched before using
watch
orwatchWith
with another termination message. To change the termination message, unwatch first.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as java.util.concurrent.CompletionStage callbacks.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toany2stringadd[ActorContext[T]] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
- def ->[B](y: B): (ActorContext[T], B)
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toArrowAssoc[ActorContext[T]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
- 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 ensuring(cond: (ActorContext[T]) => Boolean, msg: => Any): ActorContext[T]
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toEnsuring[ActorContext[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: (ActorContext[T]) => Boolean): ActorContext[T]
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toEnsuring[ActorContext[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean, msg: => Any): ActorContext[T]
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toEnsuring[ActorContext[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean): ActorContext[T]
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toEnsuring[ActorContext[T]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- 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()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- 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()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
- def formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toStringFormat[ActorContext[T]] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.12.16) Use
formatString.format(value)
instead ofvalue.formatted(formatString)
, or use thef""
string interpolator. In Java 15 and later,formatted
resolves to the new method in String which has reversed parameters.
- def →[B](y: B): (ActorContext[T], B)
- Implicit
- This member is added by an implicit conversion from ActorContext[T] toArrowAssoc[ActorContext[T]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use
->
instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.