Zookeeper$Status 中的 isAlive() 和 isConnected() 有什么区别? (3.4.5)

问题描述 投票:0回答:2

这是源代码,让我困惑的是状态“close”和“not_connected”。(zookeeper版本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?

apache-zookeeper
2个回答
1
投票

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

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


0
投票

ZooKeeper 会话来自 ZooKeeper 程序员指南

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

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

© www.soinside.com 2019 - 2024. All rights reserved.