return;
}
boolean restartBootstrap = false;
String bsServerInfo = _resumeCkpt.getBootstrapServerInfo();
ServerInfo lastReadBS = null;
if ( null != bsServerInfo)
{
try
{
lastReadBS = ServerInfo.buildServerInfoFromHostPort(bsServerInfo, DbusConstants.HOSTPORT_DELIMITER);
} catch(Exception ex) {
_log.error("Unable to fetch bootstrap serverInfo from checkpoint, ServerInfo :" + bsServerInfo, ex);
}
}
if ( null == lastReadBS)
restartBootstrap = true;
int retriesLeft = 0;
DatabusBootstrapConnection bootstrapConn = null;
ServerInfo serverInfo = lastReadBS;
if ( !restartBootstrap )
{
//attempt to reconnect to the last used bootstrap server
while (null == bootstrapConn && (retriesLeft = _retriesBeforeCkptCleanup.getRemainingRetriesNum()) >= 0
&& !checkForShutdownRequest())
{
_log.info("Retry picking last used bootstrap server :" + serverInfo +
"; retries left:" + retriesLeft);
if (lastReadBS.equals(_curServer) ) // if it is new server do not sleep?
_retriesBeforeCkptCleanup.backoffAndSleep();
try
{
bootstrapConn = _sourcesConn.getBootstrapConnFactory().createConnection(serverInfo, this,
_remoteExceptionHandler);
_log.info("picked last used bootstrap server:" + serverInfo);
}
catch (Exception e)
{
_log.error("Unable to get connection to bootstrap server:" + serverInfo, e);
}
}
if ((null == bootstrapConn) && (_retriesBeforeCkptCleanup.getRemainingRetriesNum() < 0))
{
_log.info("Exhausted retrying the same bootstrap server :" + lastReadBS);
}
}
if(checkForShutdownRequest()) {
_log.info("Shutting down bootstrap");
return;
}
Random rng = new Random();
if ( null == bootstrapConn)
{
_log.info("Restarting bootstrap as client might be getting bootstrap data from different server instance !!");
_log.info("Old Checkpoint :" + _resumeCkpt);
curState.getBstCheckpointHandler().resetForServerChange(_resumeCkpt);
_log.info("New Checkpoint :" + _resumeCkpt);
_retriesBeforeCkptCleanup.reset();
} else {
_curServer = serverInfo;
}
while ((null == bootstrapConn) && (retriesLeft = _status.getRetriesLeft()) >= 0 &&
!checkForShutdownRequest())
{
_log.info("picking a bootstrap server; retries left:" + retriesLeft);
backoffOnPullError();
_curServerIdx = (_curServerIdx < 0) ? rng.nextInt(serversNum)
: (_curServerIdx + 1) % serversNum;
Iterator<ServerInfo> setIter = _servers.iterator();
for (int i = 0; i <= _curServerIdx; ++i) serverInfo = setIter.next();
_curServer = serverInfo;
try
{
bootstrapConn = _sourcesConn.getBootstrapConnFactory().createConnection(serverInfo, this, _remoteExceptionHandler);
_log.info("picked a bootstrap server:" + serverInfo.toSimpleString());
}
catch (Exception e)
{
_log.error("Unable to get connection to bootstrap server:" + serverInfo, e);
}
}
/*
* Close the old bootstrap Connection
*/
DatabusBootstrapConnection oldBootstrapConn = curState.getBootstrapConnection();
if ( null != oldBootstrapConn)
resetConnectionAndSetFlag();
_lastOpenConnection = bootstrapConn;
if (checkForShutdownRequest()) return;
if (null == bootstrapConn)
{
_log.error("bootstrap server retries exhausted");
enqueueMessage(LifecycleMessage.createSuspendOnErroMessage(new DatabusException("bootstrap server retries exhausted")));
return;
}
sendHeartbeat(_sourcesConn.getUnifiedClientStats());
curState.bootstrapServerSelected(serverInfo.getAddress(), bootstrapConn, _curServer);
//determine what to do next based on the current checkpoint
_log.info("resuming bootstrap from checkpoint: " + _resumeCkpt);
curState.setCheckpoint(_resumeCkpt);
determineNextStateFromCheckpoint(curState);