1

这是源代码,让我感到困惑的是状态“关闭”和“未连接”。(动物园管理员版本 r3.4.5)

public enum States {
    CONNECTING, ASSOCIATING, CONNECTED, CONNECTEDREADONLY,
    CLOSED, AUTH_FAILED, NOT_CONNECTED;

    public boolean isAlive() {
        return this != CLOSED && this != AUTH_FAILED;
    }

    /**
     * Returns whether we are connected to a server (which
     * could possibly be read-only, if this client is allowed
     * to go to read-only mode)
     * */
    public boolean isConnected() {
        return this == CONNECTED || this == CONNECTEDREADONLY;
    }
}

如果会话过期(观察者捕获过期事件),是否意味着 isAlive() 将返回 false?

4

2 回答 2

1

我可以给你看一个例子来说明清楚。

如果 zookeeper 客户端状态是 CONNECTING,它是 ALIVE 但不是 CONNECTED。

于 2014-04-10T07:11:37.473 回答
0

ZooKeeper 会话状态来自ZooKeeper 程序员指南

ZooKeeper 会话

如果会话过期(观察者捕获过期事件),是否意味着 isAlive() 将返回 false?

因此,如果会话过期,isAlive() 将返回 false。

于 2013-12-09T02:09:31.297 回答