use of org.apache.synapse.endpoints.algorithms.RoundRobin in project wso2-synapse by wso2.
the class LoadbalanceAlgorithmFactory method createLoadbalanceAlgorithm.
public static LoadbalanceAlgorithm createLoadbalanceAlgorithm(OMElement loadbalanceElement, List endpoints) {
// default algorithm is round robin
LoadbalanceAlgorithm algorithm = new RoundRobin(endpoints);
OMAttribute policyAttribute = loadbalanceElement.getAttribute(new QName(null, XMLConfigConstants.LOADBALANCE_POLICY));
OMAttribute algoAttribute = loadbalanceElement.getAttribute(new QName(null, XMLConfigConstants.LOADBALANCE_ALGORITHM));
if (policyAttribute != null && algoAttribute != null) {
String msg = "You cannot specify both the 'policy' & 'algorithm' in the configuration. " + "It is sufficient to provide only the 'algorithm'.";
// We cannot continue execution. Hence it is logged at fatal level
log.fatal(msg);
throw new SynapseException(msg);
}
if (algoAttribute != null) {
String algorithmStr = algoAttribute.getAttributeValue().trim();
try {
algorithm = (LoadbalanceAlgorithm) Class.forName(algorithmStr).newInstance();
algorithm.setEndpoints(endpoints);
} catch (Exception e) {
String msg = "Cannot instantiate LoadbalanceAlgorithm implementation class " + algorithmStr;
// We cannot continue execution. Hence it is logged at fatal level
log.fatal(msg, e);
throw new SynapseException(msg, e);
}
} else if (policyAttribute != null) {
// currently only the roundRobin policy is supported
if (!policyAttribute.getAttributeValue().trim().equals("roundRobin")) {
String msg = "Unsupported algorithm " + policyAttribute.getAttributeValue().trim() + " specified. Please use the 'algorithm' attribute to specify the " + "correct loadbalance algorithm implementation.";
// We cannot continue execution. Hence it is logged at fatal level
log.fatal(msg);
throw new SynapseException(msg);
}
}
return algorithm;
}
Aggregations