@Override public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) { if (connectionState.equals(ConnectionState.CONNECTED) || connectionState.equals(ConnectionState.RECONNECTED)) { isConnected = true; } else if (connectionState.equals(ConnectionState.LOST) || connectionState.equals(ConnectionState.SUSPENDED)) { isConnected = false; } } }
@Override public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) { if (connectionState.equals(ConnectionState.CONNECTED) || connectionState.equals(ConnectionState.RECONNECTED)) { isConnected = true; } else if (connectionState.equals(ConnectionState.LOST) || connectionState.equals(ConnectionState.SUSPENDED)) { isConnected = false; } } }
@Override public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) { if (connectionState.equals(ConnectionState.CONNECTED) || connectionState.equals(ConnectionState.RECONNECTED)) { isConnected = true; } else if (connectionState.equals(ConnectionState.LOST) || connectionState.equals(ConnectionState.SUSPENDED)) { isConnected = false; } } }
public void stateChanged(CuratorFramework client, ConnectionState newState) { try { this.stateLock.lock(); this.stateDisallowed = ConnectionState.CONNECTED.equals(newState) == false && ConnectionState.RECONNECTED.equals(newState) == false; if (this.stateDisallowed) { this.stateCondition.signalAll(); } // end-if (this.stateDisallowed) } finally { this.stateLock.unlock(); } }
@Override public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) { if (_expected.equals(connectionState)) { fire(); } } }
@VisibleForTesting static CuratorFramework createZKClient(ZKClientConfig zkClientConfig, Supplier<Boolean> canRetry, Consumer<Void> expiryHandler) { if (zkClientConfig.isSecureConnectionToZooKeeper()) { ZKTLSUtils.setSecureZKClientProperties(zkClientConfig.getTrustStorePath(), JKSHelper.loadPasswordFrom(zkClientConfig.getTrustStorePasswordPath())); } RetryWrapper retryPolicy = new RetryWrapper(new ExponentialBackoffRetry(zkClientConfig.getInitialSleepInterval(), zkClientConfig.getMaxRetries(), CURATOR_MAX_SLEEP_MS), canRetry); //Create and initialize the curator client framework. CuratorFramework zkClient = CuratorFrameworkFactory.builder() .connectString(zkClientConfig.getConnectionString()) .namespace(zkClientConfig.getNamespace()) .zookeeperFactory(new ZKClientFactory()) .retryPolicy(retryPolicy) .sessionTimeoutMs(zkClientConfig.getSessionTimeoutMs()) .build(); zkClient.start(); zkClient.getConnectionStateListenable().addListener((client1, newState) -> { if (newState.equals(ConnectionState.LOST)) { expiryHandler.accept(null); } }); return zkClient; }
if (newState.equals(ConnectionState.LOST)) { sessionExpiryFuture.complete(null);