if (mIsShutdown) {
throw new IOException("Client is shutdown, will not try to connect");
}
Exception lastException = null;
RetryPolicy retry = new ExponentialBackoffRetry(50, Constants.SECOND_MS, MAX_CONNECT_TRY);
do {
mMasterAddress = getMasterAddress();
LOG.info("Tachyon client (version " + Version.VERSION + ") is trying to connect master @ "
+ mMasterAddress);
mProtocol =
new TBinaryProtocol(new TFramedTransport(new TSocket(
NetworkUtils.getFqdnHost(mMasterAddress), mMasterAddress.getPort())));
mClient = new MasterService.Client(mProtocol);
try {
mProtocol.getTransport().open();
mHeartbeatThread =
new HeartbeatThread("Master_Client Heartbeat", new MasterClientHeartbeatExecutor(this),
UserConf.get().HEARTBEAT_INTERVAL_MS / 2);
mHeartbeatThread.start();
} catch (TTransportException e) {
lastException = e;
LOG.error("Failed to connect (" + retry.getRetryCount() + ") to master " + mMasterAddress
+ " : " + e.getMessage());
if (mHeartbeatThread != null) {
mHeartbeatThread.shutdown();
}
continue;
}
try {
mUserId = mClient.user_getUserId();
} catch (TException e) {
lastException = e;
LOG.error(e.getMessage(), e);
continue;
}
LOG.info("User registered at the master " + mMasterAddress + " got UserId " + mUserId);
mConnected = true;
return;
} while (retry.attemptRetry() && !mIsShutdown);
// Reaching here indicates that we did not successfully connect.
throw new IOException("Failed to connect to master " + mMasterAddress + " after "
+ (retry.getRetryCount()) + " attempts", lastException);
}