Interface ActorContextImpl<T>

    • Method Detail

      • _messageAdapters_$eq

        void _messageAdapters_$eq​(scala.collection.immutable.List<scala.Tuple2<java.lang.Class<?>,​scala.Function1<java.lang.Object,​T>>> x$1)
      • 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>
        Parameters:
        target - (undocumented)
        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.

        responseTimeout - (undocumented)
        classTag - (undocumented)
      • ask

        <Req,​Res> void ask​(java.lang.Class<Res> resClass,
                                 RecipientRef<Req> target,
                                 java.time.Duration responseTimeout,
                                 java.util.function.Function<ActorRef<Res>,​Req> createRequest,
                                 java.util.function.BiFunction<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>, java.util.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>
        Parameters:
        resClass - (undocumented)
        target - (undocumented)
        responseTimeout - (undocumented)
        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 untyped and sent a 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.

      • 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>
        Parameters:
        name - (undocumented)
        Returns:
        (undocumented)
      • 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>
        Returns:
        (undocumented)
      • 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>
        Returns:
        (undocumented)
      • getLog

        Logger getLog()
        Description copied from interface: ActorContext
        An actor specific logger

        *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>
        Returns:
        (undocumented)
      • 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>
        Returns:
        (undocumented)
      • 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>
        Returns:
        (undocumented)
      • hasTimer

        boolean hasTimer()
        Description copied from interface: ActorContext
        INTERNAL API
        Specified by:
        hasTimer in interface ActorContext<T>
        Returns:
        (undocumented)
      • internalMessageAdapter

        <U> ActorRef<U> internalMessageAdapter​(java.lang.Class<U> messageClass,
                                               scala.Function1<U,​T> f)
      • 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.
        Parameters:
        f - (undocumented)
        name - (undocumented)
        Returns:
        (undocumented)
      • 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>
        Parameters:
        f - (undocumented)
        evidence$1 - (undocumented)
        Returns:
        (undocumented)
      • messageAdapter

        <U> ActorRef<U> messageAdapter​(java.lang.Class<U> messageClass,
                                       java.util.function.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>
        Parameters:
        messageClass - (undocumented)
        f - (undocumented)
        Returns:
        (undocumented)
      • messageAdapterRef_$eq

        void messageAdapterRef_$eq​(OptionVal<ActorRef<java.lang.Object>> x$1)
      • messageAdapters

        scala.collection.immutable.List<scala.Tuple2<java.lang.Class<?>,​scala.Function1<java.lang.Object,​T>>> messageAdapters()
        INTERNAL API
        Returns:
        (undocumented)
      • 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>
        Parameters:
        future - (undocumented)
        mapResult - (undocumented)
      • pipeToSelf

        <Value> void pipeToSelf​(java.util.concurrent.CompletionStage<Value> future,
                                java.util.function.BiFunction<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>
        Parameters:
        future - (undocumented)
        applyToResult - (undocumented)
      • 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 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>
        Parameters:
        delay - (undocumented)
        target - (undocumented)
        msg - (undocumented)
        Returns:
        (undocumented)
      • setReceiveTimeout

        void setReceiveTimeout​(java.time.Duration d,
                               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>
        Parameters:
        d - (undocumented)
        msg - (undocumented)
      • spawn

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

        <U> ActorRef<U> spawnAnonymous​(Behavior<U> behavior)
        Description copied from interface: ActorContext
        Create a child Actor from the given 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>
        Parameters:
        behavior - (undocumented)
        Returns:
        (undocumented)
      • 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>
        Parameters:
        f - (undocumented)
        name - (undocumented)
        Returns:
        (undocumented)
      • spawnMessageAdapter

        <U> ActorRef<U> spawnMessageAdapter​(scala.Function1<U,​T> f)
        Description copied from interface: ActorContext
        INTERNAL API: See spawnMessageAdapter with name parameter
        Specified by:
        spawnMessageAdapter in interface ActorContext<T>
        Parameters:
        f - (undocumented)
        Returns:
        (undocumented)