use of org.apache.curator.framework.state.ConnectionState in project flink by apache.
the class ZooKeeperCheckpointIDCounter method getAndIncrement.
@Override
public long getAndIncrement() throws Exception {
while (true) {
ConnectionState connState = connStateListener.getLastState();
if (connState != null) {
throw new IllegalStateException("Connection state: " + connState);
}
VersionedValue<Integer> current = sharedCount.getVersionedValue();
int newCount = current.getValue() + 1;
if (newCount < 0) {
// overflow and wrap around
throw new Exception("Checkpoint counter overflow. ZooKeeper checkpoint counter only supports " + "checkpoints Ids up to " + Integer.MAX_VALUE);
}
if (sharedCount.trySetCount(current, newCount)) {
return current.getValue();
}
}
}
use of org.apache.curator.framework.state.ConnectionState in project flink by apache.
the class ZooKeeperCheckpointIDCounter method setCount.
@Override
public void setCount(long newId) throws Exception {
ConnectionState connState = connStateListener.getLastState();
if (connState != null) {
throw new IllegalStateException("Connection state: " + connState);
}
if (newId > Integer.MAX_VALUE) {
throw new IllegalArgumentException("ZooKeeper checkpoint counter only supports " + "checkpoints Ids up to " + Integer.MAX_VALUE + ", but given value is" + newId);
}
sharedCount.setCount((int) newId);
}
use of org.apache.curator.framework.state.ConnectionState 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;
}
use of org.apache.curator.framework.state.ConnectionState 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;
}
Aggregations