这是源代码,让我感到困惑的是状态“已关闭”和“未连接”。(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?
答案 0 :(得分:0)
ZooKeeper会话来自ZooKeeper Programmer's Guide
如果会话过期(观察者捕获过期事件),是否意味着isAlive()将返回false?
因此,如果会话过期,isAlive()将返回false。
答案 1 :(得分:0)
我可以向你展示一个明确的例子。
如果zookeeper客户端状态在CONNECTING中,则它是ALIVE但不是CONNECTED。