List of usage examples for org.apache.zookeeper WatchedEvent getPath
public String getPath()
From source file:org.jc.zk.dpw.DataMonitor.java
@Override public void process(WatchedEvent event) { String path = event.getPath(); switch (event.getType()) { case NodeDataChanged: if (path.equals(this.znodeTime)) { //Time has been updated this.listener.timeZnodeChanged(); } else if (path.equals(this.znodeMaster)) { this.listener.masterZnodeChanged(); } else if (path.equals(this.processHeartBeatZnode)) { this.listener.processHeartBeatZnodeUpdate(); } else if (this.znodeToCreateForUpdates == null && this.cmwUpdateZnodes.contains(event.getPath())) { this.listener.cmwUpdatedUpdateZnode(event.getPath()); } else if (this.znodeToCreateForUpdates != null && this.znodeToCreateForUpdates.equals(event.getPath())) { this.bindToZnodes(this.isActiveMaster); } else if (path.equals(this.amwRequestKillZnode)) { this.listener.amwRequestKillZnodeChanged(); }/*from w ww . ja va 2 s.com*/ break; case None: if (event.getState() == Event.KeeperState.Expired || event.getState() == Event.KeeperState.Disconnected) { this.listener.disconnected(KeeperException.Code.CONNECTIONLOSS.intValue()); } else if (event.getState() == Event.KeeperState.SyncConnected) { this.listener.connected(); } break; case NodeDeleted: if (event.getPath().equals(this.znodeTime)) { this.listener.timeZnodeRemoved(); } else if (event.getPath().equals(this.znodeProcessObserved)) { this.listener.processObservedZnodeRemoved(); } else if (this.cmwUpdateZnodes.contains(event.getPath())) { this.listener.cmwUpdateZnodeRemoved(); } break; case NodeCreated: if (this.ownCMWFailoverZnode != null && this.ownCMWFailoverZnode.equals(event.getPath())) { this.listener.cmwFailoverZnodeCreated(event.getPath()); } else if (this.znodeToCreateForUpdates != null && this.znodeToCreateForUpdates.equals(event.getPath())) { /** * To comply with the old model, where CMWs created update * znode, instead of waiting for AMW to create them, once CMW * detects that update znode was created by AMW, it will * automatically read the data from znode, that is, instead * of invoking callback to notify about the creation of znode * by master, it will proceed to read the content and later * notify CMW about the new data. */ Map<String, String> ctx = new HashMap<>(); ctx.put(ZNODE_TYPE, CMW_UPDATE_NODE); ctx.put(UPDATE_NODE_EVENT, UPDATE_EVENT_IS_CREATE); this.zk.getData(path, this, this, ctx); } else if (this.znodeToCreateForUpdates == null && this.cmwUpdateZnodes.contains(event.getPath())) { this.bindToZnodes(this.isActiveMaster); } else if (event.getPath().equals(this.znodeMaster)) { this.listener.masterZnodeCreated(); } else if (event.getPath().equals(this.znodeTime)) { this.listener.timeZnodeCreated(); } else if (event.getPath().equals(this.znodeProcessObserved)) { this.listener.processObservedZnodeCreated(); } break; } }
From source file:org.jc.zk.dpw.DataMonitorProcesses.java
@Override public void process(WatchedEvent event) { switch (event.getType()) { case NodeCreated: if (event.getPath().equals(this.znodeObserved)) { }/* w ww . ja v a 2 s. co m*/ break; case NodeDataChanged: if (event.getPath().equals(this.znodeTime)) { this.readTimeZnode(); } break; case None: if (event.getState() == Event.KeeperState.Disconnected || event.getState() == Event.KeeperState.Expired) { this.listener.closing(KeeperException.Code.CONNECTIONLOSS.intValue()); } break; case NodeDeleted: if (event.getPath().equals(this.znodeObserved) || event.getPath().equals(this.znodeTime)) { this.listener.closing(KeeperException.Code.CONNECTIONLOSS.intValue()); } break; } }
From source file:org.jc.zk.dpw.TimeDataMonitor.java
@Override public void process(WatchedEvent event) { System.out.print(event.toString()); switch (event.getType()) { case NodeCreated: if (event.getPath().equals(this.znodeForTimeListeners)) { this.listener.timeListenersZnodeCreated(); } else if (event.getPath().equals(this.timeZnodeRemovedFlagZnode)) { this.listener.notificationZnodeCreated(); }//from w w w . j a va 2s. c o m break; case NodeDeleted: if (event.getPath().equals(this.timeZnode)) { this.listener.timeZnodeDeleted(); } else if (event.getPath().equals(this.znodeForTimeListeners)) { this.listener.timeListenersZnodeDeleted(); } else if (event.getPath().equals(this.timeZnodeRemovedFlagZnode)) { this.listener.notificationZnodeRemoved(); } break; case NodeDataChanged: if (event.getPath().equals(this.timeZnode)) { this.listener.timeZnodeChanged(); //this.zk.getData(this.timeZnode, null, this, this.ctx); } else if (event.getPath().equals(this.znodeForTimeListeners)) { this.listener.timeListenersZnodeChanged(); } else if (event.getPath().equals(this.requestAMWKillZnode)) { this.listener.requestAMWKillZnodeChanged(); } break; case None: if (event.getState() == Event.KeeperState.SyncConnected) { this.listener.connected(); } else if (event.getState() == Event.KeeperState.Disconnected || event.getState() == Event.KeeperState.Expired) { this.listener.disconnected(KeeperException.Code.CONNECTIONLOSS.intValue()); } break; } }
From source file:org.jc.zk.process.ProcessWrapperMonitor.java
@Override public void process(WatchedEvent event) { switch (event.getType()) { case None:/*from w ww. j a va 2 s .c o m*/ if (event.getState() == Event.KeeperState.Disconnected || event.getState() == Event.KeeperState.Expired) { this.listener.disconnected(); } else if (event.getState() == Event.KeeperState.SyncConnected) { this.listener.connected(); } break; case NodeCreated: if (event.getPath().equals(this.heartBeatZnode)) { this.listener.pHeartBeatZnodeCreated(); } break; case NodeDeleted: if (event.getPath().equals(this.heartBeatZnode)) { this.listener.pHeartBeatZnodeRemoved(); } break; } }
From source file:org.labs.qbit.election.leader.LeaderProcedure.java
License:Open Source License
@Override public void process(WatchedEvent event) { logger.info("An event occurred for [{}] for process ID [{}]", event.getPath(), processID); if (event.getType() == Watcher.Event.EventType.None) { createZNode();/*from ww w. j a va 2 s.c om*/ } else { String path = event.getPath(); if (path != null && path.equals(zNodeBasePath)) { try { zooKeeper.getChildren(zNodeBasePath, this); } catch (KeeperException e) { logger.error("An error occurred", e); } catch (InterruptedException e) { logger.error("An error occurred", e); } } } }
From source file:org.linkedin.zookeeper.tracker.ZooKeeperTreeTracker.java
License:Apache License
private void raiseError(WatchedEvent event, Throwable th) { Set<ErrorListener> listeners; synchronized (_lock) { listeners = new LinkedHashSet<ErrorListener>(_errorListeners); }//from ww w . j a v a2s. c o m if (!listeners.isEmpty()) { for (ErrorListener listener : listeners) { try { if (log.isDebugEnabled()) log.debug(logString(event.getPath(), "Raising error to " + LangUtils.identityString(listener)), th); listener.onError(event, th); } catch (Throwable th2) { log.warn(logString(event.getPath(), "Error in watcher while executing listener " + LangUtils.identityString(listener) + " (ignored)"), th2); } } } }
From source file:org.neo4j.kernel.ha.zookeeper.ClusterManager.java
License:Open Source License
public void process(WatchedEvent event) { // System.out.println( "Got event: " + event ); String path = event.getPath(); if (path == null) { state = event.getState();//from w w w . j a v a 2 s .com } }
From source file:org.prot.controller.zookeeper.jobs.WatchApp.java
License:Open Source License
@Override public void process(WatchedEvent event) { try {// w w w . j a v a 2s . c om // Check the event type if (event.getType() == EventType.None) return; // Check the path final String path = event.getPath(); if (path == null) return; // Connection to zookeeper ZooKeeper zk = zooHelper.getZooKeeper(); // Extract the AppEntry object Stat stat = new Stat(); byte[] data = zk.getData(path, false, stat); ObjectSerializer serializer = new ObjectSerializer(); AppEntry entry = (AppEntry) serializer.deserialize(data); // The ZooKeeper API cannot remove watches. We have to check here if // the appId is still in the watchlist if (watching.containsKey(entry.appId)) appDeployed(entry.appId); } catch (InterruptedException e) { logger.error("InterruptedException", e); } catch (KeeperException e) { logger.error("KeeperException", e); } finally { // Reschedule this task (install watchers) zooHelper.getQueue().insert(this); } }
From source file:org.prot.controller.zookeeper.jobs.WatchMaster.java
License:Open Source License
@Override public void process(WatchedEvent event) { logger.info("Processing Watcher: " + event.getPath()); zooHelper.getQueue().insert(this); }
From source file:org.rioproject.zookeeper.watcher.ZooKeeperServiceWatcher.java
License:Apache License
public void process(WatchedEvent event) { String path = event.getPath(); if (logger.isDebugEnabled()) logger.debug("{}", event); if (path == null) return;//from ww w.j av a2s. c o m if (event.getType() == Event.EventType.None && event.getState().equals(Event.KeeperState.Expired)) { services.remove(path).serviceFailure(null, path); } else { if (logger.isDebugEnabled()) logger.debug("Path: {}", path); if (services.get(path) != null) { /* Something has changed on the node, let's find out if it still exists */ zooKeeper.exists(path, false, new AsyncCallback.StatCallback() { public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.NONODE.equals(KeeperException.Code.get(rc))) { services.remove(path).serviceFailure(null, path); } } }, null); } } }