Source:
@Override public void process(WatchedEvent event) { LOG.info("Got an event from ZooKeeper " + event.toString()); synchronized (lastStatusVersionMonitor) { switch (event.getType()) { case None: switch (event.getState()) { case SyncConnected: break; case Disconnected: case AuthFailed: case Expired: default: isSynchronizedWithZooKeeper.set(false); sendEventToCoordinateListener( CoordinateListener.Event.NO_CONNECTION_TO_STORAGE, event.toString()); return; } return; case NodeDeleted: isSynchronizedWithZooKeeper.set(false); sendEventToCoordinateListener(CoordinateListener.Event.NOT_OWNER, event.toString()); return; case NodeDataChanged: LOG.fine("Node data changed, check versions."); try { Stat stat = zkClient.getZookeeper().exists(path, this); if (stat == null) { LOG.info("Could not stat path, setting out of synch, will retry claim"); isSynchronizedWithZooKeeper.set(false); } else { LOG.fine("Previous version is " + lastStatusVersion + " now is " + stat.getVersion()); if (stat.getVersion() != lastStatusVersion) { LOG.fine("Version mismatch, sending out of sync."); isSynchronizedWithZooKeeper.set(false); } } } catch (KeeperException e) { LOG.fine("Problems with zookeeper, sending consistencyState out of sync: " + e.getMessage()); isSynchronizedWithZooKeeper.set(false); } catch (InterruptedException e) { LOG.fine("Got interrupted: " + e.getMessage()); isSynchronizedWithZooKeeper.set(false); return; } if (! isSynchronizedWithZooKeeper.get()) { sendEventToCoordinateListener( CoordinateListener.Event.COORDINATE_OUT_OF_SYNC, event.toString()); } return; case NodeChildrenChanged: case NodeCreated: isSynchronizedWithZooKeeper.set(false); sendEventToCoordinateListener( CoordinateListener.Event.COORDINATE_OUT_OF_SYNC, event.toString()); return; } } }

Target:
@Override public void process(WatchedEvent event) { LOG.info("Got an event from ZooKeeper " + event.toString()); synchronized (lastStatusVersionMonitor) { switch (event.getType()) { case None: switch (event.getState()) { case SyncConnected: break; case Disconnected: case AuthFailed: case Expired: default: isSynchronizedWithZooKeeper.set(false); sendEventToCoordinateListener( CoordinateListener.Event.NO_CONNECTION_TO_STORAGE, event.toString()); return; } return; case NodeDeleted: isSynchronizedWithZooKeeper.set(false); sendEventToCoordinateListener(CoordinateListener.Event.NOT_OWNER, event.toString()); return; case NodeDataChanged: LOG.fine("Node data changed, check versions."); boolean verifiedSynchronized = false; try { final Stat stat = zkClient.getZookeeper().exists(path, this); if (stat == null) { LOG.info("Could not stat path, setting out of synch, will retry claim"); } else { LOG.fine("Previous version is " + lastStatusVersion + " now is " + stat.getVersion()); if (stat.getVersion() != lastStatusVersion) { LOG.fine("Version mismatch, sending out of sync."); } else { verifiedSynchronized = true; } } } catch (KeeperException e) { LOG.fine("Problems with zookeeper, sending consistencyState out of sync: " + e.getMessage()); } catch (InterruptedException e) { LOG.fine("Got interrupted: " + e.getMessage()); return; } finally { isSynchronizedWithZooKeeper.set(verifiedSynchronized); } if (verifiedSynchronized) { sendEventToCoordinateListener( CoordinateListener.Event.COORDINATE_OUT_OF_SYNC, event.toString()); } return; case NodeChildrenChanged: case NodeCreated: isSynchronizedWithZooKeeper.set(false); sendEventToCoordinateListener( CoordinateListener.Event.COORDINATE_OUT_OF_SYNC, event.toString()); return; } } }