epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE,
"dynamicLoadbalance"));
if (loadbalanceElement != null) {
DynamicLoadbalanceEndpoint loadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
// set endpoint name
OMAttribute name =
epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
loadbalanceEndpoint.setName(name.getAttributeValue());
}
// get the session for this endpoint
OMElement sessionElement = epConfig.
getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "session"));
if (sessionElement != null) {
OMElement sessionTimeout = sessionElement.getFirstChildWithName(
new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sessionTimeout"));
if (sessionTimeout != null) {
try {
loadbalanceEndpoint.setSessionTimeout(Long.parseLong(
sessionTimeout.getText().trim()));
} catch (NumberFormatException nfe) {
handleException("Invalid session timeout value : " + sessionTimeout.getText());
}
}
String type = sessionElement.getAttributeValue(new QName("type"));
if (type.equalsIgnoreCase("soap")) {
Dispatcher soapDispatcher = new SoapSessionDispatcher();
loadbalanceEndpoint.setDispatcher(soapDispatcher);
} else if (type.equalsIgnoreCase("http")) {
Dispatcher httpDispatcher = new HttpSessionDispatcher();
loadbalanceEndpoint.setDispatcher(httpDispatcher);
}
loadbalanceEndpoint.setSessionAffinity(true);
}
// set if failover is turned off
String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
if (failover != null && failover.equalsIgnoreCase("false")) {
loadbalanceEndpoint.setFailover(false);
} else {
loadbalanceEndpoint.setFailover(true);
}
OMElement eventHandler =
loadbalanceElement.
getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE,
"membershipHandler"));
if (eventHandler != null) {
String clazz =
eventHandler.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE,
"class")).trim();
try {
LoadBalanceMembershipHandler lbMembershipHandler =
(LoadBalanceMembershipHandler) Class.forName(clazz).newInstance();
Properties lbProperties = new Properties();
for (Iterator props = eventHandler.getChildrenWithName(new QName(
SynapseConstants.SYNAPSE_NAMESPACE, "property")); props.hasNext();) {
OMElement prop = (OMElement) props.next();
String propName =
prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE,
"name")).trim();
String propValue =
prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE,
"value")).trim();
lbProperties.put(propName, propValue);
}
// Set load balance algorithm
LoadbalanceAlgorithm algorithm =
LoadbalanceAlgorithmFactory.
createLoadbalanceAlgorithm(loadbalanceElement, null);
lbMembershipHandler.init(lbProperties, algorithm);
loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
} catch (Exception e) {
String msg = "Could not instantiate " +
"LoadBalanceMembershipHandler implementation " + clazz;
log.error(msg, e);
throw new SynapseException(msg, e);