use of org.apache.curator.retry.ExponentialBackoffRetry in project incubator-gobblin by apache.
the class ZookeeperBasedJobLock method initializeCuratorFramework.
private static synchronized void initializeCuratorFramework(Properties properties) {
if (curatorFrameworkShutdownHook == null) {
curatorFrameworkShutdownHook = new CuratorFrameworkShutdownHook();
Runtime.getRuntime().addShutdownHook(curatorFrameworkShutdownHook);
}
if (curatorFramework == null) {
CuratorFramework newCuratorFramework = CuratorFrameworkFactory.builder().connectString(properties.getProperty(CONNECTION_STRING, CONNECTION_STRING_DEFAULT)).connectionTimeoutMs(getMilliseconds(properties, CONNECTION_TIMEOUT_SECONDS, CONNECTION_TIMEOUT_SECONDS_DEFAULT)).sessionTimeoutMs(getMilliseconds(properties, SESSION_TIMEOUT_SECONDS, SESSION_TIMEOUT_SECONDS_DEFAULT)).retryPolicy(new ExponentialBackoffRetry(getMilliseconds(properties, RETRY_BACKOFF_SECONDS, RETRY_BACKOFF_SECONDS_DEFAULT), getInt(properties, MAX_RETRY_COUNT, MAX_RETRY_COUNT_DEFAULT))).build();
newCuratorFramework.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
switch(connectionState) {
case LOST:
log.warn("Lost connection with zookeeper");
for (Map.Entry<String, JobLockEventListener> lockEventListener : lockEventListeners.entrySet()) {
log.warn("Informing job {} that lock was lost", lockEventListener.getKey());
lockEventListener.getValue().onLost();
}
break;
case SUSPENDED:
log.warn("Suspended connection with zookeeper");
for (Map.Entry<String, JobLockEventListener> lockEventListener : lockEventListeners.entrySet()) {
log.warn("Informing job {} that lock was suspended", lockEventListener.getKey());
lockEventListener.getValue().onLost();
}
break;
case CONNECTED:
log.info("Connected with zookeeper");
break;
case RECONNECTED:
log.warn("Regained connection with zookeeper");
break;
case READ_ONLY:
log.warn("Zookeeper connection went into read-only mode");
break;
}
}
});
newCuratorFramework.start();
try {
if (!newCuratorFramework.blockUntilConnected(getInt(properties, CONNECTION_TIMEOUT_SECONDS, CONNECTION_TIMEOUT_SECONDS_DEFAULT), TimeUnit.SECONDS)) {
throw new RuntimeException("Time out while waiting to connect to zookeeper");
}
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while waiting to connect to zookeeper");
}
curatorFramework = newCuratorFramework;
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project airavata by apache.
the class Factory method getCuratorClient.
public static CuratorFramework getCuratorClient() throws ApplicationSettingsException {
if (curatorClient == null) {
synchronized (Factory.class) {
if (curatorClient == null) {
String connectionSting = ServerSettings.getZookeeperConnection();
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy);
}
}
}
return curatorClient;
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project airavata by apache.
the class DbEventManagerZkUtils method getCuratorClient.
/**
* Get curatorFramework instance
* @return
* @throws ApplicationSettingsException
*/
public static CuratorFramework getCuratorClient() throws ApplicationSettingsException {
if (curatorClient == null) {
synchronized (DbEventManagerZkUtils.class) {
if (curatorClient == null) {
String connectionSting = ServerSettings.getZookeeperConnection();
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy);
}
}
}
return curatorClient;
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project airavata by apache.
the class OrchestratorServerHandler method startCurator.
private void startCurator() throws ApplicationSettingsException {
String connectionSting = ServerSettings.getZookeeperConnection();
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy);
curatorClient.start();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project Mycat_plus by coderczp.
the class ZKUtils method createConnection.
private static CuratorFramework createConnection() {
String url = ZkConfig.getInstance().getZkURL();
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
// start connection
curatorFramework.start();
// wait 3 second to establish connect
try {
curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
if (curatorFramework.getZookeeperClient().isConnected()) {
return curatorFramework;
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// fail situation
curatorFramework.close();
throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
Aggregations