OMElement loadbalanceElement = epConfig.getFirstChildWithName(
new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));
if (loadbalanceElement != null) {
LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(
org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
loadbalanceEndpoint.setName(name.getAttributeValue());
}
LoadbalanceAlgorithm algorithm = null;
// set endpoints or members
if (loadbalanceElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
if(loadbalanceElement.
getChildrenWithName((MEMBER)).hasNext()){
String msg =
"Invalid Synapse configuration. " +
"child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Endpoint> endpoints
= getEndpoints(loadbalanceElement, loadbalanceEndpoint, properties);
loadbalanceEndpoint.setChildren(endpoints);
algorithm =
LoadbalanceAlgorithmFactory.
createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
} else if (loadbalanceElement.getFirstChildWithName(MEMBER) != null) {
if(loadbalanceElement.
getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()){
String msg =
"Invalid Synapse configuration. " +
"loadbalanceEndpoint element cannot have both member & endpoint " +
"child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Member> members = getMembers(loadbalanceElement);
loadbalanceEndpoint.setMembers(members);
algorithm =
LoadbalanceAlgorithmFactory.
createLoadbalanceAlgorithm2(loadbalanceElement, members);
loadbalanceEndpoint.startApplicationMembershipTimer();
}
if (loadbalanceEndpoint.getChildren() == null &&
loadbalanceEndpoint.getMembers() == null) {
String msg = "Invalid Synapse configuration.\n"
+ "A LoadbalanceEndpoint must have child elements, but the LoadbalanceEndpoint "
+ "'" + loadbalanceEndpoint.getName() + "' does not have any child elements.";
log.error(msg);
throw new SynapseException(msg);
}
// set load balance algorithm
loadbalanceEndpoint.setAlgorithm(algorithm);
// set if failover is turned off
String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
if (failover != null && failover.equalsIgnoreCase("false")) {
loadbalanceEndpoint.setFailover(false);
}
// process the parameters
processProperties(loadbalanceEndpoint, epConfig);