Interface ActorContext
-
- All Superinterfaces:
ActorRefFactory,ClassicActorContextProvider
- All Known Subinterfaces:
AbstractActor.ActorContext
public interface ActorContext extends ActorRefFactory, ClassicActorContextProvider
The actor context - the view of the actor cell from the actor. Exposes contextual information for the actor and the current message.There are several possibilities for creating actors (see
Propsfor details onprops):// Java or Scala context.actorOf(props, "name") context.actorOf(props) // Scala context.actorOf(Props[MyActor]) context.actorOf(Props(classOf[MyActor], arg1, arg2), "name") // Java getContext().actorOf(Props.create(MyActor.class)); getContext().actorOf(Props.create(MyActor.class, arg1, arg2), "name");Where no name is given explicitly, one will be automatically generated.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbecome(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> behavior)Changes the Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler.voidbecome(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> behavior, boolean discardOld)Changes the Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler.scala.Option<ActorRef>child(java.lang.String name)Get the child with the given name if it exists.scala.collection.immutable.Iterable<ActorRef>children()Returns all supervised children; this method returns a view (i.e.scala.concurrent.ExecutionContextExecutordispatcher()Returns the dispatcher (MessageDispatcher) that is used for this Actor.ActorRefparent()Returns the supervising parent ActorRef.Propsprops()Retrieve the Props which were used to create this actor.scala.concurrent.duration.DurationreceiveTimeout()Gets the current receive timeout.ActorRefself()The ActorRef representing this actorActorRefsender()Returns the sender 'ActorRef' of the current message.voidsetReceiveTimeout(scala.concurrent.duration.Duration timeout)Defines the inactivity timeout after which the sending of aReceiveTimeoutmessage is triggered.ActorSystemsystem()The system that the actor belongs to.voidunbecome()Reverts the Actor behavior to the previous one on the behavior stack.ActorRefunwatch(ActorRef subject)Unregisters this actor as Monitor for the provided ActorRef.ActorRefwatch(ActorRef subject)Registers this actor as a Monitor for the provided ActorRef.ActorRefwatchWith(ActorRef subject, java.lang.Object msg)Registers this actor as a Monitor for the provided ActorRef.voidwriteObject(java.io.ObjectOutputStream o)ActorContexts shouldn't be Serializable-
Methods inherited from interface akka.actor.ActorRefFactory
actorOf, actorOf, actorSelection, actorSelection, guardian, lookupRoot, provider, stop, systemImpl
-
Methods inherited from interface akka.actor.ClassicActorContextProvider
classicActorContext
-
-
-
-
Method Detail
-
become
void become(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> behavior)
Changes the Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler. Replaces the current behavior on the top of the behavior stack.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
become
void become(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> behavior, boolean discardOld)Changes the Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler. This method acts upon the behavior stack as follows:- if
discardOld = trueit will replace the top element (i.e. the current behavior) - ifdiscardOld = falseit will keep the current behavior and push the given one atopThe default of replacing the current behavior on the stack has been chosen to avoid memory leaks in case client code is written without consulting this documentation first (i.e. always pushing new behaviors and never issuing an
unbecome())*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
child
scala.Option<ActorRef> child(java.lang.String name)
Get the child with the given name if it exists.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
children
scala.collection.immutable.Iterable<ActorRef> children()
Returns all supervised children; this method returns a view (i.e. a lazy collection) onto the internal collection of children. Targeted lookups should be usingchildinstead for performance reasons:val badLookup = context.children find (_.path.name == "kid") // should better be expressed as: val goodLookup = context.child("kid")*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
dispatcher
scala.concurrent.ExecutionContextExecutor dispatcher()
Returns the dispatcher (MessageDispatcher) that is used for this Actor. Importing this member will place an implicit ExecutionContext in scope.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.- Specified by:
dispatcherin interfaceActorRefFactory
-
parent
ActorRef parent()
Returns the supervising parent ActorRef.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
props
Props props()
Retrieve the Props which were used to create this actor.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
receiveTimeout
scala.concurrent.duration.Duration receiveTimeout()
Gets the current receive timeout. When specified, the receive method should be able to handle aReceiveTimeoutmessage.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
self
ActorRef self()
The ActorRef representing this actorThis method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
sender
ActorRef sender()
Returns the sender 'ActorRef' of the current message.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
setReceiveTimeout
void setReceiveTimeout(scala.concurrent.duration.Duration timeout)
Defines the inactivity timeout after which the sending of aReceiveTimeoutmessage is triggered. When specified, the receive function should be able to handle aReceiveTimeoutmessage. 1 millisecond is the minimum supported timeout.Please note that the receive timeout might fire and enqueue the
ReceiveTimeoutmessage right after another message was enqueued; hence it is '''not guaranteed''' that upon reception of the receive timeout there must have been an idle period beforehand as configured via this method.Once set, the receive timeout stays in effect (i.e. continues firing repeatedly after inactivity periods). Pass in
Duration.Undefinedto switch off this feature.Messages marked with
NotInfluenceReceiveTimeoutwill not reset the timer. This can be useful whenReceiveTimeoutshould be fired by external inactivity but not influenced by internal activity, e.g. scheduled tick messages.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
system
ActorSystem system()
The system that the actor belongs to. Importing this member will place an implicit ActorSystem in scope.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
unbecome
void unbecome()
Reverts the Actor behavior to the previous one on the behavior stack.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
unwatch
ActorRef unwatch(ActorRef subject)
Unregisters this actor as Monitor for the provided ActorRef.- Returns:
- the provided ActorRef
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStageandFuturecallbacks.
-
watch
ActorRef watch(ActorRef subject)
Registers this actor as a Monitor for the provided ActorRef. This actor will receive a Terminated(subject) message when watched actor is terminated.watchis idempotent if it is not mixed withwatchWith.It will fail with an
IllegalStateExceptionif the same subject was watched before usingwatchWith. 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
CompletionStageandFuturecallbacks.- Returns:
- the provided ActorRef
-
watchWith
ActorRef watchWith(ActorRef subject, java.lang.Object msg)
Registers this actor as a Monitor for the provided ActorRef. This actor will receive the specified message when watched actor is terminated.watchWithis idempotent if it is called with the samemsgand not mixed withwatch.It will fail with an
IllegalStateExceptionif the same subject was watched before usingwatchorwatchWithwith 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
CompletionStageandFuturecallbacks.- Returns:
- the provided ActorRef
-
writeObject
void writeObject(java.io.ObjectOutputStream o)
ActorContexts shouldn't be Serializable
-
-