org.apache.synapse.endpoints.algorithms
public class: RoundRobin [javadoc |
source]
java.lang.Object
org.apache.synapse.endpoints.algorithms.RoundRobin
All Implemented Interfaces:
LoadbalanceAlgorithm
This is the implementation of the round robin load balancing algorithm. It simply iterates
through the endpoint list one by one for until an active endpoint is found.
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.synapse.endpoints.algorithms.RoundRobin Detail: |
public Endpoint getNextEndpoint(MessageContext synapseMessageContext,
AlgorithmContext algorithmContext) {
if (log.isDebugEnabled()) {
log.debug("Using the Round Robin loadbalancing algorithm to select the next endpoint");
}
Endpoint nextEndpoint;
int attempts = 0;
int currentEPR = algorithmContext.getCurrentEndpointIndex();
do {
// two successive clients could get the same endpoint if not synchronized.
synchronized (this) {
nextEndpoint = (Endpoint) endpoints.get(currentEPR);
if (currentEPR == endpoints.size() - 1) {
currentEPR = 0;
} else {
currentEPR++;
}
algorithmContext.setCurrentEPR(currentEPR);
}
attempts++;
if (attempts > endpoints.size()) {
log.warn("Couldn't find an endpoint from the Round Robin loadbalancing algorithm");
return null;
}
} while (!nextEndpoint.isActive(synapseMessageContext));
return nextEndpoint;
}
Choose an active endpoint using the round robin algorithm. If there are no active endpoints
available, returns null. |
public void reset(AlgorithmContext algorithmContext) {
if (log.isDebugEnabled()) {
log.debug("Resetting the Round Robin loadbalancing algorithm ...");
}
algorithmContext.setCurrentEPR(0);
}
|