Class ClusterClient

  • All Implemented Interfaces:
    Actor, ActorLogging

    public final class ClusterClient
    extends java.lang.Object
    implements Actor, ActorLogging
    This actor is intended to be used on an external node that is not member of the cluster. It acts like a gateway for sending messages to actors somewhere in the cluster. From the initial contact points it will establish a connection to a ClusterReceptionist somewhere in the cluster. It will monitor the connection to the receptionist and establish a new connection if the link goes down. When looking for a new receptionist it uses fresh contact points retrieved from previous establishment, or periodically refreshed contacts, i.e. not necessarily the initial contact points.

    You can send messages via the ClusterClient to any actor in the cluster that is registered in the ClusterReceptionist. Messages are wrapped in ClusterClient.Send, ClusterClient.SendToAll or ClusterClient.Publish.

    1. ClusterClient.Send - The message will be delivered to one recipient with a matching path, if any such exists. If several entries match the path the message will be delivered to one random destination. The sender of the message can specify that local affinity is preferred, i.e. the message is sent to an actor in the same local actor system as the used receptionist actor, if any such exists, otherwise random to any other matching entry.

    2. ClusterClient.SendToAll - The message will be delivered to all recipients with a matching path.

    3. ClusterClient.Publish - The message will be delivered to all recipients Actors that have been registered as subscribers to to the named topic.

    Use the factory method props(akka.cluster.client.ClusterClientSettings)) to create the Props for the actor.

    If the receptionist is not currently available, the client will buffer the messages and then deliver them when the connection to the receptionist has been established. The size of the buffer is configurable and it can be disabled by using a buffer size of 0. When the buffer is full old messages will be dropped when new messages are sent via the client.

    Note that this is a best effort implementation: messages can always be lost due to the distributed nature of the actors involved.

    • Method Detail

      • context

        public ActorContext context()
        Description copied from interface: Actor
        Scala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such as forward.

        WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads!

        ActorContext is the Scala API. getContext returns a AbstractActor.ActorContext, which is the Java API of the actor context.

        Specified by:
        context in interface Actor
      • self

        public final ActorRef self()
        Description copied from interface: Actor
        The 'self' field holds the ActorRef for this actor.

        Can be used to send messages to itself:
         self ! message
        Specified by:
        self in interface Actor
      • akka$actor$Actor$_setter_$self_$eq

        protected final void akka$actor$Actor$_setter_$self_$eq​(ActorRef x$1)
        Description copied from interface: Actor
        The 'self' field holds the ActorRef for this actor.

        Can be used to send messages to itself:
         self ! message
        Specified by:
        akka$actor$Actor$_setter_$self_$eq in interface Actor
        x$1 - (undocumented)
      • contactPaths

        public scala.collection.immutable.HashSet<ActorPath> contactPaths()
      • contactPaths_$eq

        public void contactPaths_$eq​(scala.collection.immutable.HashSet<ActorPath> x$1)
      • initialContactsSel

        public scala.collection.immutable.HashSet<ActorSelection> initialContactsSel()
      • contacts

        public scala.collection.immutable.HashSet<ActorSelection> contacts()
      • contacts_$eq

        public void contacts_$eq​(scala.collection.immutable.HashSet<ActorSelection> x$1)
      • contactPathsPublished

        public scala.collection.immutable.HashSet<ActorPath> contactPathsPublished()
      • contactPathsPublished_$eq

        public void contactPathsPublished_$eq​(scala.collection.immutable.HashSet<ActorPath> x$1)
      • subscribers

        public scala.collection.immutable.Vector<ActorRef> subscribers()
      • subscribers_$eq

        public void subscribers_$eq​(scala.collection.immutable.Vector<ActorRef> x$1)
      • refreshContactsTask

        public scala.Option<Cancellable> refreshContactsTask()
      • refreshContactsTask_$eq

        public void refreshContactsTask_$eq​(scala.Option<Cancellable> x$1)
      • scheduleRefreshContactsTick

        public void scheduleRefreshContactsTick​(scala.concurrent.duration.FiniteDuration interval)
      • postStop

        public void postStop()
        Description copied from interface: Actor
        User overridable callback.

        Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation.
        Specified by:
        postStop in interface Actor
      • receive

        public scala.PartialFunction<java.lang.Object,​scala.runtime.BoxedUnit> receive()
        Description copied from interface: Actor
        Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.
        Specified by:
        receive in interface Actor
      • establishing

        public scala.PartialFunction<java.lang.Object,​scala.runtime.BoxedUnit> establishing()
      • active

        public scala.PartialFunction<java.lang.Object,​scala.runtime.BoxedUnit> active​(ActorRef receptionist)
      • contactPointMessages

        public scala.PartialFunction<java.lang.Object,​scala.runtime.BoxedUnit> contactPointMessages()
      • sendGetContacts

        public void sendGetContacts()
      • buffer

        public void buffer​(java.lang.Object msg)
      • sendBuffered

        public void sendBuffered​(ActorRef receptionist)
      • publishContactPoints

        public void publishContactPoints()
      • reestablish

        public void reestablish()