Search in sources :

Example 1 with RetryUntilElapsed

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryUntilElapsed(org.apache.curator.retry.RetryUntilElapsed) UnhandledErrorListener(org.apache.curator.framework.api.UnhandledErrorListener) ConnectionState(org.apache.curator.framework.state.ConnectionState) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener) IOException(java.io.IOException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException)

Aggregations

CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 IOException (java.io.IOException)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 UnhandledErrorListener (org.apache.curator.framework.api.UnhandledErrorListener)1 ConnectionState (org.apache.curator.framework.state.ConnectionState)1 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)1 RetryUntilElapsed (org.apache.curator.retry.RetryUntilElapsed)1