try {
sn = masterAddressTracker.getMasterAddress();
if (sn == null) {
LOG.info("ZooKeeper available but no active master location found");
throw new MasterNotRunningException();
}
InetSocketAddress isa =
new InetSocketAddress(sn.getHostname(), sn.getPort());
HMasterInterface tryMaster = rpcEngine.getProxy(
HMasterInterface.class, HMasterInterface.VERSION, isa, this.conf,
this.rpcTimeout);
if (tryMaster.isMasterRunning()) {
this.master = tryMaster;
this.masterLock.notifyAll();
break;
}
} catch (IOException e) {
if (!shouldRetryGetMaster(tries, e)) break;
} catch (UndeclaredThrowableException ute) {
if (!shouldRetryGetMaster(tries, ute)) break;
}
// Cannot connect to master or it is not running. Sleep & retry
try {
this.masterLock.wait(ConnectionUtils.getPauseTime(this.pause, tries));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread was interrupted while trying to connect to master.");
}
}
if (this.master == null) {
if (sn == null) {
throw new MasterNotRunningException();
}
throw new MasterNotRunningException(sn.toString());
}
return this.master;
}
}