当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionState.CONNECTED属性代码示例

本文整理汇总了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();
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:18,代码来源:RedirectorCuratorFramework.java

示例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();
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:17,代码来源:ZookeeperServiceRegistry.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:20,代码来源:ServiceDiscoveryImpl.java

示例4: stateChanged

@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
  if(newState == ConnectionState.CONNECTED) {
    ZKClusterCoordinator.this.initialConnection.countDown();
    client.getConnectionStateListenable().removeListener(this);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:7,代码来源:ZKClusterCoordinator.java

示例5: isConnected

@Override
public boolean isConnected() {
    return client != null && client.isStarted() &&
            currentConnectionState != null &&
            (currentConnectionState == ConnectionState.CONNECTED ||
            currentConnectionState == ConnectionState.RECONNECTED);
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:7,代码来源:ZookeeperConnector.java

示例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;
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:11,代码来源:ZookeeperConnector.java

示例7: stateChanged

@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
  if(newState == ConnectionState.CONNECTED) {
    ZKClusterClient.this.initialConnection.countDown();
    client.getConnectionStateListenable().removeListener(this);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:7,代码来源:ZKClusterClient.java

示例8: listen

@Override
public void listen(ServiceDescription description) throws Exception {
    if (connectionState != ConnectionState.CONNECTED) {
        listenServices.add(description);
    } else {
        internalListen(description);
    }
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:8,代码来源:ZookeeperServiceDiscovery.java

示例9: register

@Override
public void register(ServiceDescription service) throws Exception {
    services.put(service.getId(), service);
    if (connectionState == ConnectionState.CONNECTED) {
        internalRegister(service);
    }
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:7,代码来源:ZookeeperServiceRegistry.java

示例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();
      }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:14,代码来源:ManagedCuratorFramework.java

示例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());
    }
}
 
开发者ID:rackerlabs,项目名称:blueflood,代码行数:13,代码来源:ZKShardLockManager.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:53,代码来源:CuratorFrameworkImpl.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:44,代码来源:TestFrameworkBackground.java


注:本文中的org.apache.curator.framework.state.ConnectionState.CONNECTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。