本文整理汇总了Java中org.apache.curator.framework.state.ConnectionState.CONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectionState.CONNECTED属性的具体用法?Java ConnectionState.CONNECTED怎么用?Java ConnectionState.CONNECTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.curator.framework.state.ConnectionState
的用法示例。
在下文中一共展示了ConnectionState.CONNECTED属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.CONNECTED) {
isConnected.set(true);
if (!isFirstConnection.get()) {
for (ConnectionStateListener listener : listenerStateProxy.getListeners()) {
listener.stateChanged(client, ConnectionState.RECONNECTED);
}
}
return;
}
if (newState == ConnectionState.LOST) {
isConnected.set(false);
isFirstConnection.set(false);
retryConnection();
}
}
示例2: destroy
@Override
public void destroy() {
if (connectionState == ConnectionState.CONNECTED) {
for (ServiceDescription service : services.values()) {
String path = pathForProvider(service.getName(), service.getId());
try {
client.delete().forPath(path);
} catch (Exception ignore) {
// ignore
}
}
}
services.clear();
client.getConnectionStateListenable().removeListener(connectionStateListener);
client.close();
}
示例3: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
if ( (newState == ConnectionState.RECONNECTED) || (newState == ConnectionState.CONNECTED) )
{
try
{
log.debug("Re-registering due to reconnection");
reRegisterServices();
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
catch ( Exception e )
{
log.error("Could not re-register instances after reconnection", e);
}
}
}
示例4: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if(newState == ConnectionState.CONNECTED) {
ZKClusterCoordinator.this.initialConnection.countDown();
client.getConnectionStateListenable().removeListener(this);
}
}
示例5: isConnected
@Override
public boolean isConnected() {
return client != null && client.isStarted() &&
currentConnectionState != null &&
(currentConnectionState == ConnectionState.CONNECTED ||
currentConnectionState == ConnectionState.RECONNECTED);
}
示例6: checkConnection
private void checkConnection() throws KeeperException.ConnectionLossException {
if (client != null &&
currentConnectionState != null &&
currentConnectionState != ConnectionState.CONNECTED &&
currentConnectionState != ConnectionState.RECONNECTED) {
KeeperException.ConnectionLossException exception = new KeeperException.ConnectionLossException();
Metrics.reportZookeeperConnectionIssue(exception);
throw exception;
}
}
示例7: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if(newState == ConnectionState.CONNECTED) {
ZKClusterClient.this.initialConnection.countDown();
client.getConnectionStateListenable().removeListener(this);
}
}
示例8: listen
@Override
public void listen(ServiceDescription description) throws Exception {
if (connectionState != ConnectionState.CONNECTED) {
listenServices.add(description);
} else {
internalListen(description);
}
}
示例9: register
@Override
public void register(ServiceDescription service) throws Exception {
services.put(service.getId(), service);
if (connectionState == ConnectionState.CONNECTED) {
internalRegister(service);
}
}
示例10: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.CONNECTED) {
if (registration == null) {
registration = bundleContext.registerService(CuratorFramework.class, curator, null);
}
}
for (ConnectionStateListener listener : connectionStateListeners) {
listener.stateChanged(client, newState);
}
if (newState == ConnectionState.LOST) {
run();
}
}
示例11: stateChanged
public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
log.info("Connection to Zookeeper toggled to state " + connectionState.toString());
connected = connectionState == ConnectionState.CONNECTED || connectionState == ConnectionState.RECONNECTED;
if (connectionState == ConnectionState.LOST) {
log.error("Connection to Zookeeper toggled to state " + connectionState.toString());
this.handleZookeeperConnectionFailed();
} else if (connectionState == ConnectionState.RECONNECTED) {
log.info("Reconnected to zookeeper, forcing lock scavenge");
forceLockScavenge();
} else {
log.info("Connection to Zookeeper toggled to state " + connectionState.toString());
}
}
示例12: start
@Override
public void start()
{
log.info("Starting");
if ( !state.compareAndSet(CuratorFrameworkState.LATENT, CuratorFrameworkState.STARTED) )
{
throw new IllegalStateException("Cannot be started more than once");
}
try
{
connectionStateManager.start(); // ordering dependency - must be called before client.start()
final ConnectionStateListener listener = new ConnectionStateListener()
{
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
if ( ConnectionState.CONNECTED == newState || ConnectionState.RECONNECTED == newState )
{
logAsErrorConnectionErrors.set(true);
}
}
};
this.getConnectionStateListenable().addListener(listener);
client.start();
executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
executorService.submit(new Callable<Object>()
{
@Override
public Object call() throws Exception
{
backgroundOperationsLoop();
return null;
}
});
if ( ensembleTracker != null )
{
ensembleTracker.start();
}
log.info(schemaSet.toDocumentation());
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
handleBackgroundOperationException(null, e);
}
}
示例13: testListenerConnectedAtStart
@Test
public void testListenerConnectedAtStart() throws Exception
{
server.stop();
Timing timing = new Timing(2);
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryNTimes(0, 0));
try
{
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
final CountDownLatch connectedLatch = new CountDownLatch(1);
final AtomicBoolean firstListenerAction = new AtomicBoolean(true);
final AtomicReference<ConnectionState> firstListenerState = new AtomicReference<>();
ConnectionStateListener listener = (client1, newState) ->
{
if ( firstListenerAction.compareAndSet(true, false) )
{
firstListenerState.set(newState);
System.out.println("First listener state is " + newState);
}
if ( newState == ConnectionState.CONNECTED )
{
connectedLatch.countDown();
}
};
client.getConnectionStateListenable().addListener(listener);
// due to CURATOR-72, this was causing a LOST event to precede the CONNECTED event
async.create().forPath("/foo");
server.restart();
Assert.assertTrue(timing.awaitLatch(connectedLatch));
Assert.assertFalse(firstListenerAction.get());
ConnectionState firstconnectionState = firstListenerState.get();
Assert.assertEquals(firstconnectionState, ConnectionState.CONNECTED, "First listener state MUST BE CONNECTED but is " + firstconnectionState);
}
finally
{
CloseableUtils.closeQuietly(client);
}
}