use of org.apache.curator.retry.RetryUntilElapsed in project coprhd-controller by CoprHD.
the class ZkConnection method build.
/**
* Builds zk connector. Note that this method does not initiate a connection. {@link ZkConnection#connect()} must be called to connect
* to cluster.
* <p/>
* This separation is provided so that callbacks can be setup separately prior to connection to cluster.
*/
public void build() {
try {
_zkConnection = CuratorFrameworkFactory.builder().connectString(_connectString).connectionTimeoutMs(DEFAULT_CONN_TIMEOUT).canBeReadOnly(true).sessionTimeoutMs(_timeoutMs).retryPolicy(new RetryUntilElapsed(_timeoutMs, RETRY_INTERVAL_MS)).build();
_zkConnection.getUnhandledErrorListenable().addListener(new UnhandledErrorListener() {
@Override
public void unhandledError(String message, Throwable e) {
_logger.warn("Unknown exception in curator stack", e);
}
});
_zkConnection.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
_logger.info("Current connection state {}", newState);
}
});
if (FileUtils.exists(siteIdFile)) {
siteId = new String(FileUtils.readDataFromFile(siteIdFile));
siteId = siteId.trim();
_logger.info("Current site id is {}", siteId);
}
} catch (Exception e) {
throw CoordinatorException.fatals.failedToBuildZKConnector(e);
}
}
Aggregations