public void process(WatchedEvent event) { LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath()); if (event.getState() == KeeperState.SyncConnected && startSignal != null && startSignal.getCount() > 0) { startSignal.countDown(); } }
@Override public void process(WatchedEvent event) { if (LOG.isDebugEnabled()) { LOG.debug( "Received Zookeeper Event, " + "type=" + event.getType() + ", " + "state=" + event.getState() + ", " + "path=" + event.getPath()); } switch (event.getType()) { case None: { if (event.getState() == KeeperState.SyncConnected) { latch.countDown(); } } case NodeCreated: { for (ZkListener listener : this.listeners) { listener.nodeCreated(event.getPath()); } break; } case NodeDeleted: { for (ZkListener listener : this.listeners) { listener.nodeDeleted(event.getPath()); } break; } case NodeDataChanged: { for (ZkListener listener : this.listeners) { listener.nodeDataChanged(event.getPath()); } break; } case NodeChildrenChanged: { for (ZkListener listener : this.listeners) { listener.nodeChildrenChanged(event.getPath()); } break; } } }
@Override public void process(WatchedEvent event) { // 已经连上 if (event.getState() == Event.KeeperState.SyncConnected) { connectedSignal.countDown(); // 结束一个等待CountDownLatch log.info("服务器已经连上!"); } log.info("收到[{}]事件通知,触发[{}]事件!", event.getState(), event.getType()); }
public synchronized void process(WatchedEvent event) { if (event.getState() == KeeperState.SyncConnected || event.getState() == KeeperState.ConnectedReadOnly) { connected = true; notifyAll(); clientConnected.countDown(); } else { connected = false; notifyAll(); } }
public void process(WatchedEvent event) { if (event.getState() == KeeperState.SyncConnected) { synchronized (this) { connected = true; notifyAll(); } } else if (event.getState() == KeeperState.Disconnected) { synchronized (this) { connected = false; notifyAll(); } } }
public void process(WatchedEvent e) { log.info(e.getPath()); // System.out.println(e.getPath() + " " + e.toString()); if (e.getState() == Watcher.Event.KeeperState.Expired) { handleExpired(); } else if (e.getState() == Watcher.Event.KeeperState.Disconnected) { log.warn("ZKDisconnected! {}", e.toString()); } else if (e.getState() == Watcher.Event.KeeperState.SyncConnected) { log.warn("ZKSyncConnected! {}", e.toString()); ZKClient.this.handleSynConnected(); } }
public void process(WatchedEvent event) { String path = event.getPath(); if (event.getType() == Event.EventType.None) { // We are are being told that the state of the // connection has changed switch (event.getState()) { case SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case Expired: // It's all over dead = true; listener.closing(KeeperException.Code.SessionExpired); break; } } else { if (path != null && path.equals(znode)) { // Something has changed on the node, let's find out zk.exists(znode, true, this, null); } } if (chainedWatcher != null) { chainedWatcher.process(event); } }
public void process(WatchedEvent event) { LOGGER.debug( "Watcher fired on path: " + event.getPath() + " state: " + event.getState() + " type " + event.getType()); latchIfNoChange.countDown(); // ignore any children except valid children for a queue if (keyHandler.hasValidName(ZkUtils.getPathEnd(event.getPath()))) { if (highestPriorityChanged == null) { highestPriorityChanged = keyHandler.getPriority(event.getPath()); } else { synchronized (highestPriorityChanged) { PRIORITY changedPriority = keyHandler.getPriority(event.getPath()); if (changedPriority != null && changedPriority.compareTo(highestPriorityChanged) < 0) { highestPriorityChanged = changedPriority; } } } } }
public void process(WatchedEvent event) { if (event.getType() == EventType.NodeDataChanged) { displayConfig(); } else { System.out.println("数据没有发生改变,而是" + event.getType() + ":" + event.getState()); } }
/* * (non-Javadoc) * * @see * org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatchedEvent) */ @Override public void process(WatchedEvent event) { // TODO Auto-generated method stub if (event.getState() == KeeperState.SyncConnected) { countDownLatch.countDown(); } }
@Override public synchronized void process(WatchedEvent event) { if (event.getState() == KeeperState.AuthFailed) { authFailed.incrementAndGet(); } else { super.process(event); } }
@Override public void process(WatchedEvent watchedEvent) { if (watchedEvent.getState() == Event.KeeperState.Expired || watchedEvent.getState() == Event.KeeperState.Disconnected) { try { ZK_CLIENT_MAP.put( host, new ZooKeeper( host, Integer.parseInt( ConfigUtils.getProperty("spy.zookeeper.session.timeout", "60000")), this)); } catch (IOException e) { logger.error("failed to reconnect zookeeper server", e); } } }
@Override public synchronized void process(WatchedEvent watchedEvent) { log.debug("ZookeeperConnWatcher.process: Entered with event {}", watchedEvent.getState()); // The ZK client re-connects automatically. However, after it // successfully reconnects, if the session had expired, we need to // create a new session. if (watchedEvent.getState() == Watcher.Event.KeeperState.Expired && conn != null) { log.info("Session expired, reconnecting to ZK with a new session"); try { conn.reopen(); } catch (Exception e) { throw new RuntimeException("Zookeeper could not be " + "restarted", e); } } log.debug("ZookeeperConnWatcher.process: Exiting"); }
@Override public void process(WatchedEvent event) { log.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState()); if (event.getState() == KeeperState.Expired) { log.warn("Trace server lost zookeeper registration at " + event.getPath()); server.stop(); } else if (event.getType() == EventType.NodeDeleted) { log.warn("Trace server zookeeper entry lost " + event.getPath()); server.stop(); } if (event.getPath() != null) { try { if (ZooReaderWriter.getInstance().exists(event.getPath(), this)) return; } catch (Exception ex) { log.error(ex, ex); } log.warn("Trace server unable to reset watch on zookeeper registration"); server.stop(); } }
public void process(WatchedEvent event) { try { KeeperState state = event.getState(); if (state == KeeperState.SyncConnected) { log.info("Connect to Zookeeper Server successfully! "); } else if (state == KeeperState.Disconnected || state == KeeperState.Expired) { log.info("Disconnected from Zookeeper Server! "); } } finally { signal.countDown(); } }
@Override public void process(WatchedEvent event) { if (event.getType() == Event.EventType.None && event.getState() == KeeperState.Expired) { try { reconnectToZookeeper(this.zookeeper); } catch (Exception e) { logger.warn("Reconnect to zookeeper cluster failed while session expired.", e); } } if (this.watcher != null) { this.watcher.process(event); } }
@Override public void process(WatchedEvent event) { // this lock is important so that when changes start happening, we // won't run into any concurrency issues synchronized (WatchedNode.this) { if (!cancelled) { if (event.getState() == KeeperState.SyncConnected) { // If connected update data and notify listeners try { if (event.getType().equals(Event.EventType.NodeCreated)) { watchForData(); } else if (event.getType().equals(Event.EventType.NodeDeleted)) { // Previous version notified is null, and we will notify with null previousVersion = null; watchForCreation(); } else if (event.getType().equals(Event.EventType.NodeDataChanged)) { watchForData(); } } catch (KeeperException e) { LOG.error("Exception while trying to update our cached value for " + nodePath, e); } catch (InterruptedException e) { if (LOG.isTraceEnabled()) { LOG.trace( "Interrupted while trying to update our cached value for " + nodePath, e); } } // Notify of new value if either we didn't notify of any value, or the node has // changed long currentVersion = stat.getCtime() + stat.getMtime(); if (previousVersion == null || !previousVersion.equals(currentVersion)) { try { synchronized (listeners) { for (WatchedNodeListener<T> listener : listeners) { listener.onWatchedNodeChange(value); } } } finally { previousVersion = currentVersion; } } } else { // Not sync connected, do nothing if (LOG.isDebugEnabled()) { LOG.debug("Not sync connected anymore for watched node " + nodePath); } } } } }
@Override public synchronized void process(WatchedEvent watchedEvent) { // If we lose synchronization, stop waiting if (watchedEvent.getState() != Event.KeeperState.SyncConnected) { waiting = false; } else { // If the node has been created, stop waiting if (watchedEvent.getType() == Event.EventType.NodeCreated) { waiting = false; } } // Notify threads to check waiting flag notifyAll(); }
@Override public void process(WatchedEvent event) { if (!asnycConnection && event.getState() == Event.KeeperState.SyncConnected) { connectionLock.release(); // 连接成功 } else if (event.getState() == Event.KeeperState.Disconnected) { // 连接断开 log.warn("zookeeper 连接断开......"); } else if (event.getState() == Event.KeeperState.Expired) { // 连接超时 log.warn("zookeeper session timeout......"); try { zkClient.reconnect(); process.relisten(); process.recreate(); } catch (Exception e) { log.error("reconnection to zookeeper error.", e); } } if (event.getType() == Event.EventType.NodeChildrenChanged) { // 子节点变化 process.clientNodeChanged(event.getPath()); } else if (event.getType() == Event.EventType.NodeDataChanged) { // 节点数据变化 process.nodeDataChanged(event.getPath()); } }
public synchronized void process(WatchedEvent event) { logger.info(getClass().getName() + event.getPath()); logger.info(getClass().getName() + event.getType()); synchronized (mutex) { switch (event.getState()) { case SyncConnected: mutex.notify(); } switch (event.getType()) { case NodeCreated: mutex.notify(); break; } } }
public void process(WatchedEvent event) { // lets either become the leader or watch the new/updated node LOG.debug( "Watcher fired on path: " + event.getPath() + " state: " + event.getState() + " type " + event.getType()); try { lock(); } catch (Exception e) { LOG.warn("Failed to acquire lock: " + e, e); } }
@Override public void process(WatchedEvent event) { if (EventType.None == event.getType()) { switch (event.getState()) { case Disconnected: // Intentional fall through of case case Expired: // ZooReader is handling the Expiration of the original ZooKeeper object for // us log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys(); } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: " + event); } // Nothing more to do for EventType.None return; } String path = event.getPath(); if (null == path) { return; } if (!path.startsWith(baseNode)) { log.info("Ignoring event for path: {}", path); return; } try { if (path.equals(baseNode)) { processBaseNode(event); } else { processChildNode(event); } } catch (KeeperException | InterruptedException e) { log.error("Failed to communicate with ZooKeeper", e); } }
/** * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatchedEvent) * <p>watch for session changes */ @Override public void process(WatchedEvent event) { if (event.getType() != EventType.None) return; switch (event.getState()) { case SyncConnected: break; case Expired: break; case Disconnected: break; default: break; } }
@Override public void process(WatchedEvent event) { LOG.debug("Received watched event {} from zookeeper based ledger manager.", event); if (Event.EventType.None == event.getType()) { if (Event.KeeperState.Expired == event.getState()) { LOG.info("ZooKeeper client expired on ledger manager."); Set<Long> keySet = new HashSet<Long>(listeners.keySet()); for (Long lid : keySet) { scheduler.submit(new ReadLedgerMetadataTask(lid)); LOG.info("Re-read ledger metadata for {} after zookeeper session expired.", lid); } } return; } String path = event.getPath(); if (null == path) { return; } final long ledgerId; try { ledgerId = getLedgerId(event.getPath()); } catch (IOException ioe) { LOG.info("Received invalid ledger path {} : ", event.getPath(), ioe); return; } switch (event.getType()) { case NodeDeleted: Set<LedgerMetadataListener> listenerSet = listeners.remove(ledgerId); if (null != listenerSet) { LOG.debug("Removed ledger metadata listeners on ledger {} : {}", ledgerId, listenerSet); } else { LOG.debug( "No ledger metadata listeners to remove from ledger {} after it's deleted.", ledgerId); } break; case NodeDataChanged: new ReadLedgerMetadataTask(ledgerId).run(); break; default: LOG.debug("Received event {} on {}.", event.getType(), event.getPath()); break; } }
@Override public void process(WatchedEvent event) { Event.EventType eventType = event.getType(); // None events are ignored // If latchEventType is not null, only fire if the type matches LOG.info( "{} fired on path {} state {} latchEventType {}", eventType, event.getPath(), event.getState(), latchEventType); if (eventType != Event.EventType.None && (latchEventType == null || eventType == latchEventType)) { synchronized (lock) { this.event = event; lock.notifyAll(); } } }
private void process(WatchedEvent event) { switch (event.getState()) { case Disconnected: this.processDisconnected(event); break; case SyncConnected: this.processSyncConnected(event); break; case AuthFailed: break; case ConnectedReadOnly: break; case SaslAuthenticated: break; case Expired: this.processSessionExpired(); break; } }
@Override public void process(WatchedEvent event) { // session events are not change events, and do not remove the watcher if (Event.EventType.None.equals(event.getType())) { return; } // If latchEventType is not null, only fire if the type matches LOG.debug( "{} fired on path {} state {} latchEventType {}", event.getType(), event.getPath(), event.getState(), latchEventType); if (latchEventType == null || event.getType() == latchEventType) { synchronized (lock) { this.event = event; lock.notifyAll(); } } }
@Override public void process(WatchedEvent event) { // TODO Auto-generated method stub System.out.println(event); if (event.getState().equals(KeeperState.SyncConnected)) { if (event.getType() == EventType.None && null == event.getPath()) { doSomething(zookeeper); } else { // if(event.getType() == EventType.NodeChildrenChanged){ // try { // List<String> subList = zookeeper.getChildren("/", // false);/*一个watch只能使用一次,如果想再次使用则需要再次注册*/ // System.out.println(subList); // } catch (KeeperException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } // } } } }
@Override public void process(WatchedEvent event) { boolean needsRefresh = false; if (event.getType() == Event.EventType.None && event.getState() == Event.KeeperState.SyncConnected) { needsRefresh = true; } else if (NodeChildrenChanged.equals(event.getType()) && event.getPath().equals(REPOSITORY_COLLECTION_PATH)) { needsRefresh = true; } else if (NodeDataChanged.equals(event.getType()) && event.getPath().startsWith(REPOSITORY_COLLECTION_PATH_SLASH)) { needsRefresh = true; } if (needsRefresh) { try { refresh(); } catch (Throwable t) { log.error("Repository Model: error handling event from ZooKeeper. Event: " + event, t); } } }
@Override public void process(WatchedEvent event) { if (LOG_EVENTS) { log.debug("ConnectState watcher: " + event); } for (Watcher parentWatcher : parentWatchers) { TimeTrace timeTrace = new TimeTrace("connection-state-parent-process", tracer.get()); parentWatcher.process(event); timeTrace.commit(); } boolean wasConnected = isConnected.get(); boolean newIsConnected = wasConnected; if (event.getType() == Watcher.Event.EventType.None) { newIsConnected = checkState(event.getState(), wasConnected); } if (newIsConnected != wasConnected) { isConnected.set(newIsConnected); connectionStartMs = System.currentTimeMillis(); } }