ZooKeeper FAQ tells that ZooKeeper object must be recreated when state becomes SESSION_EXPIRED.
Are there any examples of code that does such reconnection properly? Recipe开发者_开发技巧s folder in zookeeper distro contains two examples of code that both assume that session never expires. This is naïve, because after server gets diconnected from ZooKeeper cluster for 5 minutes, both queue and lock won't work again after connectivity reestablished.
ZkClient does that you can look at the code. It also has a listener implementation where you could register a listener implementation and get a persistent notification when the session expires
精彩评论