use of org.apache.synapse.PropertyInclude in project wso2-synapse by wso2.
the class WeightedRRLCAlgorithm method intialize.
/**
* 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()));
}
list[i] = state;
}
}
// sort the states according to the initial fixed weights
Arrays.sort(list, new Comparator<WeightedState>() {
public int compare(WeightedState o1, WeightedState o2) {
return o2.getFixedWeight() - o1.getFixedWeight();
}
});
}
use of org.apache.synapse.PropertyInclude in project wso2-synapse by wso2.
the class WeightedRoundRobin method init.
public void init(SynapseEnvironment se) {
if (endpoints == null) {
String msg = "Endpoints are not set, cannot initialize the algorithm";
log.error(msg);
throw new SynapseException(msg);
}
endpointStates = new EndpointState[endpoints.size()];
for (int i = 0; i < endpoints.size(); i++) {
Endpoint endpoint = endpoints.get(i);
if (!(endpoint instanceof PropertyInclude)) {
EndpointState state = new EndpointState(i, DEFAULT_WEIGHT);
endpointStates[i] = state;
} else {
MediatorProperty property = ((PropertyInclude) endpoint).getProperty(LOADBALANCE_WEIGHT);
EndpointState state;
if (property != null) {
int weight = Integer.parseInt(property.getValue());
if (weight <= 0) {
String msg = "Weight must be greater than zero";
log.error(msg);
throw new SynapseException(msg);
}
state = new EndpointState(i, weight);
} else {
state = new EndpointState(i, DEFAULT_WEIGHT);
}
endpointStates[i] = state;
}
}
if (loadBalanceEndpoint instanceof PropertyInclude) {
MediatorProperty threadLocalProperty = ((PropertyInclude) loadBalanceEndpoint).getProperty(LOADBALANCE_ThEADLOCAL);
if (threadLocalProperty != null && threadLocalProperty.getValue().equals("true")) {
isThreadLocal = true;
}
}
view = new WeightedRoundRobinView(this);
MBeanRegistrar.getInstance().registerMBean(view, "LBAlgorithms", loadBalanceEndpoint.getName() != null ? loadBalanceEndpoint.getName() : "LBEpr");
}
Aggregations