Java Code Examples for org.apache.zookeeper.Watcher.Event.EventType#NodeDeleted
The following examples show how to use
org.apache.zookeeper.Watcher.Event.EventType#NodeDeleted .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZkClient.java From DDMQ with Apache License 2.0 | 6 votes |
private void processDataOrChildChange(WatchedEvent event) { final String path = event.getPath(); if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDeleted) { Set<IZkChildListener> childListeners = _childListener.get(path); if (childListeners != null && !childListeners.isEmpty()) { fireChildChangedEvents(path, childListeners); } } if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated) { Set<IZkDataListener> listeners = _dataListener.get(path); if (listeners != null && !listeners.isEmpty()) { fireDataChangedEvents(event.getPath(), listeners); } } }
Example 2
Source File: ZkClient.java From helix with Apache License 2.0 | 6 votes |
private void processDataOrChildChange(WatchedEvent event, long notificationTime) { final String path = event.getPath(); final boolean pathExists = event.getType() != EventType.NodeDeleted; if (EventType.NodeDeleted == event.getType()) { LOG.debug("Event NodeDeleted: {}", event.getPath()); } if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDeleted) { Set<IZkChildListener> childListeners = _childListener.get(path); if (childListeners != null && !childListeners.isEmpty()) { // TODO recording child changed event propagation latency as well. Note this change will // introduce additional ZK access. fireChildChangedEvents(path, childListeners, pathExists); } } if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated) { Set<IZkDataListenerEntry> listeners = _dataListener.get(path); if (listeners != null && !listeners.isEmpty()) { fireDataChangedEvents(event.getPath(), listeners, OptionalLong.of(notificationTime), pathExists); } } }
Example 3
Source File: DistributionRegionSyncer.java From bboxdb with Apache License 2.0 | 6 votes |
/** * The zookeeper callbacks */ @Override public void process(final WatchedEvent event) { try { // Ignore events like connected and disconnected if(event == null || event.getPath() == null) { return; } if(! event.getPath().endsWith(ZookeeperNodeNames.NAME_NODE_VERSION)) { logger.debug("Ignoring event: {}", event); return; } if(event.getType() == EventType.NodeDeleted) { processNodeDeletedEvent(event); return; } logger.debug("Handling event: {}", event); processNodeUpdateEvent(event); } catch (Throwable e) { logger.error("Got uncatched throwable during event handling", e); } }
Example 4
Source File: ZKNodeListener.java From zkclient with Apache License 2.0 | 6 votes |
@Override public void handle(String path, EventType eventType, Object data) throws Exception { if (eventType == EventType.NodeCreated) { handleDataCreated(path,data); } if (eventType == EventType.NodeDataChanged) { handleDataChanged(path,data); } if(eventType == EventType.NodeDeleted ){ handleDataDeleted(path); } if(eventType == eventType.None){ handleSessionExpired(path); } }
Example 5
Source File: ZKChildDataListener.java From zkclient with Apache License 2.0 | 6 votes |
@Override public void handle(String path, EventType eventType, Object data) throws Exception { //子节点个数变化 if (eventType == EventType.NodeChildrenChanged || eventType == EventType.NodeCreated || eventType == EventType.NodeDeleted) { handleChildCountChanged(path,(List<String>)data); } //子节点数据变化 if(eventType == EventType.NodeDataChanged){ handleChildDataChanged(path,data); } //Session失效 if(eventType == eventType.None){ handleSessionExpired(path,data); } }
Example 6
Source File: ZkClient.java From TakinRPC with Apache License 2.0 | 6 votes |
private void processDataOrChildChange(WatchedEvent event) { final String path = event.getPath(); if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDeleted) { Set<IZkChildListener> childListeners = _childListener.get(path); if (childListeners != null && !childListeners.isEmpty()) { fireChildChangedEvents(path, childListeners); } } if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated) { Set<IZkDataListener> listeners = _dataListener.get(path); if (listeners != null && !listeners.isEmpty()) { fireDataChangedEvents(event.getPath(), listeners); } } }
Example 7
Source File: ZkClient.java From DDMQ with Apache License 2.0 | 6 votes |
private void processDataOrChildChange(WatchedEvent event) { final String path = event.getPath(); if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDeleted) { Set<IZkChildListener> childListeners = _childListener.get(path); if (childListeners != null && !childListeners.isEmpty()) { fireChildChangedEvents(path, childListeners); } } if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated) { Set<IZkDataListener> listeners = _dataListener.get(path); if (listeners != null && !listeners.isEmpty()) { fireDataChangedEvents(event.getPath(), listeners); } } }
Example 8
Source File: FlinkServerRegister.java From pinpoint with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Override public void process(WatchedEvent event) { logger.info("Handle Zookeeper Event({}) started.", event); KeeperState state = event.getState(); EventType eventType = event.getType(); String path = event.getPath(); if (state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) { // when this happens, ephemeral node disappears // reconnects automatically, and process gets notified for all events if (eventType == EventType.NodeChildrenChanged) { logger.info("zookeeper Event occurs : NodeChildrenChanged event"); } else if (eventType == EventType.NodeDeleted) { logger.info("zookeeper Event occurs : NodeDeleted"); } else if (eventType == EventType.NodeDataChanged) { logger.info("zookeeper Event occurs : NodeDataChanged"); } } logger.info("Handle Zookeeper Event({}) completed.", event); }
Example 9
Source File: ZkDistributeLock.java From azeroth with Apache License 2.0 | 5 votes |
/** * zookeeper节点的监视器 */ public void process(WatchedEvent event) { if (this.latch != null) { if (event.getType() == EventType.NodeDeleted) { this.latch.countDown(); } } }
Example 10
Source File: ZkDistributeLock.java From jeesuite-libs with Apache License 2.0 | 5 votes |
/** * zookeeper节点的监视器 */ public void process(WatchedEvent event) { if (this.latch != null) { if(event.getType() == EventType.NodeDeleted){ this.latch.countDown(); } } }
Example 11
Source File: ZkUtils.java From pulsar with Apache License 2.0 | 5 votes |
/** * Check if the provided <i>path</i> exists or not and wait it expired if possible. * * @param zk the zookeeper client instance * @param path the zookeeper path * @param sessionTimeoutMs session timeout in milliseconds * @return true if path exists, otherwise return false * @throws KeeperException when failed to access zookeeper * @throws InterruptedException interrupted when waiting for znode to be expired */ public static boolean checkNodeAndWaitExpired(ZooKeeper zk, String path, long sessionTimeoutMs) throws KeeperException, InterruptedException { final CountDownLatch prevNodeLatch = new CountDownLatch(1); Watcher zkPrevNodeWatcher = watchedEvent -> { // check for prev node deletion. if (EventType.NodeDeleted == watchedEvent.getType()) { prevNodeLatch.countDown(); } }; Stat stat = zk.exists(path, zkPrevNodeWatcher); if (null != stat) { // if the ephemeral owner isn't current zookeeper client // wait for it to be expired if (stat.getEphemeralOwner() != zk.getSessionId()) { log.info("Previous znode : {} still exists, so waiting {} ms for znode deletion", path, sessionTimeoutMs); if (!prevNodeLatch.await(sessionTimeoutMs, TimeUnit.MILLISECONDS)) { throw new NodeExistsException(path); } else { return false; } } return true; } else { return false; } }
Example 12
Source File: ClusterManagerService.java From blog with MIT License | 5 votes |
private void handleStateChange(WatchedEvent event) { if (finishedInitialization.get()) { if (previousState != KeeperState.SyncConnected && event.getState() == KeeperState.SyncConnected) { previousState = event.getState(); checkMasterIsAvailable(); } EventType eventType = event.getType(); if (EventType.NodeDeleted == eventType && event.getPath().equalsIgnoreCase(watchedNodePath)) { checkMasterIsAvailable(); } } }
Example 13
Source File: ZKHelixManager.java From helix with Apache License 2.0 | 5 votes |
void handleNewSessionAsController() { if (_leaderElectionHandler != null) { _leaderElectionHandler.init(); } else { _leaderElectionHandler = new CallbackHandler(this, _zkclient, _keyBuilder.controller(), new DistributedLeaderElection(this, _controller, _controllerTimerTasks), new EventType[] { EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated }, ChangeType.CONTROLLER, _callbackMonitors.get(ChangeType.CONTROLLER)); } }
Example 14
Source File: ZookeeperClusterDataManager.java From pinpoint with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void process(WatchedEvent event) { logger.info("Handle Zookeeper Event({}) started.", event); KeeperState state = event.getState(); EventType eventType = event.getType(); String path = event.getPath(); // when this happens, ephemeral node disappears // reconnects automatically, and process gets notified for all events boolean result = false; if (state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) { if (eventType == EventType.NodeChildrenChanged) { result = handleNodeChildrenChanged(path); } else if (eventType == EventType.NodeDeleted) { result = handleNodeDeleted(path); } else if (eventType == EventType.NodeDataChanged) { result = handleNodeDataChanged(path); } } if (result) { logger.info("Handle Zookeeper Event({}) completed.", event); } else { logger.info("Handle Zookeeper Event({}) failed.", event); } }
Example 15
Source File: ZKWatcher.java From zkclient with Apache License 2.0 | 4 votes |
/** * 事件处理 * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatchedEvent) */ @Override public void process(WatchedEvent event) { LOG.debug("ZooKeeper event is arrived [" + event+" ]..."); EventType eventType = event.getType(); //状态更新 boolean stateChanged = event.getPath() == null; //节点相关的所有事件 boolean znodeChanged = event.getPath() != null; //节点创建、删除和数据改变的事件 boolean nodeChanged = eventType == EventType.NodeDataChanged || eventType == EventType.NodeDeleted || eventType == EventType.NodeCreated; //子节点数量改变相关的事件,包括节点创建和删除(都会影响子节点数量的变化),以及子节点数量的改变 boolean childChanged = eventType == EventType.NodeDeleted || eventType == EventType.NodeCreated || eventType == EventType.NodeChildrenChanged; client.acquireEventLock(); try { if (client.getShutdownTrigger()) { LOG.debug("client will shutdown,ignore the event [" + eventType + " | " + event.getPath() + "]"); return; } if (stateChanged) {//ZooKeeper状态改变的处理 process.processStateChanged(event); } if (nodeChanged) {//节点改变事件处理,包括节点的创建、删除、数据改变 process.processNodeChanged(event); } if (childChanged) {//造成子节点数量改变的事件的处理,包括节点的创建、删除、子节点数量改变 process.processChildChanged(event); } } finally { if (stateChanged) { client.getEventLock().getStateChangedCondition().signalAll(); // 在会话失效后,服务端会取消watch. // 如果在会话失效后与重连这段时间内有数据发生变化,监听器是无法监听到的, // 所以要唤醒等待的监听,并触发所有的监听事件 if (event.getState() == KeeperState.Expired) { client.getEventLock().getNodeEventCondition().signalAll(); client.getEventLock().getNodeOrChildChangedCondition().signalAll(); // 通知所有的监听器,可能存在数据变化 process.processAllNodeAndChildListeners(event); } } if (znodeChanged) { client.getEventLock().getNodeEventCondition().signalAll(); } if (nodeChanged || childChanged) { client.getEventLock().getNodeOrChildChangedCondition().signalAll(); } client.releaseEventLock(); } }
Example 16
Source File: ZKWatcherProcess.java From zkclient with Apache License 2.0 | 4 votes |
/** * 提交节点改变相关的事件进行处理 * @param listeners * @param childDataChangeListners * @param path * @param eventType * @return void */ private void submitNodeEvent(final Set<ZKListener> listeners,final Set<ZKListener> childDataChangeListners,final String path,final EventType eventType ){ if (listeners != null && !listeners.isEmpty()) { for (final ZKListener listener : listeners) { ZKEvent zkEvent = new ZKEvent("Node of " + path + " changed sent to " + listener) { @Override public void run() throws Exception { //原生的zookeeper 的监听只生效一次,重新注册监听 LOG.debug("Rewatch the path ["+path+"] by exists method"); boolean flag = client.exists(path, true); LOG.debug("Rewatched the path ["+path+"] by exists method"); try { LOG.debug("Rewatch and get changed data [path:"+path+" | EventType:"+eventType+"] by getData method"); Object data = client.getData(path, null); LOG.debug("Rewatched and return data ["+path+" | "+data+" | EventType:"+eventType+"] by getData method"); listener.handle(path, eventType, data); //响应了删除事件,但是在再次注册监听之前节点又被创建了,这样是无法重新监听到节点创建的 //这里主动触发节点创建事件。 if (eventType == EventType.NodeDeleted && flag) { listener.handle(path, EventType.NodeCreated, data); } } catch (ZKNoNodeException e) { //如果是节点不存在了,则只移除,ZKChildDataListener监听器 client.unlistenNodeChanges(path, childDataChangeListners); //如果路径不存在,在调用client.getData(path,null)会抛出异常 listener.handle(path, eventType, null); //如果是创建节点事件,并且在创建事件收到后,监听还没来得及重新注册,刚创建的节点已经被删除了。 //对于这种情况,客户端就无法重新监听到节点的删除事件的,这里做特殊处理 //主动触发删除的监听事件 if (eventType == EventType.NodeCreated && !flag) { listener.handle(path, EventType.NodeDeleted, null); } } } }; eventThreadPool.submit(zkEvent); } } }
Example 17
Source File: ZkClient.java From TakinRPC with Apache License 2.0 | 4 votes |
public void process(WatchedEvent event) { logger.debug("Received event: " + event); _zookeeperEventThread = Thread.currentThread(); boolean stateChanged = event.getPath() == null; boolean znodeChanged = event.getPath() != null; boolean dataChanged = event.getType() == EventType.NodeDataChanged || // event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || // event.getType() == EventType.NodeChildrenChanged; getEventLock().lock(); try { // We might have to install child change event listener if a new node was created if (getShutdownTrigger()) { logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered"); return; } if (stateChanged) { processStateChanged(event); } if (dataChanged) { processDataOrChildChange(event); } } finally { if (stateChanged) { getEventLock().getStateChangedCondition().signalAll(); // If the session expired we have to signal all conditions, because watches might have been removed and // there is no guarantee that those // conditions will be signaled at all after an Expired event if (event.getState() == KeeperState.Expired) { getEventLock().getZNodeEventCondition().signalAll(); getEventLock().getDataChangedCondition().signalAll(); // We also have to notify all listeners that something might have changed fireAllEvents(); } } if (znodeChanged) { getEventLock().getZNodeEventCondition().signalAll(); } if (dataChanged) { getEventLock().getDataChangedCondition().signalAll(); } getEventLock().unlock(); logger.debug("Leaving process event"); } }
Example 18
Source File: ZooKeeperCache.java From pulsar with Apache License 2.0 | 4 votes |
public boolean checkRegNodeAndWaitExpired(String regPath) throws IOException { final CountDownLatch prevNodeLatch = new CountDownLatch(1); Watcher zkPrevRegNodewatcher = new Watcher() { @Override public void process(WatchedEvent event) { // Check for prev znode deletion. Connection expiration is // not handling, since bookie has logic to shutdown. if (EventType.NodeDeleted == event.getType()) { prevNodeLatch.countDown(); } } }; try { Stat stat = getZooKeeper().exists(regPath, zkPrevRegNodewatcher); if (null != stat) { // if the ephemeral owner isn't current zookeeper client // wait for it to be expired. if (stat.getEphemeralOwner() != getZooKeeper().getSessionId()) { log.info("Previous bookie registration znode: {} exists, so waiting zk sessiontimeout:" + " {} ms for znode deletion", regPath, getZooKeeper().getSessionTimeout()); // waiting for the previous bookie reg znode deletion if (!prevNodeLatch.await(getZooKeeper().getSessionTimeout(), TimeUnit.MILLISECONDS)) { throw new NodeExistsException(regPath); } else { return false; } } return true; } else { return false; } } catch (KeeperException ke) { log.error("ZK exception checking and wait ephemeral znode {} expired : ", regPath, ke); throw new IOException("ZK exception checking and wait ephemeral znode " + regPath + " expired", ke); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); log.error("Interrupted checking and wait ephemeral znode {} expired : ", regPath, ie); throw new IOException("Interrupted checking and wait ephemeral znode " + regPath + " expired", ie); } }
Example 19
Source File: ZkClient.java From helix with Apache License 2.0 | 4 votes |
@Override public void process(WatchedEvent event) { long notificationTime = System.currentTimeMillis(); if (LOG.isDebugEnabled()) { LOG.debug("Received event: " + event); } _zookeeperEventThread = Thread.currentThread(); boolean stateChanged = event.getPath() == null; boolean sessionExpired = stateChanged && event.getState() == KeeperState.Expired; boolean znodeChanged = event.getPath() != null; boolean dataChanged = event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeChildrenChanged; if (event.getType() == EventType.NodeDeleted) { LOG.debug("Path {} is deleted", event.getPath()); } getEventLock().lock(); try { // We might have to install child change event listener if a new node was created if (getShutdownTrigger()) { if (LOG.isDebugEnabled()) { LOG.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered"); } return; } if (stateChanged) { processStateChanged(event); } if (dataChanged) { processDataOrChildChange(event, notificationTime); } } finally { if (stateChanged) { getEventLock().getStateChangedCondition().signalAll(); // If the session expired we have to signal all conditions, because watches might have been // removed and // there is no guarantee that those // conditions will be signaled at all after an Expired event // TODO PVo write a test for this if (event.getState() == KeeperState.Expired) { getEventLock().getZNodeEventCondition().signalAll(); getEventLock().getDataChangedCondition().signalAll(); } } if (znodeChanged) { getEventLock().getZNodeEventCondition().signalAll(); } if (dataChanged) { getEventLock().getDataChangedCondition().signalAll(); } getEventLock().unlock(); // update state change counter. recordStateChange(stateChanged, dataChanged, sessionExpired); if (LOG.isDebugEnabled()) { LOG.debug("Leaving process event"); } } }
Example 20
Source File: ZkClient.java From DDMQ with Apache License 2.0 | 4 votes |
@Override public void process(WatchedEvent event) { LOG.debug("Received event: " + event); _zookeeperEventThread = Thread.currentThread(); boolean stateChanged = event.getPath() == null; boolean znodeChanged = event.getPath() != null; boolean dataChanged = event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeChildrenChanged; getEventLock().lock(); try { // We might have to install child change event listener if a new node was created if (getShutdownTrigger()) { LOG.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered"); return; } if (stateChanged) { processStateChanged(event); } if (dataChanged) { processDataOrChildChange(event); } } finally { if (stateChanged) { getEventLock().getStateChangedCondition().signalAll(); // If the session expired we have to signal all conditions, because watches might have been removed and // there is no guarantee that those // conditions will be signaled at all after an Expired event if (event.getState() == KeeperState.Expired) { getEventLock().getZNodeEventCondition().signalAll(); getEventLock().getDataChangedCondition().signalAll(); // We also have to notify all listeners that something might have changed fireAllEvents(); } } if (znodeChanged) { getEventLock().getZNodeEventCondition().signalAll(); } if (dataChanged) { getEventLock().getDataChangedCondition().signalAll(); } getEventLock().unlock(); LOG.debug("Leaving process event"); } }