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


Java States.CONNECTEDREADONLY屬性代碼示例

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


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

示例1: onConnected

/**
 * Callback invoked by the ClientCnxnSocket once a connection has been
 * established.
 * 
 * @param _negotiatedSessionTimeout
 * @param _sessionId
 * @param _sessionPasswd
 * @param isRO
 * @throws IOException
 */
void onConnected(int _negotiatedSessionTimeout, long _sessionId,
        byte[] _sessionPasswd, boolean isRO) throws IOException {
    negotiatedSessionTimeout = _negotiatedSessionTimeout;
    if (negotiatedSessionTimeout <= 0) {
        state = States.CLOSED;

        eventThread.queueEvent(new WatchedEvent(
                Watcher.Event.EventType.None,
                Watcher.Event.KeeperState.Expired, null));
        eventThread.queueEventOfDeath();

        String warnInfo;
        warnInfo = "Unable to reconnect to ZooKeeper service, session 0x"
            + Long.toHexString(sessionId) + " has expired";
        LOG.warn(warnInfo);
        throw new SessionExpiredException(warnInfo);
    }
    if (!readOnly && isRO) {
        LOG.error("Read/write client got connected to read-only server");
    }
    readTimeout = negotiatedSessionTimeout * 2 / 3;
    connectTimeout = negotiatedSessionTimeout / hostProvider.size();
    hostProvider.onConnected();
    sessionId = _sessionId;
    sessionPasswd = _sessionPasswd;
    state = (isRO) ?
            States.CONNECTEDREADONLY : States.CONNECTED;
    seenRwServerBefore |= !isRO;
    LOG.info("Session establishment complete on server "
            + clientCnxnSocket.getRemoteSocketAddress()
            + ", sessionid = 0x" + Long.toHexString(sessionId)
            + ", negotiated timeout = " + negotiatedSessionTimeout
            + (isRO ? " (READ-ONLY mode)" : ""));
    KeeperState eventState = (isRO) ?
            KeeperState.ConnectedReadOnly : KeeperState.SyncConnected;
    eventThread.queueEvent(new WatchedEvent(
            Watcher.Event.EventType.None,
            eventState, null));
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:49,代碼來源:ClientCnxn.java

示例2: onConnected

/**
 * Callback invoked by the ClientCnxnSocket once a connection has been
 * established.
 * 
 * @param _negotiatedSessionTimeout
 * @param _sessionId
 * @param _sessionPasswd
 * @param isRO
 * @throws IOException
 */
void onConnected(int _negotiatedSessionTimeout, long _sessionId,
        byte[] _sessionPasswd, boolean isRO) throws IOException {
    negotiatedSessionTimeout = _negotiatedSessionTimeout;
    if (negotiatedSessionTimeout <= 0) {
        state = States.CLOSED;

        eventThread.queueEvent(new WatchedEvent(
                Watcher.Event.EventType.None,
                Watcher.Event.KeeperState.Expired, null));
        eventThread.queueEventOfDeath();
        throw new SessionExpiredException(
                "Unable to reconnect to ZooKeeper service, session 0x"
                        + Long.toHexString(sessionId) + " has expired");
    }
    if (!readOnly && isRO) {
        LOG.error("Read/write client got connected to read-only server");
    }
    readTimeout = negotiatedSessionTimeout * 2 / 3;
    connectTimeout = negotiatedSessionTimeout / hostProvider.size();
    hostProvider.onConnected();
    sessionId = _sessionId;
    sessionPasswd = _sessionPasswd;
    state = (isRO) ?
            States.CONNECTEDREADONLY : States.CONNECTED;
    seenRwServerBefore |= !isRO;
    LOG.info("Session establishment complete on server "
            + clientCnxnSocket.getRemoteSocketAddress()
            + ", sessionid = 0x" + Long.toHexString(sessionId)
            + ", negotiated timeout = " + negotiatedSessionTimeout
            + (isRO ? " (READ-ONLY mode)" : ""));
    KeeperState eventState = (isRO) ?
            KeeperState.ConnectedReadOnly : KeeperState.SyncConnected;
    eventThread.queueEvent(new WatchedEvent(
            Watcher.Event.EventType.None,
            eventState, null));
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:46,代碼來源:ClientCnxn.java

示例3: testConnectionEvents

/**
 * Ensures that upon connection to a read-only server client receives
 * ConnectedReadOnly state notification.
 */
@Test
public void testConnectionEvents() throws Exception {
    final List<KeeperState> states = new ArrayList<KeeperState>();
    ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            new Watcher() {
                public void process(WatchedEvent event) {
                    states.add(event.getState());
                }
            }, true);
    boolean success = false;
    for (int i = 0; i < 30; i++) {
        try {
            zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
            success=true;
            break;
        } catch(KeeperException.ConnectionLossException e) {
            Thread.sleep(1000);               
        }            
    }
    Assert.assertTrue("Did not succeed in connecting in 30s", success);

    // kill peer and wait no more than 5 seconds for read-only server
    // to be started (which should take one tickTime (2 seconds))
    qu.shutdown(2);
    long start = System.currentTimeMillis();
    while (!(zk.getState() == States.CONNECTEDREADONLY)) {
        Thread.sleep(200);
        Assert.assertTrue("Can't connect to the server", System
                .currentTimeMillis()
                - start < 5000);
    }

    // At this point states list should contain, in the given order,
    // SyncConnected, Disconnected, and ConnectedReadOnly states
    Assert.assertTrue("ConnectedReadOnly event wasn't received", states
            .get(2) == KeeperState.ConnectedReadOnly);
    zk.close();
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:43,代碼來源:ReadOnlyModeTest.java

示例4: onConnected

/**
 * Callback invoked by the ClientCnxnSocket once a connection has been
 * established.
 *
 * @param _negotiatedSessionTimeout
 * @param _sessionId
 * @param _sessionPasswd
 * @param isRO
 * @throws IOException
 */
void onConnected(int _negotiatedSessionTimeout, long _sessionId,
                 byte[] _sessionPasswd, boolean isRO) throws IOException {
    negotiatedSessionTimeout = _negotiatedSessionTimeout;
    if (negotiatedSessionTimeout <= 0) {
        state = States.CLOSED;

        eventThread.queueEvent(new WatchedEvent(
                Watcher.Event.EventType.None,
                Watcher.Event.KeeperState.Expired, null));
        eventThread.queueEventOfDeath();
        throw new SessionExpiredException(
                "Unable to reconnect to ZooKeeper service, session 0x"
                        + Long.toHexString(sessionId) + " has expired");
    }
    if (!readOnly && isRO) {
        LOG.error("Read/write client got connected to read-only server");
    }
    readTimeout = negotiatedSessionTimeout * 2 / 3;
    connectTimeout = negotiatedSessionTimeout / hostProvider.size();
    hostProvider.onConnected();
    sessionId = _sessionId;
    sessionPasswd = _sessionPasswd;
    state = (isRO) ?
            States.CONNECTEDREADONLY : States.CONNECTED;
    seenRwServerBefore |= !isRO;
    LOG.info("Session establishment complete on server "
            + clientCnxnSocket.getRemoteSocketAddress()
            + ", sessionid = 0x" + Long.toHexString(sessionId)
            + ", negotiated timeout = " + negotiatedSessionTimeout
            + (isRO ? " (READ-ONLY mode)" : ""));
    KeeperState eventState = (isRO) ?
            KeeperState.ConnectedReadOnly : KeeperState.SyncConnected;
    eventThread.queueEvent(new WatchedEvent(
            Watcher.Event.EventType.None,
            eventState, null));
}
 
開發者ID:blentle,項目名稱:zookeeper-src-learning,代碼行數:46,代碼來源:ClientCnxn.java

示例5: testConnectionEvents

/**
 * Ensures that upon connection to a read-only server client receives
 * ConnectedReadOnly state notification.
 */
@Test(timeout = 90000)
public void testConnectionEvents() throws Exception {
    final List<KeeperState> states = new ArrayList<KeeperState>();
    ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            new Watcher() {
                public void process(WatchedEvent event) {
                    states.add(event.getState());
                }
            }, true);
    boolean success = false;
    for (int i = 0; i < 30; i++) {
        try {
            zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
            success=true;
            break;
        } catch(KeeperException.ConnectionLossException e) {
            Thread.sleep(1000);               
        }            
    }
    Assert.assertTrue("Did not succeed in connecting in 30s", success);

    // kill peer and wait no more than 5 seconds for read-only server
    // to be started (which should take one tickTime (2 seconds))
    qu.shutdown(2);
    long start = System.currentTimeMillis();
    while (!(zk.getState() == States.CONNECTEDREADONLY)) {
        Thread.sleep(200);
        // FIXME this was originally 5 seconds, but realistically, on random/slow/virt hosts, there is no way to guarantee this
        Assert.assertTrue("Can't connect to the server", System
                .currentTimeMillis()
                - start < 30000);
    }

    // At this point states list should contain, in the given order,
    // SyncConnected, Disconnected, and ConnectedReadOnly states
    Assert.assertTrue("ConnectedReadOnly event wasn't received", states
            .get(2) == KeeperState.ConnectedReadOnly);
    zk.close();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:44,代碼來源:ReadOnlyModeTest.java

示例6: testConnectionEvents

/**
 * Ensures that upon connection to a read-only server client receives
 * ConnectedReadOnly state notification.
 */
@Test
public void testConnectionEvents() throws Exception {
    final List<KeeperState> states = new ArrayList<KeeperState>();
    ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            new Watcher() {
                public void process(WatchedEvent event) {
                    states.add(event.getState());
                }
            }, true);
    boolean success = false;
    for (int i = 0; i < 30; i++) {
        try {
            zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
            success=true;
            break;
        } catch(KeeperException.ConnectionLossException e) {
            Thread.sleep(1000);               
        }            
    }
    Assert.assertTrue("Did not succeed in connecting in 30s", success);

    // kill peer and wait no more than 5 seconds for read-only server
    // to be started (which should take one tickTime (2 seconds))
    qu.shutdown(2);
    long start = System.currentTimeMillis();
    while (!(zk.getState() == States.CONNECTEDREADONLY)) {
        Thread.sleep(200);
        // FIXME this was originally 5 seconds, but realistically, on random/slow/virt hosts, there is no way to guarantee this
        Assert.assertTrue("Can't connect to the server", System
                .currentTimeMillis()
                - start < 30000);
    }

    // At this point states list should contain, in the given order,
    // SyncConnected, Disconnected, and ConnectedReadOnly states
    Assert.assertTrue("ConnectedReadOnly event wasn't received", states
            .get(2) == KeeperState.ConnectedReadOnly);
    zk.close();
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:44,代碼來源:ReadOnlyModeTest.java

示例7: testConnectionEvents

/**
 * Ensures that upon connection to a read-only server client receives
 * ConnectedReadOnly state notification.
 */
@Test(timeout = 90000)
public void testConnectionEvents() throws Exception {
    final List<KeeperState> states = new ArrayList<KeeperState>();
    ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            new Watcher() {
                public void process(WatchedEvent event) {
                    states.add(event.getState());
                }
            }, true);
    boolean success = false;
    for (int i = 0; i < 30; i++) {
        try {
            zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
            success=true;
            break;
        } catch(KeeperException.ConnectionLossException e) {
            Thread.sleep(1000);               
        }            
    }
    Assert.assertTrue("Did not succeed in connecting in 30s", success);

    // kill peer and wait no more than 5 seconds for read-only server
    // to be started (which should take one tickTime (2 seconds))
    qu.shutdown(2);

    // Re-connect the client (in case we were connected to the shut down
    // server and the local session was not persisted).
    zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            new Watcher() {
                public void process(WatchedEvent event) {
                    states.add(event.getState());
                }
            }, true);
    long start = Time.currentElapsedTime();
    while (!(zk.getState() == States.CONNECTEDREADONLY)) {
        Thread.sleep(200);
        // FIXME this was originally 5 seconds, but realistically, on random/slow/virt hosts, there is no way to guarantee this
        Assert.assertTrue("Can't connect to the server",
                          Time.currentElapsedTime() - start < 30000);
    }

    // At this point states list should contain, in the given order,
    // SyncConnected, Disconnected, and ConnectedReadOnly states
    Assert.assertTrue("ConnectedReadOnly event wasn't received", states
            .get(2) == KeeperState.ConnectedReadOnly);
    zk.close();
}
 
開發者ID:sereca,項目名稱:SecureKeeper,代碼行數:52,代碼來源:ReadOnlyModeTest.java


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