// We attempt to connect to the next node in a loop, since we might need to go through
// multiple hops
int attemptCount = 0;
ClientConnectionFactoryDelegate delegate = null;
while (attemptCount < MAX_RECONNECT_HOP_COUNT)
{
// since an exception might be captured during an attempt, this has to be the first
// operation
attemptCount++;
int nextHopingServer = -1;
try
{
int failedNodeIDToServer = -1;
if (delegate == null)
{
if (failedNodeID != null && failedNodeID.intValue() >= 0)
{
//It's a reconnect after failover
delegate = getFailoverDelegateForNode(failedNodeID);
failedNodeIDToServer = failedNodeID.intValue();
nextHopingServer = delegate.getServerID();
}
else
{
//It's a first time create connection
LoadBalancingPolicy loadBalancingPolicy = clusteredDelegate.getLoadBalancingPolicy();
delegate = (ClientConnectionFactoryDelegate)loadBalancingPolicy.getNext();
}
}
log.trace(this + " has chosen " + delegate + " as target, " +
(attemptCount == 0 ? "first connection attempt" : attemptCount + " connection attempts"));
CreateConnectionResult res = delegate.
createConnectionDelegate(username, password, failedNodeIDToServer);
ClientConnectionDelegate cd = (ClientConnectionDelegate)res.getDelegate();
if (cd != null)