// Step 1: Find out my stratum for this message (if i have one)
// Check all rules to find my lowest stratum
int myStratum = Integer.MAX_VALUE;
Iterator it = nodeMasterInfoSet.iterator();
while (it.hasNext()) {
NodeMasterInfo nodeMasterInfo = (NodeMasterInfo)it.next();
if (nodeMasterInfo.getClusterNode().isLocalNode()) {
if (nodeMasterInfo.getStratum() < myStratum) {
myStratum = nodeMasterInfo.getStratum();
break;
}
}
}
// Step 2: Take the node with the lowest stratum or myself
// Aaheem, this is no round robin ... :-)
// We know that the Set is sorted after available:stratum:nodeId
it = nodeMasterInfoSet.iterator();
while (it.hasNext()) {
NodeMasterInfo nodeMasterInfo = (NodeMasterInfo)it.next();
if (myStratum <= nodeMasterInfo.getStratum()) {
// handle locally, no need to send to a worse or equal stratum
if (nodeMasterInfo.getStratum() > 0) {
log.warning("Selected myself as master node from a choice of " + nodeMasterInfoSet.size()
+ " nodes, but we are only stratum=" + nodeMasterInfo.getStratum() + ". The message is not routed further!");
}
else {
if (log.isLoggable(Level.FINE)) log.fine("Selected myself as master node from a choice of " + nodeMasterInfoSet.size() + " nodes");
}
return null; // handle locally: clusterManager.getMyClusterNode();
}
if (log.isLoggable(Level.FINE))
log.fine("Selected master node id='" +
nodeMasterInfo.getClusterNode().getId() + "' from a choice of " +
nodeMasterInfoSet.size() + " nodes. alive = " +
nodeMasterInfo.getClusterNode().isAlive() + ", polling = " +
nodeMasterInfo.getClusterNode().isPolling());
return nodeMasterInfo;
}
/*