* @param synapseMessageContext
* @return endpoint to send the next message
*/
public Endpoint getNextEndpoint(MessageContext synapseMessageContext) {
Endpoint nextEndpoint = null;
int attempts = 0;
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++;
}
}
attempts++;
if (attempts > endpoints.size()) {
return null;
}
} while (!nextEndpoint.isActive(synapseMessageContext));
return nextEndpoint;
}