public final class ClusterSingletonProxy
extends java.lang.Object
implements akka.actor.Actor, akka.actor.ActorLogging
ClusterSingletonProxy
works together with the ClusterSingletonManager
to provide a
distributed proxy to the singleton actor.
The proxy can be started on every node where the singleton needs to be reached and used as if it were the singleton itself. It will then act as a router to the currently running singleton instance. If the singleton is not currently available, e.g., during hand off or startup, the proxy will buffer the messages sent to the singleton and then deliver them when the singleton is finally available. 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 proxy.
The proxy works by keeping track of the oldest cluster member. When a new oldest member is identified, e.g. because
the older one left the cluster, or at startup, the proxy will try to identify the singleton on the oldest member by
periodically sending an Identify
message until the singleton responds with its
ActorIdentity
.
Note that this is a best effort implementation: messages can always be lost due to the distributed nature of the actors involved.
Constructor and Description |
---|
ClusterSingletonProxy(java.lang.String singletonManagerPath,
ClusterSingletonProxySettings settings) |
Modifier and Type | Method and Description |
---|---|
void |
add(akka.cluster.Member m)
Adds new member if it has the right role.
|
scala.math.Ordering<akka.cluster.Member> |
ageOrdering() |
java.util.LinkedList<scala.Tuple2<java.lang.Object,akka.actor.ActorRef>> |
buffer() |
void |
buffer(java.lang.Object msg) |
void |
cancelTimer() |
akka.cluster.Cluster |
cluster() |
java.lang.String |
createIdentifyId(int i) |
void |
handleInitial(akka.cluster.ClusterEvent.CurrentClusterState state) |
int |
identifyCounter() |
java.lang.String |
identifyId() |
void |
identifySingleton()
Discard old singleton ActorRef and send a periodic message to self to identify the singleton.
|
scala.Option<akka.actor.Cancellable> |
identifyTimer() |
boolean |
matchingRole(akka.cluster.Member member) |
scala.collection.immutable.SortedSet<akka.cluster.Member> |
membersByAge() |
void |
postStop() |
void |
preStart() |
static akka.actor.Props |
props(java.lang.String singletonManagerPath,
ClusterSingletonProxySettings settings)
Scala API: Factory method for
ClusterSingletonProxy Props . |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
receive() |
void |
remove(akka.cluster.Member m)
Removes a member.
|
void |
sendBuffered() |
scala.Option<akka.actor.ActorRef> |
singleton() |
java.lang.String[] |
singletonPath() |
void |
trackChange(scala.Function0<scala.runtime.BoxedUnit> block) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ClusterSingletonProxy(java.lang.String singletonManagerPath, ClusterSingletonProxySettings settings)
public static akka.actor.Props props(java.lang.String singletonManagerPath, ClusterSingletonProxySettings settings)
ClusterSingletonProxy
Props
.
singletonManagerPath
- The logical path of the singleton manager, e.g. /user/singletonManager
,
which ends with the name you defined in actorOf
when creating the ClusterSingletonManager
.settings
- see ClusterSingletonProxySettings
public java.lang.String[] singletonPath()
public int identifyCounter()
public java.lang.String identifyId()
public java.lang.String createIdentifyId(int i)
public scala.Option<akka.actor.Cancellable> identifyTimer()
public akka.cluster.Cluster cluster()
public scala.Option<akka.actor.ActorRef> singleton()
public scala.math.Ordering<akka.cluster.Member> ageOrdering()
public scala.collection.immutable.SortedSet<akka.cluster.Member> membersByAge()
public java.util.LinkedList<scala.Tuple2<java.lang.Object,akka.actor.ActorRef>> buffer()
public void preStart()
preStart
in interface akka.actor.Actor
public void postStop()
postStop
in interface akka.actor.Actor
public void cancelTimer()
public boolean matchingRole(akka.cluster.Member member)
public void handleInitial(akka.cluster.ClusterEvent.CurrentClusterState state)
public void identifySingleton()
public void trackChange(scala.Function0<scala.runtime.BoxedUnit> block)
public void add(akka.cluster.Member m)
m
- New cluster member.public void remove(akka.cluster.Member m)
m
- Cluster member to remove.public scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
receive
in interface akka.actor.Actor
public void buffer(java.lang.Object msg)
public void sendBuffered()