Look at the stop() method of ZooKeeperConnection.