use of org.apache.curator.framework.state.ConnectionStateListener in project chassis by Kixeye.
the class CuratorFrameworkBuilder method buildCuratorWithExhibitor.
private CuratorFramework buildCuratorWithExhibitor(Configuration configuration) {
LOGGER.debug("configuring zookeeper connection through Exhibitor...");
ExhibitorEnsembleProvider ensembleProvider = new KixeyeExhibitorEnsembleProvider(exhibitors, new KixeyeExhibitorRestClient(configuration.getBoolean(EXHIBITOR_USE_HTTPS.getPropertyName())), configuration.getString(EXHIBITOR_URI_PATH.getPropertyName()), configuration.getInt(EXHIBITOR_POLL_INTERVAL.getPropertyName()), new ExponentialBackoffRetry(configuration.getInt(EXHIBITOR_INITIAL_SLEEP_MILLIS.getPropertyName()), configuration.getInt(EXHIBITOR_MAX_RETRIES.getPropertyName()), configuration.getInt(EXHIBITOR_RETRIES_MAX_MILLIS.getPropertyName())));
// ensures that the SERVER list from Exhibitor is already downloaded before curator attempts to connect to zookeeper.
try {
ensembleProvider.pollForInitialEnsemble();
} catch (Exception e) {
try {
Closeables.close(ensembleProvider, true);
} catch (IOException e1) {
}
throw new BootstrapException("Failed to initialize Exhibitor with host(s) " + exhibitors.getHostnames(), e);
}
CuratorFramework curator = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider).retryPolicy(buildZookeeperRetryPolicy(configuration)).build();
curator.getConnectionStateListenable().addListener(new ConnectionStateListener() {
public void stateChanged(CuratorFramework client, ConnectionState newState) {
LOGGER.debug("Connection state to ZooKeeper changed: " + newState);
}
});
return curator;
}
use of org.apache.curator.framework.state.ConnectionStateListener in project chassis by Kixeye.
the class CuratorFrameworkBuilder method buildCuratorWithZookeeperDirectly.
private CuratorFramework buildCuratorWithZookeeperDirectly(Configuration configuration) {
LOGGER.debug("configuring direct zookeeper connection.");
CuratorFramework curator = CuratorFrameworkFactory.newClient(this.zookeeperConnectionString, configuration.getInt(ZOOKEEPER_SESSION_TIMEOUT_MILLIS.getPropertyName()), configuration.getInt(ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS.getPropertyName()), buildZookeeperRetryPolicy(configuration));
curator.getConnectionStateListenable().addListener(new ConnectionStateListener() {
public void stateChanged(CuratorFramework client, ConnectionState newState) {
LOGGER.debug("Connection state to ZooKeeper changed: " + newState);
}
});
return curator;
}
Aggregations