Methods Summary |
---|
public void | _stopOldMaster()This method will be invoked twice by the local node
when it stops as well as by the remote
log.debug("_stopOldMaster, isMasterNode=" + isMasterNode);
try
{
// since this is a cluster call, all nodes will hear it
// so if the node is not the master, then ignore
if (isMasterNode == true)
{
isMasterNode = false;
// notify stopping
sendLocalNotification(HASINGLETON_STOPPING_NOTIFICATION);
// stop the singleton
stopSingleton();
// notify stopped
sendLocalNotification(HASINGLETON_STOPPED_NOTIFICATION);
}
}
catch (Exception ex)
{
log.error(
"_stopOldMaster failed. Will still try to start new master. " +
"You need to examine the reason why the old master wouldn't stop and resolve it. " +
"It is bad that the old singleton may still be running while we are starting a new one, " +
"so you need to resolve this ASAP.", ex);
}
|
public HASingletonElectionPolicy | getElectionPolicy()
return this.mElectionPolicyMB;
|
public boolean | getRestartOnMerge()Gets whether this singleton will stop and restart itself if it is the
master and a cluster merge occurs.
A restart allows the service to reset any state that may
have gotten out-of-sync with the rest of the cluster while
the just-merged split was in effect.
return restartOnMerge;
|
public boolean | isMasterNode()
return isMasterNode;
|
protected void | makeThisNodeMaster()
try
{
// stop the old master (if there is one) before starting the new one
// ovidiu 09/02/04 - temporary solution for Case 1843, use an asynchronous
// distributed call.
//callMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
callAsyncMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
startNewMaster();
}
catch (Exception ex)
{
log.error("_stopOldMaster failed. New master singleton will not start.", ex);
}
|
public void | partitionTopologyChanged(java.util.List newReplicants, int newViewID)When topology changes, a new master is elected based on the result
of the isDRMMasterReplica() call.
boolean isElectedNewMaster;
if (this.mElectionPolicyMB != null)
isElectedNewMaster = this.mElectionPolicyMB.isElectedMaster(this.getPartition());
else
isElectedNewMaster = isDRMMasterReplica();
if (log.isDebugEnabled())
{
log.debug("partitionTopologyChanged, isElectedNewMaster=" + isElectedNewMaster
+ ", isMasterNode=" + isMasterNode + ", viewID=" + newViewID);
}
// if this node is already the master, don't bother electing it again
if (isElectedNewMaster && isMasterNode)
{
// JBAS-4229
if (restartOnMerge && ClusterMergeStatus.isMergeInProcess())
{
restartMaster();
}
}
// just becoming master
else if (isElectedNewMaster && !isMasterNode)
{
makeThisNodeMaster();
}
// transition from master to slave
else if (isMasterNode == true)
{
_stopOldMaster();
}
|
protected void | restartMaster()
_stopOldMaster();
startNewMaster();
|
private void | sendLocalNotification(java.lang.String type)
Notification n = new Notification(type, this, getNextNotificationSequenceNumber());
super.sendNotificationToLocalListeners(n);
|
public void | setElectionPolicy(HASingletonElectionPolicy mb)
this.mElectionPolicyMB = mb;
|
public void | setRestartOnMerge(boolean restartOnMerge)Sets whether this singleton will stop and restart itself if it is the
master and a cluster merge occurs?
A restart allows the service to reset any state that may
have gotten out-of-sync with the rest of the cluster while
the just-merged split was in effect.
this.restartOnMerge = restartOnMerge;
|
protected void | startNewMaster()
log.debug("startNewMaster, isMasterNode=" + isMasterNode);
isMasterNode = true;
// notify starting
sendLocalNotification(HASINGLETON_STARTING_NOTIFICATION);
// start new master
startSingleton();
// notify started
sendLocalNotification(HASINGLETON_STARTED_NOTIFICATION);
|
public void | startSingleton()Extending classes should override this method and implement the custom
singleton logic. Only one node in the cluster is the active master.
If the current node is elected for master, this method is invoked.
When another node is elected for master for some reason, the
stopSingleton() method is invokded.
When the extending class is a stateful singleton, it will
usually use putDistributedState() and getDistributedState() to save in
the cluster environment information that will be needed by the next node
elected for master should the current master node fail.
if (log.isDebugEnabled())
log.debug("startSingleton() : elected for master singleton node");
// Extending classes will implement the singleton logic here
|
public void | stopSingleton()Extending classes should override this method and implement the custom
singleton logic. Only one node in the cluster is the active master.
If the current node is master and another node is elected for master, this
method is invoked.
if (log.isDebugEnabled())
log.debug("stopSingleton() : another node in the partition (if any) is elected for master");
// Extending classes will implement the singleton logic here
|