Interface ActorContextImpl<T>

    • Method Detail

      • _logging_$eq

        void _logging_$eq​(<any> x$1)
      • messageAdapterRef_$eq

        void messageAdapterRef_$eq​(<any> x$1)
      • _messageAdapters_$eq

        void _messageAdapters_$eq​(scala.collection.immutable.List<scala.Tuple2<java.lang.Class<?>,​scala.Function1<java.lang.Object,​T>>> x$1)
      • _timer_$eq

        void _timer_$eq​(<any> x$1)
      • _currentActorThread_$eq

        void _currentActorThread_$eq​(<any> x$1)
      • getChild

        java.util.Optional<ActorRef<java.lang.Void>> getChild​(java.lang.String name)
        Description copied from interface: ActorContext
        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 CompletionStage callbacks.

        Specified by:
        getChild in interface ActorContext<T>
      • getChildren

        java.util.List<ActorRef<java.lang.Void>> getChildren()
        Description copied from interface: ActorContext
        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 CompletionStage callbacks.

        Specified by:
        getChildren in interface ActorContext<T>
      • getExecutionContext

        scala.concurrent.ExecutionContextExecutor getExecutionContext()
        Description copied from interface: ActorContext
        This Actor&rsquo;s execution context. It can be used to run asynchronous tasks like Future combinators.

        This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as CompletionStage callbacks.

        Specified by:
        getExecutionContext in interface ActorContext<T>
      • getSelf

        ActorRef<T> getSelf()
        Description copied from interface: ActorContext
        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 CompletionStage callbacks.

        Specified by:
        getSelf in interface ActorContext<T>
      • getSystem

        ActorSystem<java.lang.Void> getSystem()
        Description copied from interface: ActorContext
        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 CompletionStage callbacks.

        Specified by:
        getSystem in interface ActorContext<T>
      • log

        org.slf4j.Logger log()
        Description copied from interface: ActorContext
        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 Future callbacks.

        Specified by:
        log in interface ActorContext<T>
      • getLog

        org.slf4j.Logger getLog()
        Description copied from interface: ActorContext
        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 CompletionStage callbacks.

        Specified by:
        getLog in interface ActorContext<T>
      • setLoggerName

        void setLoggerName​(java.lang.String name)
        Description copied from interface: ActorContext
        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 "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 CompletionStage callbacks.

        Specified by:
        setLoggerName in interface ActorContext<T>
        Specified by:
        setLoggerName in interface ActorContext<T>
      • setLoggerName

        void setLoggerName​(java.lang.Class<?> clazz)
        Description copied from interface: ActorContext
        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 "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 CompletionStage callbacks.

        Specified by:
        setLoggerName in interface ActorContext<T>
        Specified by:
        setLoggerName in interface ActorContext<T>
      • hasCustomLoggerName

        boolean hasCustomLoggerName()
      • setReceiveTimeout

        void setReceiveTimeout​(java.time.Duration duration,
                               T msg)
        Description copied from interface: ActorContext
        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 CompletionStage callbacks.

        Specified by:
        setReceiveTimeout in interface ActorContext<T>
      • scheduleOnce

        <U> Cancellable scheduleOnce​(java.time.Duration delay,
                                     ActorRef<U> target,
                                     U msg)
        Description copied from interface: ActorContext
        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 pekko.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 CompletionStage callbacks.

        Specified by:
        scheduleOnce in interface ActorContext<T>
      • spawn

        <U> ActorRef<U> spawn​(Behavior<U> behavior,
                              java.lang.String name)
        Description copied from interface: ActorContext
        Create a child Actor from the given pekko.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 CompletionStage callbacks.

        Specified by:
        spawn in interface ActorContext<T>
      • spawnAnonymous

        <U> ActorRef<U> spawnAnonymous​(Behavior<U> behavior)
        Description copied from interface: ActorContext
        Create a child Actor from the given pekko.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 CompletionStage callbacks.

        Specified by:
        spawnAnonymous in interface ActorContext<T>
      • delegate

        Behavior<T> delegate​(Behavior<T> delegator,
                             T msg)
        Description copied from interface: ActorContext
        Delegate message and signal's execution by given pekko.actor.typed.Behavior using Behavior.interpretMessage or Behavior.interpretSignal

        note: if given pekko.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 pekko.actor.typed.scaladsl.ActorContext.onUnhandled then switching to the given behavior.

        Specified by:
        delegate in interface ActorContext<T>
        Specified by:
        delegate in interface ActorContext<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: ActorContext
        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 a Failure(TimeoutException) to the mapResponse function (this is the only "normal" way a Failure is 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 Future callbacks.

        Specified by:
        ask in interface ActorContext<T>
        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.
        mapResponse - Transforms the response from the target into 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.

      • ask

        <Req,​Res> void ask​(java.lang.Class<Res> resClass,
                                 RecipientRef<Req> target,
                                 java.time.Duration responseTimeout,
                                 Function<ActorRef<Res>,​Req> createRequest,
                                 Function2<Res,​java.lang.Throwable,​T> applyToResponse)
        Description copied from interface: ActorContext
        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 TimeoutException to the applyToResponse function.

        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 CompletionStage callbacks.

        Specified by:
        ask in interface ActorContext<T>
        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 pekko.actor.Status.Failure as response. The returned message of type T 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.

      • pipeToSelf

        <Value> void pipeToSelf​(scala.concurrent.Future<Value> future,
                                scala.Function1<scala.util.Try<Value>,​T> mapResult)
        Description copied from interface: ActorContext
        Sends the result of the given Future to this Actor (&ldquo;self&rdquo;), 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 Future callbacks.

        Specified by:
        pipeToSelf in interface ActorContext<T>
      • pipeToSelf

        <Value> void pipeToSelf​(java.util.concurrent.CompletionStage<Value> future,
                                Function2<Value,​java.lang.Throwable,​T> applyToResult)
        Description copied from interface: ActorContext
        Sends the result of the given CompletionStage to this Actor (&ldquo;self&rdquo;), 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 CompletionStage callbacks.

        Specified by:
        pipeToSelf in interface ActorContext<T>
      • spawnMessageAdapter

        <U> ActorRef<U> spawnMessageAdapter​(scala.Function1<U,​T> f,
                                            java.lang.String name)
        Description copied from interface: ActorContext
        INTERNAL API: It is currently internal because it's too easy to create resource leaks by spawning adapters without stopping them. messageAdapter is the public API.

        Create a "lightweight" child actor that will convert or wrap messages such that other Actor&rsquo;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 name argument is appended, with an inserted hyphen between these two parts. Therefore the given name argument 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:
        spawnMessageAdapter in interface ActorContext<T>
      • internalSpawnMessageAdapter

        <U> ActorRef<U> internalSpawnMessageAdapter​(scala.Function1<U,​T> f,
                                                    java.lang.String name)
        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

        <U> ActorRef<U> messageAdapter​(scala.Function1<U,​T> f,
                                       scala.reflect.ClassTag<U> evidence$1)
        Description copied from interface: ActorContext
        Create a message adapter that will convert or wrap messages such that other Actor&rsquo;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 level Behaviors.setup or constructor of AbstractBehavior 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 internal Map 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 Future callbacks.

        Specified by:
        messageAdapter in interface ActorContext<T>
      • messageAdapter

        <U> ActorRef<U> messageAdapter​(java.lang.Class<U> messageClass,
                                       Function<U,​T> f)
        Description copied from interface: ActorContext
        Create a message adapter that will convert or wrap messages such that other Actor&rsquo;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 level Behaviors.setup or constructor of AbstractBehavior 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 internal Map 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 CompletionStage callbacks.

        Specified by:
        messageAdapter in interface ActorContext<T>
      • internalMessageAdapter

        <U> ActorRef<U> internalMessageAdapter​(java.lang.Class<U> messageClass,
                                               scala.Function1<U,​T> f)
      • messageAdapters

        scala.collection.immutable.List<scala.Tuple2<java.lang.Class<?>,​scala.Function1<java.lang.Object,​T>>> messageAdapters()
        INTERNAL API