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);
}
}
Aggregations