Interface ActorContextImpl<T>
- All Superinterfaces:
ActorContext<T>,ActorContext<T>,ClassicActorContextProvider,TypedActorContext<T>
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classstatic class -
Method Summary
Modifier and TypeMethodDescriptionvoid_currentActorThread_$eq(<any> x$1) void_logging_$eq(<any> x$1) void_messageAdapters_$eq(scala.collection.immutable.List<scala.Tuple2<Class<?>, scala.Function1<Object, T>>> x$1) void_timer_$eq(<any> x$1) asJava()Get thejavadslof thisActorContext.<Req,Res> void ask(Class<Res> resClass, RecipientRef<Req> target, Duration responseTimeout, Function<ActorRef<Res>, Req> createRequest, Function2<Res, Throwable, T> applyToResponse) Perform a single request-response message interaction with another actor, and transform the messages back to the protocol of this actor.<Req,Res> void ask(RecipientRef<Req> target, scala.Function1<ActorRef<Res>, Req> createRequest, scala.Function1<scala.util.Try<Res>, T> mapResponse, Timeout responseTimeout, scala.reflect.ClassTag<Res> classTag) Perform a single request-response message interaction with another actor, and transform the messages back to the protocol of this actor.<Req,Res> void askWithStatus(Class<Res> resClass, RecipientRef<Req> target, Duration responseTimeout, Function<ActorRef<StatusReply<Res>>, Req> createRequest, Function2<Res, Throwable, T> applyToResponse) The same asActorContext.<Req,Res>ask(java.lang.Class<Res>,org.apache.pekko.actor.typed.RecipientRef<Req>,java.time.Duration,org.apache.pekko.japi.function.Function<org.apache.pekko.actor.typed.ActorRef<Res>,Req>,org.apache.pekko.japi.function.Function2<Res,java.lang.Throwable,T>)but only for requests that result in a response of typepekko.pattern.StatusReply.<Req,Res> void askWithStatus(RecipientRef<Req> target, scala.Function1<ActorRef<StatusReply<Res>>, Req> createRequest, scala.Function1<scala.util.Try<Res>, T> mapResponse, Timeout responseTimeout, scala.reflect.ClassTag<Res> classTag) The same asActorContext.<Req,Res>ask(org.apache.pekko.actor.typed.RecipientRef<Req>,scala.Function1<org.apache.pekko.actor.typed.ActorRef<Res>,Req>,scala.Function1<scala.util.Try<Res>,T>,org.apache.pekko.util.Timeout,scala.reflect.ClassTag<Res>)but only for requests that result in a response of typepekko.pattern.StatusReply.asScala()Get thescaladslof thisActorContext.voidINTERNAL APIvoidINTERNAL APIvoidINTERNAL APIvoidclearMdc()INTERNAL APIDelegate message and signal's execution by givenpekko.actor.typed.BehaviorusingBehavior.interpretMessageorBehavior.interpretSignalThe named child Actor if it is alive.The list of child Actors created by this Actor during its lifetime that are still alive, in no particular order.scala.concurrent.ExecutionContextExecutorThis Actor’s execution context.org.slf4j.LoggergetLog()An actor specific logger.getSelf()The identity of this Actor, bound to the lifecycle of this Actor instance.TheActorSystemto which this Actor belongs.booleanbooleanhasTimer()INTERNAL API<U> ActorRef<U>internalMessageAdapter(Class<U> messageClass, scala.Function1<U, T> f) <U> ActorRef<U>internalSpawnMessageAdapter(scala.Function1<U, T> f, String name) INTERNAL API: Needed to make Scala 2.12 compiler happy if spawnMessageAdapter is overloaded for scaladsl/javadsl.org.slf4j.Loggerlog()An actor specific logger.<U> ActorRef<U>messageAdapter(Class<U> messageClass, Function<U, T> f) Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.<U> ActorRef<U>messageAdapter(scala.Function1<U, T> f, scala.reflect.ClassTag<U> evidence$1) Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.voidmessageAdapterRef_$eq(<any> x$1) INTERNAL APImkTimer()<Value> voidpipeToSelf(CompletionStage<Value> future, Function2<Value, Throwable, T> applyToResult) Sends the result of the givenCompletionStageto this Actor (“self”), after adapted it with the given function.<Value> voidpipeToSelf(scala.concurrent.Future<Value> future, scala.Function1<scala.util.Try<Value>, T> mapResult) Sends the result of the givenFutureto this Actor (“self”), after adapted it with the given function.<U> CancellablescheduleOnce(Duration 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.voidINTERNAL APIvoidsetLoggerName(Class<?> clazz) 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.voidsetLoggerName(String 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.voidsetReceiveTimeout(Duration duration, T msg) Schedule the sending of a notification in case no other message is received during the given period of time.<U> ActorRef<U>Create a child Actor from the givenpekko.actor.typed.Behaviorand with the given name.<U> ActorRef<U>spawnAnonymous(Behavior<U> behavior) Create a child Actor from the givenpekko.actor.typed.Behaviorunder a randomly chosen name.<U> ActorRef<U>spawnMessageAdapter(scala.Function1<U, T> f) INTERNAL API: SeespawnMessageAdapterwith name parameter<U> ActorRef<U>spawnMessageAdapter(scala.Function1<U, T> f, String name) INTERNAL API: It is currently internal because it's too easy to create resource leaks by spawning adapters without stopping them.timer()Methods inherited from interface org.apache.pekko.actor.typed.javadsl.ActorContext
cancelReceiveTimeout, spawn, spawnAnonymous, stop, unwatch, watch, watchWithMethods inherited from interface org.apache.pekko.actor.typed.scaladsl.ActorContext
cancelReceiveTimeout, child, children, currentBehavior, executionContext, onUnhandled, scheduleOnce, self, setReceiveTimeout, spawn, spawn$default$3, spawnAnonymous, spawnAnonymous$default$2, stop, system, unwatch, watch, watchWithMethods inherited from interface org.apache.pekko.actor.ClassicActorContextProvider
classicActorContext
-
Method Details
-
_logging_$eq
void _logging_$eq(<any> x$1) -
messageAdapterRef_$eq
void messageAdapterRef_$eq(<any> x$1) -
_messageAdapters_$eq
-
_timer_$eq
void _timer_$eq(<any> x$1) -
_currentActorThread_$eq
void _currentActorThread_$eq(<any> x$1) -
timer
TimerSchedulerCrossDslSupport<T> timer() -
mkTimer
TimerSchedulerCrossDslSupport<T> mkTimer() -
hasTimer
boolean hasTimer()Description copied from interface:ActorContextINTERNAL API- Specified by:
hasTimerin interfaceActorContext<T>
-
cancelAllTimers
void cancelAllTimers()Description copied from interface:ActorContextINTERNAL API- Specified by:
cancelAllTimersin interfaceActorContext<T>
-
asJava
ActorContext<T> asJava()Description copied from interface:TypedActorContextGet thejavadslof thisActorContext.- Specified by:
asJavain interfaceActorContext<T>- Specified by:
asJavain interfaceTypedActorContext<T>
-
asScala
ActorContext<T> asScala()Description copied from interface:TypedActorContextGet thescaladslof thisActorContext.- Specified by:
asScalain interfaceActorContext<T>- Specified by:
asScalain interfaceTypedActorContext<T>
-
getChild
Description copied from interface:ActorContextThe 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
CompletionStagecallbacks.- Specified by:
getChildin interfaceActorContext<T>
-
getChildren
Description copied from interface:ActorContextThe 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
CompletionStagecallbacks.- Specified by:
getChildrenin interfaceActorContext<T>
-
getExecutionContext
scala.concurrent.ExecutionContextExecutor getExecutionContext()Description copied from interface:ActorContextThis Actor’s execution context. It can be used to run asynchronous tasks likeFuturecombinators.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStagecallbacks.- Specified by:
getExecutionContextin interfaceActorContext<T>
-
getSelf
Description copied from interface:ActorContextThe 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 differentActorRef.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStagecallbacks.- Specified by:
getSelfin interfaceActorContext<T>
-
getSystem
ActorSystem<Void> getSystem()Description copied from interface:ActorContextTheActorSystemto 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
CompletionStagecallbacks.- Specified by:
getSystemin interfaceActorContext<T>
-
loggingContext
ActorContextImpl.LoggingContext loggingContext() -
log
org.slf4j.Logger log()Description copied from interface:ActorContextAn 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
Futurecallbacks.- Specified by:
login interfaceActorContext<T>
-
getLog
org.slf4j.Logger getLog()Description copied from interface:ActorContextAn 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
CompletionStagecallbacks.- Specified by:
getLogin interfaceActorContext<T>
-
setLoggerName
Description copied from interface:ActorContextReplace 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 "pekkoSource" 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
CompletionStagecallbacks.- Specified by:
setLoggerNamein interfaceActorContext<T>- Specified by:
setLoggerNamein interfaceActorContext<T>
-
setLoggerName
Description copied from interface:ActorContextReplace 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 "pekkoSource" 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
CompletionStagecallbacks.- Specified by:
setLoggerNamein interfaceActorContext<T>- Specified by:
setLoggerNamein interfaceActorContext<T>
-
hasCustomLoggerName
boolean hasCustomLoggerName() -
clearMdc
void clearMdc()Description copied from interface:ActorContextINTERNAL API- Specified by:
clearMdcin interfaceActorContext<T>
-
setReceiveTimeout
Description copied from interface:ActorContextSchedule 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. UsecancelReceiveTimeoutto 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
CompletionStagecallbacks.- Specified by:
setReceiveTimeoutin interfaceActorContext<T>
-
scheduleOnce
Description copied from interface:ActorContextSchedule 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 invokingpekko.actor.Cancellable#cancelon the returned handle.For scheduling messages to the actor itself, use
Behaviors.withTimersThis method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStagecallbacks.- Specified by:
scheduleOncein interfaceActorContext<T>
-
spawn
Description copied from interface:ActorContextCreate a child Actor from the givenpekko.actor.typed.Behaviorand 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
CompletionStagecallbacks.- Specified by:
spawnin interfaceActorContext<T>
-
spawnAnonymous
Description copied from interface:ActorContextCreate a child Actor from the givenpekko.actor.typed.Behaviorunder 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
CompletionStagecallbacks.- Specified by:
spawnAnonymousin interfaceActorContext<T>
-
delegate
Description copied from interface:ActorContextDelegate message and signal's execution by givenpekko.actor.typed.BehaviorusingBehavior.interpretMessageorBehavior.interpretSignalnote: if given
pekko.actor.typed.BehaviorresultingBehaviors.samethat will cause context switching to the given behavior and if result isBehaviors.unhandledthat will trigger thepekko.actor.typed.scaladsl.ActorContext.onUnhandledthen switching to the given behavior.- Specified by:
delegatein interfaceActorContext<T>- Specified by:
delegatein interfaceActorContext<T>
-
ask
<Req,Res> void ask(RecipientRef<Req> target, scala.Function1<ActorRef<Res>, Req> createRequest, scala.Function1<scala.util.Try<Res>, T> mapResponse, Timeout responseTimeout, scala.reflect.ClassTag<Res> classTag) Description copied from interface:ActorContextPerform 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 a
Failure(TimeoutException)to themapResponsefunction (this is the only "normal" way aFailureis passed to the function).For other messaging patterns with other actors, see
ActorContext.messageAdapter(scala.Function1<U, T>, scala.reflect.ClassTag<U>).This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
Futurecallbacks.- Specified by:
askin interfaceActorContext<T>createRequest- A function that creates a message for the other actor, containing the providedActorRef[Res]that the other actor can send a message back through.mapResponse- Transforms the response from thetargetinto a message this actor understands. 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.
-
askWithStatus
<Req,Res> void askWithStatus(RecipientRef<Req> target, scala.Function1<ActorRef<StatusReply<Res>>, Req> createRequest, scala.Function1<scala.util.Try<Res>, T> mapResponse, Timeout responseTimeout, scala.reflect.ClassTag<Res> classTag) Description copied from interface:ActorContextThe same asActorContext.<Req,Res>ask(org.apache.pekko.actor.typed.RecipientRef<Req>,scala.Function1<org.apache.pekko.actor.typed.ActorRef<Res>,Req>,scala.Function1<scala.util.Try<Res>,T>,org.apache.pekko.util.Timeout,scala.reflect.ClassTag<Res>)but only for requests that result in a response of typepekko.pattern.StatusReply. If the response is apekko.pattern.StatusReply.Successthe returned future is completed successfully with the wrapped response. If the status response is apekko.pattern.StatusReply.Errorthe returned future will be failed with the exception in the error (normally apekko.pattern.StatusReply.ErrorMessage).- Specified by:
askWithStatusin interfaceActorContext<T>
-
ask
<Req,Res> void ask(Class<Res> resClass, RecipientRef<Req> target, Duration responseTimeout, Function<ActorRef<Res>, Req> createRequest, Function2<Res, Throwable, T> applyToResponse) Description copied from interface:ActorContextPerform 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
TimeoutExceptionto theapplyToResponsefunction.For other messaging patterns with other actors, see
ActorContext.messageAdapter(java.lang.Class<U>, org.apache.pekko.japi.function.Function<U, T>).This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
CompletionStagecallbacks.- Specified by:
askin interfaceActorContext<T>createRequest- A function that creates a message for the other actor, containing the providedActorRef[Res]that the other actor can send a message back through.applyToResponse- Transforms the response from thetargetinto 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 apekko.actor.Status.Failureas response. The returned message of typeTis 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.
-
askWithStatus
<Req,Res> void askWithStatus(Class<Res> resClass, RecipientRef<Req> target, Duration responseTimeout, Function<ActorRef<StatusReply<Res>>, Req> createRequest, Function2<Res, Throwable, T> applyToResponse) Description copied from interface:ActorContextThe same asActorContext.<Req,Res>ask(java.lang.Class<Res>,org.apache.pekko.actor.typed.RecipientRef<Req>,java.time.Duration,org.apache.pekko.japi.function.Function<org.apache.pekko.actor.typed.ActorRef<Res>,Req>,org.apache.pekko.japi.function.Function2<Res,java.lang.Throwable,T>)but only for requests that result in a response of typepekko.pattern.StatusReply. If the response is apekko.pattern.StatusReply#successthe returned future is completed successfully with the wrapped response. If the status response is apekko.pattern.StatusReply#errorthe returned future will be failed with the exception in the error (normally apekko.pattern.StatusReply.ErrorMessage).- Specified by:
askWithStatusin interfaceActorContext<T>
-
pipeToSelf
<Value> void pipeToSelf(scala.concurrent.Future<Value> future, scala.Function1<scala.util.Try<Value>, T> mapResult) Description copied from interface:ActorContextSends the result of the givenFutureto 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
Futurecallbacks.- Specified by:
pipeToSelfin interfaceActorContext<T>
-
pipeToSelf
Description copied from interface:ActorContextSends the result of the givenCompletionStageto 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
CompletionStagecallbacks.- Specified by:
pipeToSelfin interfaceActorContext<T>
-
spawnMessageAdapter
Description copied from interface:ActorContextINTERNAL API: It is currently internal because it's too easy to create resource leaks by spawning adapters without stopping them.messageAdapteris the public API.Create a "lightweight" child actor that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor. You are strongly advised to cache these ActorRefs or to stop them when no longer needed.
The name of the child actor will be composed of a unique identifier starting with a dollar sign to which the given
nameargument is appended, with an inserted hyphen between these two parts. Therefore the givennameargument does not need to be unique within the scope of the parent actor.The function is applied inside the "parent" actor and can safely access state of the "parent".
- Specified by:
spawnMessageAdapterin interfaceActorContext<T>
-
spawnMessageAdapter
Description copied from interface:ActorContextINTERNAL API: SeespawnMessageAdapterwith name parameter- Specified by:
spawnMessageAdapterin interfaceActorContext<T>
-
internalSpawnMessageAdapter
INTERNAL API: Needed to make Scala 2.12 compiler happy if spawnMessageAdapter is overloaded for scaladsl/javadsl. Otherwise "ambiguous reference to overloaded definition" because Function is lambda. -
messageAdapter
Description copied from interface:ActorContextCreate 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.setupor constructor ofAbstractBehaviorbut 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 internalMapand 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
Futurecallbacks.- Specified by:
messageAdapterin interfaceActorContext<T>
-
messageAdapter
Description copied from interface:ActorContextCreate 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.setupor constructor ofAbstractBehaviorbut 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 internalMapand 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
CompletionStagecallbacks.- Specified by:
messageAdapterin interfaceActorContext<T>
-
internalMessageAdapter
-
messageAdapters
INTERNAL API -
setCurrentActorThread
void setCurrentActorThread()INTERNAL API- Specified by:
setCurrentActorThreadin interfaceActorContext<T>
-
clearCurrentActorThread
void clearCurrentActorThread()INTERNAL API- Specified by:
clearCurrentActorThreadin interfaceActorContext<T>
-
checkCurrentActorThread
void checkCurrentActorThread()INTERNAL API- Specified by:
checkCurrentActorThreadin interfaceActorContext<T>
-