Search in sources :

Example 1 with ConnectionState

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();
        }
    }
}
Also used : ConnectionState(org.apache.curator.framework.state.ConnectionState)

Example 2 with ConnectionState

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);
}
Also used : ConnectionState(org.apache.curator.framework.state.ConnectionState)

Example 3 with ConnectionState

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;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ConnectionState(org.apache.curator.framework.state.ConnectionState) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener)

Example 4 with ConnectionState

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;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) IOException(java.io.IOException) ConnectionState(org.apache.curator.framework.state.ConnectionState) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener)

Aggregations

ConnectionState (org.apache.curator.framework.state.ConnectionState)4 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)2 BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)1 IOException (java.io.IOException)1 ExhibitorEnsembleProvider (org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider)1 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)1