Class EffectfulActorContext<T>

    • Constructor Detail

      • EffectfulActorContext

        public EffectfulActorContext​(ActorPath path,
                                     scala.Function0<Behavior<T>> currentBehaviorProvider)
    • Method Detail

      • effectQueue

        public java.util.concurrent.ConcurrentLinkedQueue<Effect> effectQueue()
      • messageAdapter

        public <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.

        Parameters:
        f - (undocumented)
        evidence$1 - (undocumented)
        Returns:
        (undocumented)
      • messageAdapter

        public <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.

        Parameters:
        messageClass - (undocumented)
        f - (undocumented)
        Returns:
        (undocumented)
      • scheduleOnce

        public <U> Cancellable scheduleOnce​(scala.concurrent.duration.FiniteDuration delay,
                                            ActorRef<U> target,
                                            U message)
        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.

        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:
        scheduleOnce in interface ActorContext<T>
        Overrides:
        scheduleOnce in class StubbedActorContext<T>
        Parameters:
        delay - (undocumented)
        target - (undocumented)
        message - (undocumented)
        Returns:
        (undocumented)
      • setReceiveTimeout

        public void setReceiveTimeout​(scala.concurrent.duration.FiniteDuration d,
                                      T message)
        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 Future callbacks.

        Specified by:
        setReceiveTimeout in interface ActorContext<T>
        Overrides:
        setReceiveTimeout in class StubbedActorContext<T>
        Parameters:
        d - (undocumented)
        message - (undocumented)
      • spawn

        public <U> ActorRef<U> spawn​(Behavior<U> behavior,
                                     java.lang.String name,
                                     Props props)
        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>
        Specified by:
        spawn in interface ActorContext<T>
        Overrides:
        spawn in class StubbedActorContext<T>
        Parameters:
        behavior - (undocumented)
        name - (undocumented)
        props - (undocumented)
        Returns:
        (undocumented)
      • spawn$default$3

        public <U> Props spawn$default$3()
        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 Future callbacks.

        Specified by:
        spawn$default$3 in interface ActorContext<T>
        Overrides:
        spawn$default$3 in class StubbedActorContext<T>
        Returns:
        (undocumented)
      • spawnAnonymous

        public <U> ActorRef<U> spawnAnonymous​(Behavior<U> behavior,
                                              Props props)
        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>
        Specified by:
        spawnAnonymous in interface ActorContext<T>
        Overrides:
        spawnAnonymous in class StubbedActorContext<T>
        Parameters:
        behavior - (undocumented)
        props - (undocumented)
        Returns:
        (undocumented)
      • spawnMessageAdapter

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

        public <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".

        Parameters:
        f - (undocumented)
        name - (undocumented)
        Returns:
        (undocumented)
      • stop

        public <U> void stop​(ActorRef<U> child)
        Description copied from class: StubbedActorContext
        Do not actually stop the child inbox, only simulate the liveness check. Removal is asynchronous, explicit removeInbox is needed from outside afterwards.
        Specified by:
        stop in interface ActorContext<T>
        Specified by:
        stop in interface ActorContext<T>
        Overrides:
        stop in class StubbedActorContext<T>
        Parameters:
        child - (undocumented)
      • unwatch

        public <U> void unwatch​(ActorRef<U> other)
        Description copied from interface: ActorContext
        Revoke the registration established by watch. A Terminated notification will not subsequently be received for the referenced Actor.

        *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:
        unwatch in interface ActorContext<T>
        Specified by:
        unwatch in interface ActorContext<T>
        Overrides:
        unwatch in class StubbedActorContext<T>
        Parameters:
        other - (undocumented)
      • watch

        public <U> void watch​(ActorRef<U> other)
        Description copied from interface: ActorContext
        Register for Terminated notification once the Actor identified by the given ActorRef terminates. This message is also sent when the watched actor is on a node that has been removed from the cluster when using akka-cluster or has been marked unreachable when using akka-remote directly.

        watch is idempotent if it is not mixed with watchWith.

        It will fail with an IllegalStateException if the same subject was watched before using watchWith. 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 CompletionStage callbacks.

        Specified by:
        watch in interface ActorContext<T>
        Specified by:
        watch in interface ActorContext<T>
        Overrides:
        watch in class StubbedActorContext<T>
        Parameters:
        other - (undocumented)
      • watchWith

        public <U> void watchWith​(ActorRef<U> other,
                                  T message)
        Description copied from interface: ActorContext
        Register for termination notification with a custom message once the Actor identified by the given ActorRef terminates. This message is also sent when the watched actor is on a node that has been removed from the cluster when using akka-cluster or has been marked unreachable when using akka-remote directly.

        watchWith is idempotent if it is called with the same msg and not mixed with watch.

        It will fail with an IllegalStateException if the same subject was watched before using watch or watchWith with 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 CompletionStage callbacks.

        Specified by:
        watchWith in interface ActorContext<T>
        Specified by:
        watchWith in interface ActorContext<T>
        Overrides:
        watchWith in class StubbedActorContext<T>
        Parameters:
        other - (undocumented)
        message - (undocumented)