public void handleNewSession() throws Exception
{
// make sure zkclient is connected again
zkClient.waitUntilConnected();
ZkConnection connection = ((ZkConnection) zkClient.getConnection());
ZooKeeper curZookeeper = connection.getZookeeper();
LOG.info("handleNewSession. sessionId: "
+ Long.toHexString(curZookeeper.getSessionId()));
waitExpire.countDown();
}
};
zkClient.subscribeStateChanges(listener);
ZkConnection connection = ((ZkConnection) zkClient.getConnection());
ZooKeeper curZookeeper = connection.getZookeeper();
LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
Watcher watcher = new Watcher()
{
@Override
public void process(WatchedEvent event)
{
LOG.info("Process watchEvent: " + event);
}
};
final ZooKeeper dupZookeeper =
new ZooKeeper(connection.getServers(),
curZookeeper.getSessionTimeout(),
watcher,
curZookeeper.getSessionId(),
curZookeeper.getSessionPasswd());
// wait until connected, then close
while (dupZookeeper.getState() != States.CONNECTED)
{
Thread.sleep(10);
}
dupZookeeper.close();
// make sure session expiry really happens
waitExpire.await();
zkClient.unsubscribeStateChanges(listener);
connection = (ZkConnection) zkClient.getConnection();
curZookeeper = connection.getZookeeper();
// System.err.println("zk: " + oldZookeeper);
LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}