* Initialize the algorithm reading the configurations from the endpoints.
*/
private void intialize() {
// get the global properties
if (loadBalanceEndpoint != null && loadBalanceEndpoint instanceof PropertyInclude) {
PropertyInclude include = (PropertyInclude) loadBalanceEndpoint;
MediatorProperty val = include.getProperty(LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
if (val != null) {
roundsPerRecalculation = Integer.parseInt(val.getValue());
}
}
// initialize the states list, this runs only once
list = new WeightedState[endpoints.size()];
int totalWeight = 0;
for (Endpoint endpoint : endpoints) {
if (endpoint instanceof PropertyInclude) {
PropertyInclude include = (PropertyInclude) endpoint;
MediatorProperty val = include.getProperty(LB_WEIGHTED_RRLC_WEIGHT);
if (val == null) {
String msg = "Parameter " +
"loadbalance.weighted.weight should be specified for every " +
"endpoint in the load balance group";
log.error(msg);
throw new SynapseException(msg);
}
totalWeight += Integer.parseInt(val.getValue());
}
}
this.totalWeight = totalWeight;
for (int i = 0; i < endpoints.size(); i++) {
Endpoint e = endpoints.get(i);
if (e instanceof PropertyInclude) {
PropertyInclude include = (PropertyInclude) e;
MediatorProperty weight = include.getProperty(
LB_WEIGHTED_RRLC_WEIGHT);
String key;
URL url;
if (e instanceof AddressEndpoint) {
AddressEndpoint addressEndpoint = (AddressEndpoint) e;
try {
url = new URL(addressEndpoint.getDefinition().getAddress());
} catch (MalformedURLException e1) {
String msg = "Mulformed URL in address endpoint";
log.error(msg);
throw new SynapseException(msg);
}
} else if (e instanceof WSDLEndpoint) {
WSDLEndpoint wsdlEndpoint = (WSDLEndpoint) e;
try {
url = new URL(wsdlEndpoint.getDefinition().getAddress());
} catch (MalformedURLException e1) {
String msg = "Mulformed URL in address endpoint";
log.error(msg);
throw new SynapseException(msg);
}
} else {
String msg = "Only AddressEndpoint and WSDLEndpoint can be used " +
"with WeightedRRLCAlgorithm";
log.error(msg);
throw new SynapseException(msg);
}
// construct the key
key = url.getHost() + ":" + url.getPort();
WeightedState state = new WeightedState(
Integer.parseInt(weight.getValue()), i, key);
MediatorProperty minimumWeight = include.getProperty(
LB_WEIGHTED_RRLC_WEIGHT_MIN);
if (minimumWeight != null) {
state.setMinWeight(Integer.parseInt(minimumWeight.getValue()));
}
MediatorProperty maxWeight = include.getProperty(
LB_WEIGHTED_RRLC_WEIGHT_MAX);
if (maxWeight != null) {
state.setMaxWeight(Integer.parseInt(maxWeight.getValue()));
}