private static Log log = LogFactory.getLog(LoadbalanceAlgorithmFactory.class);
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'.";
log.fatal(msg); // We cannot continue execution. Hence it is logged at fatal level
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;
log.fatal(msg, e); // We cannot continue execution. Hence it is logged at fatal level
throw new SynapseException(msg, e);