Search in sources :

Example 1 with ConnectionStateListener

use of com.emc.storageos.coordinator.client.service.ConnectionStateListener in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method start.

@Override
public void start() throws IOException {
    if (_zkConnection.curator().isStarted()) {
        return;
    }
    _zkConnection.curator().getConnectionStateListenable().addListener(new org.apache.curator.framework.state.ConnectionStateListener() {

        @Override
        public void stateChanged(CuratorFramework client, final ConnectionState newState) {
            log.info("Entering stateChanged method : {}", newState);
            _connectionStateWorker.submit(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    Iterator<ConnectionStateListener> it = _listener.iterator();
                    while (it.hasNext()) {
                        ConnectionStateListener listener = it.next();
                        try {
                            switch(newState) {
                                case RECONNECTED:
                                case CONNECTED:
                                    {
                                        listener.connectionStateChanged(ConnectionStateListener.State.CONNECTED);
                                        break;
                                    }
                                case LOST:
                                case SUSPENDED:
                                    {
                                        listener.connectionStateChanged(ConnectionStateListener.State.DISCONNECTED);
                                        break;
                                    }
                            }
                        } catch (Exception e) {
                            log.warn("Connection listener threw", e);
                        }
                    }
                    return null;
                }
            });
        }
    });
    _zkConnection.connect();
    // writing local node to zk
    initInetAddressEntry();
    try {
        checkAndCreateSiteSpecificSection();
        String servicePath = getServicePath();
        EnsurePath path = new EnsurePath(servicePath);
        path.ensure(_zkConnection.curator().getZookeeperClient());
    } catch (Exception e) {
        // desired
        if ((_connectionStateWorker != null) && (!_connectionStateWorker.isShutdown())) {
            _connectionStateWorker.shutdownNow();
        }
        if (nodeChangeWorker != null && !nodeChangeWorker.isShutdown()) {
            nodeChangeWorker.shutdownNow();
        }
        throw CoordinatorException.fatals.errorConnectingCoordinatorService(e);
    }
}
Also used : PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) Callable(java.util.concurrent.Callable) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CuratorFramework(org.apache.curator.framework.CuratorFramework) EnsurePath(org.apache.curator.utils.EnsurePath) ConnectionState(org.apache.curator.framework.state.ConnectionState) ConnectionStateListener(com.emc.storageos.coordinator.client.service.ConnectionStateListener)

Aggregations

ConnectionStateListener (com.emc.storageos.coordinator.client.service.ConnectionStateListener)1 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)1 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Callable (java.util.concurrent.Callable)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 ConnectionState (org.apache.curator.framework.state.ConnectionState)1 EnsurePath (org.apache.curator.utils.EnsurePath)1 KeeperException (org.apache.zookeeper.KeeperException)1