public interface ActorContext<T>
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 !
or tell
method
on an ActorRef
, the second is provided by spawn(akka.typed.Behavior<U>, java.lang.String, akka.typed.DeploymentConfig)
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.
Modifier and Type | Method and Description |
---|---|
void |
cancelReceiveTimeout()
Cancel the sending of receive timeout notifications.
|
scala.Option<ActorRef<scala.runtime.Nothing$>> |
child(java.lang.String name)
The named child Actor if it is alive.
|
scala.collection.Iterable<ActorRef<scala.runtime.Nothing$>> |
children()
The list of child Actors created by this Actor during its lifetime that
are still alive, in no particular order.
|
scala.concurrent.ExecutionContextExecutor |
executionContext()
This Actor’s execution context.
|
int |
mailboxCapacity()
Return the mailbox capacity that was configured by the parent for this actor.
|
<U> Cancellable |
schedule(scala.concurrent.duration.FiniteDuration delay,
ActorRef<U> target,
U msg)
Schedule the sending of the given message to the given target Actor after
the given time period has elapsed.
|
ActorRef<T> |
self()
The identity of this Actor, bound to the lifecycle of this Actor instance.
|
void |
setReceiveTimeout(scala.concurrent.duration.FiniteDuration d,
T msg)
Schedule the sending of a notification in case no other
message is received during the given period of time.
|
<U> ActorRef<U> |
spawn(Behavior<U> behavior,
java.lang.String name,
DeploymentConfig deployment)
Create a child Actor from the given
Props and with the given name. |
<U> ActorRef<U> |
spawnAdapter(scala.Function1<U,T> f)
Create a child actor that will wrap messages such that other Actor’s
protocols can be ingested by this Actor.
|
<U> ActorRef<U> |
spawnAnonymous(Behavior<U> behavior,
DeploymentConfig deployment)
Create a child Actor from the given
Props under a randomly chosen name. |
boolean |
stop(ActorRef<scala.runtime.Nothing$> child)
Force the child Actor under the given name to terminate after it finishes
processing its current message.
|
ActorSystem<scala.runtime.Nothing$> |
system()
The
ActorSystem to which this Actor belongs. |
<U> ActorRef<U> |
unwatch(ActorRef<U> other)
Revoke the registration established by
watch . |
<U> ActorRef<U> |
watch(ActorRef<U> other)
Register for
Terminated notification once the Actor identified by the
given ActorRef terminates. |
ActorRef<T> self()
ActorRef
.int mailboxCapacity()
ActorSystem<scala.runtime.Nothing$> system()
ActorSystem
to which this Actor belongs.scala.collection.Iterable<ActorRef<scala.runtime.Nothing$>> children()
scala.Option<ActorRef<scala.runtime.Nothing$>> child(java.lang.String name)
name
- (undocumented)<U> ActorRef<U> spawnAnonymous(Behavior<U> behavior, DeploymentConfig deployment)
Props
under a randomly chosen name.
It is good practice to name Actors wherever practical.behavior
- (undocumented)deployment
- (undocumented)<U> ActorRef<U> spawn(Behavior<U> behavior, java.lang.String name, DeploymentConfig deployment)
Props
and with the given name.behavior
- (undocumented)name
- (undocumented)deployment
- (undocumented)boolean stop(ActorRef<scala.runtime.Nothing$> child)
child
- (undocumented)ActorRef
points to a current child Actor<U> ActorRef<U> watch(ActorRef<U> other)
Terminated
notification once the Actor identified by the
given ActorRef
terminates. This notification is also generated when the
ActorSystem
to which the referenced Actor belongs is declared as
failed (e.g. in reaction to being unreachable).other
- (undocumented)<U> ActorRef<U> unwatch(ActorRef<U> other)
watch
. A Terminated
notification will not subsequently be received for the referenced Actor.other
- (undocumented)void setReceiveTimeout(scala.concurrent.duration.FiniteDuration d, T msg)
Duration.Undefined
to switch off this
mechanism.d
- (undocumented)msg
- (undocumented)void cancelReceiveTimeout()
<U> Cancellable schedule(scala.concurrent.duration.FiniteDuration delay, ActorRef<U> target, U msg)
Cancellable
cancel
on the returned
handle.delay
- (undocumented)target
- (undocumented)msg
- (undocumented)scala.concurrent.ExecutionContextExecutor executionContext()
Future
combinators.<U> ActorRef<U> spawnAdapter(scala.Function1<U,T> f)
f
- (undocumented)