// Search all other cluster nodes to find the masters of this message ...
// NOTE: If no filters are used, the masterSet=f(msgUnit) could be cached for performance gain
// Cache implementation is currently missing
Set masterSet = new TreeSet(); // Contains the NodeMasterInfo objects which match this message
// Sorted by stratum (0 is the first entry) -> see NodeMasterInfo.compareTo
int numRulesFound = 0; // For nicer logging of warnings
QosData publishQos = msgUnit.getQosData();
if (publishQos.count(glob.getNodeId()) > 1) { // Checked in RequestBroker as well with warning
log.warning("Warning, message '" + msgUnit.getLogId() +
"' passed my node id='" + glob.getId() + "' before, we have a circular routing problem, keeping message locally");
return null;
}
ClusterNode[] clusterNodes = getClusterNodes();
for (int ic=0; ic<clusterNodes.length; ic++) {
ClusterNode clusterNode = clusterNodes[ic];
NodeMasterInfo[] nodeMasterInfos = clusterNode.getNodeMasterInfos();
if (nodeMasterInfos.length < 1)
continue;
if (clusterNode.isAllowed() == false) {
if (log.isLoggable(Level.FINE)) log.fine("Ignoring master node id='" + clusterNode.getId() + "' because it is not available");
continue;
}
if (!clusterNode.isLocalNode() && publishQos.count(clusterNode.getNodeId()) > 0) {
if (log.isLoggable(Level.FINE)) log.fine("Ignoring node id='" + clusterNode.getId() + "' for routing, message '" +
msgUnit.getLogId() + "' has been there already");
continue;
}
if (log.isLoggable(Level.FINE)) log.fine("Testing " + nodeMasterInfos.length + " domains rules of node " +
clusterNode.getId() + " for " + msgUnit.getLogId());
numRulesFound += clusterNode.getNodeMasterInfos().length;
// for each domain mapping rule ...
for (int i=0; i<nodeMasterInfos.length; i++) {
NodeMasterInfo nodeMasterInfo = (NodeMasterInfo)nodeMasterInfos[i];
I_MapMsgToMasterId domainMapper = this.mapMsgToMasterPluginManager.getMapMsgToMasterId(
nodeMasterInfo.getType(), nodeMasterInfo.getVersion(), // "DomainToMaster", "1.0"
msgUnit.getContentMime(), msgUnit.getContentMimeExtended());
if (domainMapper == null) {
log.warning("No domain mapping plugin type='" + nodeMasterInfo.getType() + "' version='" + nodeMasterInfo.getVersion() +
"' found for message mime='" + msgUnit.getContentMime() + "' and '" + msgUnit.getContentMimeExtended() +
"' ignoring rules " + nodeMasterInfo.toXml());
continue;
}
// Now invoke the plugin to find out who is the master ...
nodeMasterInfo = domainMapper.getMasterId(nodeMasterInfo, msgUnit);
if (nodeMasterInfo != null) {
masterSet.add(nodeMasterInfo);
break; // found one
}
}
}
if (masterSet.size() < 1) {
if (numRulesFound == 0) {
if (log.isLoggable(Level.FINE)) log.fine("Using local node for message, no master mapping rules are known.");
}
else {
if (destination == null) {
log.info("No master found for " + msgUnit.getMethodName() + " message '" + msgUnit.getLogId() + "' mime='" +
msgUnit.getContentMime() + "' domain='" + msgUnit.getDomain() + "', using local node.");
}
else {
if (log.isLoggable(Level.FINE)) log.fine("No master found for PtP message '" + msgUnit.getLogId() + "' mime='" +
msgUnit.getContentMime() + "' domain='" + msgUnit.getDomain() + "', using local node.");
}
}
return null;
}
if (masterSet.size() > 1) {
if (log.isLoggable(Level.FINE)) log.fine(masterSet.size() + " masters found for message '" + msgUnit.getLogId() +
"' domain='" + msgUnit.getDomain() + "'");
}
NodeMasterInfo nodeMasterInfo = loadBalancer.getClusterNode(masterSet); // Invoke for masterSet.size()==1 as well, the balancer may choose to ignore it