當前位置: 首頁>>代碼示例>>Java>>正文


Java States.CONNECTING屬性代碼示例

本文整理匯總了Java中org.apache.zookeeper.ZooKeeper.States.CONNECTING屬性的典型用法代碼示例。如果您正苦於以下問題:Java States.CONNECTING屬性的具體用法?Java States.CONNECTING怎麽用?Java States.CONNECTING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.zookeeper.ZooKeeper.States的用法示例。


在下文中一共展示了States.CONNECTING屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startConnect

private void startConnect() throws IOException {
    if(!isFirstConnect){
        try {
            Thread.sleep(r.nextInt(1000));
        } catch (InterruptedException e) {
            LOG.warn("Unexpected exception", e);
        }
    }
    state = States.CONNECTING;

    InetSocketAddress addr;
    if (rwServerAddress != null) {
        addr = rwServerAddress;
        rwServerAddress = null;
    } else {
        addr = hostProvider.next(1000);
    }

    LOG.info("Opening socket connection to server " + addr);

    setName(getName().replaceAll("\\(.*\\)",
            "(" + addr.getHostName() + ":" + addr.getPort() + ")"));

    clientCnxnSocket.connect(addr);
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:25,代碼來源:ClientCnxn.java

示例2: startConnect

private void startConnect() throws IOException {
    state = States.CONNECTING;

    InetSocketAddress addr;
    if (rwServerAddress != null) {
        addr = rwServerAddress;
        rwServerAddress = null;
    } else {
        addr = hostProvider.next(1000);
    }

    setName(getName().replaceAll("\\(.*\\)",
            "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
    if (ZooKeeperSaslClient.isEnabled()) {
        try {
            String principalUserName = System.getProperty(
                    ZK_SASL_CLIENT_USERNAME, "zookeeper");
            zooKeeperSaslClient =
                new ZooKeeperSaslClient(
                        principalUserName+"/"+addr.getHostName());
        } catch (LoginException e) {
            // An authentication error occurred when the SASL client tried to initialize:
            // for Kerberos this means that the client failed to authenticate with the KDC.
            // This is different from an authentication error that occurs during communication
            // with the Zookeeper server, which is handled below.
            LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without "
              + "SASL authentication, if Zookeeper server allows it.");
            eventThread.queueEvent(new WatchedEvent(
              Watcher.Event.EventType.None,
              Watcher.Event.KeeperState.AuthFailed, null));
            saslLoginFailed = true;
        }
    }
    logStartConnect(addr);

    clientCnxnSocket.connect(addr);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:37,代碼來源:ClientCnxn.java

示例3: waitUntilConnected

public static void waitUntilConnected(ZooKeeper zooKeeper) {
    CountDownLatch connectedLatch = new CountDownLatch(1);
    Watcher watcher = new ConnectedWatcher(connectedLatch);
    zooKeeper.register(watcher);
    if (States.CONNECTING == zooKeeper.getState()) {
        try {
            connectedLatch.await();
        } catch (InterruptedException e) {
            throw new IllegalStateException(e);
        }
    }
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:12,代碼來源:ZkHelper.java

示例4: SendThread

SendThread(ClientCnxnSocket clientCnxnSocket) {
    super(makeThreadName("-SendThread()"));
    state = States.CONNECTING;
    this.clientCnxnSocket = clientCnxnSocket;
    setUncaughtExceptionHandler(uncaughtExceptionHandler);
    setDaemon(true);
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:7,代碼來源:ClientCnxn.java

示例5: startConnect

private void startConnect() throws IOException {
    state = States.CONNECTING;

    InetSocketAddress addr;
    if (rwServerAddress != null) {
        addr = rwServerAddress;
        rwServerAddress = null;
    } else {
        addr = hostProvider.next(1000);
    }

    setName(getName().replaceAll("\\(.*\\)",
            "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
    try {
        zooKeeperSaslClient = new ZooKeeperSaslClient("zookeeper/"+addr.getHostName());
    } catch (LoginException e) {
        // An authentication error occurred when the SASL client tried to initialize:
        // for Kerberos this means that the client failed to authenticate with the KDC.
        // This is different from an authentication error that occurs during communication
        // with the Zookeeper server, which is handled below.
        LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without "
          + "SASL authentication, if Zookeeper server allows it.");
        eventThread.queueEvent(new WatchedEvent(
          Watcher.Event.EventType.None,
          Watcher.Event.KeeperState.AuthFailed, null));
        saslLoginFailed = true;
    }
    logStartConnect(addr);

    clientCnxnSocket.connect(addr);
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:31,代碼來源:ClientCnxn.java

示例6: startConnect

private void startConnect() throws IOException {
    state = States.CONNECTING;

    InetSocketAddress addr;
    if (rwServerAddress != null) {
        addr = rwServerAddress;
        rwServerAddress = null;
    } else {
        addr = hostProvider.next(1000);
    }

    setName(getName().replaceAll("\\(.*\\)",
            "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
    try {
        zooKeeperSaslClient = new ZooKeeperSaslClient("zookeeper/" + addr.getHostName());
    } catch (LoginException e) {
        // An authentication error occurred when the SASL client tried to initialize:
        // for Kerberos this means that the client failed to authenticate with the KDC.
        // This is different from an authentication error that occurs during communication
        // with the Zookeeper server, which is handled below.
        LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without "
                + "SASL authentication, if Zookeeper server allows it.");
        eventThread.queueEvent(new WatchedEvent(
                Watcher.Event.EventType.None,
                Watcher.Event.KeeperState.AuthFailed, null));
        saslLoginFailed = true;
    }
    logStartConnect(addr);

    clientCnxnSocket.connect(addr);
}
 
開發者ID:blentle,項目名稱:zookeeper-src-learning,代碼行數:31,代碼來源:ClientCnxn.java

示例7: SendThread

SendThread(ClientCnxnSocket clientCnxnSocket) {
    super(makeThreadName("-SendThread()"));
    state = States.CONNECTING;
    this.clientCnxnSocket = clientCnxnSocket;
    setDaemon(true);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:6,代碼來源:ClientCnxn.java

示例8: testClientSessionExpired

/**
 * See HBASE-1232 and http://wiki.apache.org/hadoop/ZooKeeper/FAQ#4.
 * @throws IOException
 * @throws InterruptedException
 */
// fails frequently, disabled for now, see HBASE-6406
//@Test
public void testClientSessionExpired() throws Exception {
  Configuration c = new Configuration(TEST_UTIL.getConfiguration());

  // We don't want to share the connection as we will check its state
  c.set(HConstants.HBASE_CLIENT_INSTANCE_ID, "1111");

  HConnection connection = HConnectionManager.getConnection(c);

  ZooKeeperWatcher connectionZK = getZooKeeperWatcher(connection);
  LOG.info("ZooKeeperWatcher= 0x"+ Integer.toHexString(
    connectionZK.hashCode()));
  LOG.info("getRecoverableZooKeeper= 0x"+ Integer.toHexString(
    connectionZK.getRecoverableZooKeeper().hashCode()));
  LOG.info("session="+Long.toHexString(
    connectionZK.getRecoverableZooKeeper().getSessionId()));

  TEST_UTIL.expireSession(connectionZK);

  LOG.info("Before using zkw state=" +
    connectionZK.getRecoverableZooKeeper().getState());
  // provoke session expiration by doing something with ZK
  try {
    connectionZK.getRecoverableZooKeeper().getZooKeeper().exists(
      "/1/1", false);
  } catch (KeeperException ignored) {
  }

  // Check that the old ZK connection is closed, means we did expire
  States state = connectionZK.getRecoverableZooKeeper().getState();
  LOG.info("After using zkw state=" + state);
  LOG.info("session="+Long.toHexString(
    connectionZK.getRecoverableZooKeeper().getSessionId()));

  // It's asynchronous, so we may have to wait a little...
  final long limit1 = System.currentTimeMillis() + 3000;
  while (System.currentTimeMillis() < limit1 && state != States.CLOSED){
    state = connectionZK.getRecoverableZooKeeper().getState();
  }
  LOG.info("After using zkw loop=" + state);
  LOG.info("ZooKeeper should have timed out");
  LOG.info("session="+Long.toHexString(
    connectionZK.getRecoverableZooKeeper().getSessionId()));

  // It's surprising but sometimes we can still be in connected state.
  // As it's known (even if not understood) we don't make the the test fail
  // for this reason.)
  // Assert.assertTrue("state=" + state, state == States.CLOSED);

  // Check that the client recovered
  ZooKeeperWatcher newConnectionZK = getZooKeeperWatcher(connection);

  States state2 = newConnectionZK.getRecoverableZooKeeper().getState();
  LOG.info("After new get state=" +state2);

  // As it's an asynchronous event we may got the same ZKW, if it's not
  //  yet invalidated. Hence this loop.
  final long limit2 = System.currentTimeMillis() + 3000;
  while (System.currentTimeMillis() < limit2 &&
    state2 != States.CONNECTED && state2 != States.CONNECTING) {

    newConnectionZK = getZooKeeperWatcher(connection);
    state2 = newConnectionZK.getRecoverableZooKeeper().getState();
  }
  LOG.info("After new get state loop=" + state2);

  Assert.assertTrue(
    state2 == States.CONNECTED || state2 == States.CONNECTING);

  connection.close();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:77,代碼來源:TestZooKeeper.java


注:本文中的org.apache.zookeeper.ZooKeeper.States.CONNECTING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。