|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object akka.contrib.pattern.ClusterSingletonProxy
public class ClusterSingletonProxy
The 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 stash the messages sent to the singleton and then unstash
them when the singleton is finally available. The proxy mixes in the Stash
trait, so it can be
configured accordingly.
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.
param: singletonPathString The logical path of the singleton. This does not include the node address or actor system
name, e.g., it can be something like /user/singletonManager/singleton.
param: role Cluster role on which the singleton is deployed. This is required to keep track only of the members where
the singleton can actually exist.
param: singletonIdentificationInterval Periodicity at which the proxy sends the Identify
message to the current
singleton actor selection.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface akka.actor.Actor |
---|
Actor.emptyBehavior$ |
Constructor Summary | |
---|---|
ClusterSingletonProxy(java.lang.String singletonPathString,
scala.Option<java.lang.String> role,
scala.concurrent.duration.FiniteDuration singletonIdentificationInterval)
|
Method Summary | |
---|---|
void |
add(Member m)
Adds new member if it has the right role. |
scala.math.Ordering<Member> |
ageOrdering()
|
void |
cancelTimer()
|
Cluster |
cluster()
|
java.lang.String |
createIdentifyId(int i)
|
static Props |
defaultProps(java.lang.String singletonPath,
java.lang.String role)
Java API: Factory method for ClusterSingletonProxy Props . |
void |
handleInitial(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<Cancellable> |
identifyTimer()
|
boolean |
matchingRole(Member member)
|
scala.collection.immutable.SortedSet<Member> |
membersByAge()
|
void |
postStop()
User overridable callback. |
void |
preStart()
User overridable callback. |
static Props |
props(java.lang.String singletonPath,
scala.Option<java.lang.String> role,
scala.concurrent.duration.FiniteDuration singletonIdentificationInterval)
Scala API: Factory method for ClusterSingletonProxy Props . |
static Props |
props(java.lang.String singletonPath,
java.lang.String role,
scala.concurrent.duration.FiniteDuration singletonIdentificationInterval)
Java API: Factory method for ClusterSingletonProxy Props . |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
receive()
This defines the initial actor behavior, it must return a partial function with the actor logic. |
void |
remove(Member m)
Removes a member. |
scala.Option<ActorRef> |
singleton()
|
java.lang.String[] |
singletonPath()
|
void |
trackChange(scala.Function0<scala.runtime.BoxedUnit> block)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface akka.actor.Actor |
---|
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, postRestart, self, sender, supervisorStrategy, unhandled |
Methods inherited from interface akka.actor.StashSupport |
---|
actorCell, capacity, clearStash, context, enqueueFirst, mailbox, prepend, self, stash, theStash, unstash, unstashAll, unstashAll |
Methods inherited from interface akka.actor.ActorLogging |
---|
_log, log |
Constructor Detail |
---|
public ClusterSingletonProxy(java.lang.String singletonPathString, scala.Option<java.lang.String> role, scala.concurrent.duration.FiniteDuration singletonIdentificationInterval)
Method Detail |
---|
public static Props props(java.lang.String singletonPath, scala.Option<java.lang.String> role, scala.concurrent.duration.FiniteDuration singletonIdentificationInterval)
ClusterSingletonProxy
Props
.
singletonPath
- The logical path of the singleton, i.e., /user/singletonManager/singleton.role
- The role of the cluster nodes where the singleton can be deployed. If None, then any node will do.singletonIdentificationInterval
- Interval at which the proxy will try to resolve the singleton instance.
public static Props props(java.lang.String singletonPath, java.lang.String role, scala.concurrent.duration.FiniteDuration singletonIdentificationInterval)
ClusterSingletonProxy
Props
.
singletonPath
- The logical path of the singleton, i.e., /user/singletonManager/singleton.role
- The role of the cluster nodes where the singleton can be deployed. If null, then any node will do.singletonIdentificationInterval
- Interval at which the proxy will try to resolve the singleton instance.
public static Props defaultProps(java.lang.String singletonPath, java.lang.String role)
ClusterSingletonProxy
Props
. The interval at which the proxy will try
to resolve the singleton instance is set to 1 second.
singletonPath
- The logical path of the singleton, i.e., /user/singletonManager/singleton.role
- The role of the cluster nodes where the singleton can be deployed. If null, then any node will do.
public java.lang.String[] singletonPath()
public int identifyCounter()
public java.lang.String identifyId()
public java.lang.String createIdentifyId(int i)
public scala.Option<Cancellable> identifyTimer()
public Cluster cluster()
public scala.Option<ActorRef> singleton()
public scala.math.Ordering<Member> ageOrdering()
public scala.collection.immutable.SortedSet<Member> membersByAge()
public void preStart()
Actor
preStart
in interface Actor
public void postStop()
Actor
postStop
in interface Actor
postStop
in interface UnrestrictedStash
public void cancelTimer()
public boolean matchingRole(Member member)
public void handleInitial(ClusterEvent.CurrentClusterState state)
public void identifySingleton()
public void trackChange(scala.Function0<scala.runtime.BoxedUnit> block)
public void add(Member m)
m
- New cluster member.public void remove(Member m)
m
- Cluster member to remove.public scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
Actor
receive
in interface Actor
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |