示例#1
0
    @Override
    public void process(WatchedEvent event) {
      switch (event.getType()) {
        case NodeChildrenChanged:
          // ring group was added OR currentversion was set for the first time
          LOG.debug("NodeChildrenChanged fired");
          fireListener();
          break;

        case NodeDataChanged:
          // one of the versions was updated
          LOG.debug("NodeDataChanged fired");
          fireListener();
          break;

        case NodeDeleted:
          // updatingToVersion was whacked
          LOG.debug("NodeDeleted fired");
          fireListener();
          break;

        default:
          LOG.debug("Unexpected event type " + event.getType());
      }
    }
 public void process(WatchedEvent event) {
   if (event.getType() == EventType.NodeDataChanged) {
     displayConfig();
   } else {
     System.out.println("数据没有发生改变,而是" + event.getType() + ":" + event.getState());
   }
 }
 @Override
 public void process(WatchedEvent event) {
   if (event.getType() == EventType.NodeDataChanged) {
     String keyPath = event.getPath();
     String key = keyPath.substring(keyPath.lastIndexOf("/") + 1);
     String value = "";
     try {
       value = pigeonCache.getServiceValue(key);
     } catch (LionException e) {
       logger.error(e.getMessage(), e);
     }
     logger.info("Pigeon Cache Key Change! Key: " + key + " Value: " + value);
     if (pigeonCache.getService().containsKey(key)) {
       List<String[]> hostDetail = pigeonCache.getServiceIpPortWeight(value);
       pigeonCache
           .getServiceChange()
           .onServiceHostChange(this.replaceServiceName(key), hostDetail);
     }
   } else {
     // 重新监听节点信息
     logger.info("Delete The Node " + event.getType() + " " + event.getPath());
     String key = event.getPath().substring(event.getPath().lastIndexOf("/") + 1);
     try {
       pigeonCache.getServiceValue(key);
     } catch (LionException e) {
       logger.error(e.getMessage(), e);
     }
   }
 }
示例#4
0
 @Override
 public void process(WatchedEvent event) throws Exception {
   if (event.getType() == EventType.NodeDeleted) {
     createNode();
   } else if (event.getType() == EventType.NodeDataChanged) {
     watchNode();
   }
 }
示例#5
0
  @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;
        }
    }
  }
示例#6
0
        @Override
        public void process(WatchedEvent event) {

          if (event.getType() == EventType.NodeChildrenChanged) {

            abortX();
          } else if (event.getType() == EventType.NodeCreated) {

            // if one votes 'ABORT', abort the X
            // if all vote 'PREPARE' commit the X
            // else continue watching
            commitX();
          }
        }
示例#7
0
        @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);
                }
              }
            }
          }
        }
 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;
     }
   }
 }
  /** Process the {@link WatchedEvent} for a node which represents an {@link AuthenticationKey} */
  void processChildNode(WatchedEvent event) throws KeeperException, InterruptedException {
    final String path = event.getPath();
    switch (event.getType()) {
      case NodeDeleted:
        // Key expired
        if (null == path) {
          log.error("Got null path for NodeDeleted event");
          return;
        }

        // Pull off the base ZK path and the '/' separator
        String childName = path.substring(baseNode.length() + 1);
        secretManager.removeKey(Integer.parseInt(childName));
        break;
      case None:
        // Not connected, don't care. We'll update when we're reconnected
        break;
      case NodeCreated:
        // New key created
        if (null == path) {
          log.error("Got null path for NodeCreated event");
          return;
        }
        // Get the data and reset the watcher
        AuthenticationKey key = deserializeKey(zk.getData(path, this, null));
        log.debug("Adding AuthenticationKey with keyId {}", key.getKeyId());
        secretManager.addKey(key);
        break;
      case NodeDataChanged:
        // Key changed, could happen on restart after not running Accumulo.
        if (null == path) {
          log.error("Got null path for NodeDataChanged event");
          return;
        }
        // Get the data and reset the watcher
        AuthenticationKey newKey = deserializeKey(zk.getData(path, this, null));
        // Will overwrite the old key if one exists
        secretManager.addKey(newKey);
        break;
      case NodeChildrenChanged:
        // no children for the children..
        log.warn("Unexpected NodeChildrenChanged event for authentication key node {}", path);
        break;
      default:
        log.warn("Unsupported event type: {}", event.getType());
        break;
    }
  }
示例#10
0
 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;
            }
          }
        }
      }
    }
示例#12
0
 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();
   }
 }
示例#13
0
 /** @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatchedEvent) */
 @Override
 public synchronized void process(WatchedEvent event) {
   EventType type = event.getType();
   if (type.equals(EventType.NodeDeleted)) {
     LOG.debug("Master address ZNode deleted, notifying waiting masters");
     notifyAll();
   }
 }
示例#14
0
 @Override
 public void process(WatchedEvent event) {
   if (event.getPath().equals(root + "/start") && event.getType() == Event.EventType.NodeCreated) {
     System.out.println("得到通知");
     super.process(event);
     doAction();
   }
 }
 @Override
 public void process(WatchedEvent watchedEvent) {
   Event.EventType type = watchedEvent.getType();
   LOG.info("Got event " + type + " with path " + watchedEvent.getPath());
   if (type.equals(Event.EventType.NodeDataChanged)) {
     readReplicationStateZnode();
   }
 }
 @Override
 public void process(WatchedEvent event) {
   // Look for a NodeCreate event on /demo
   if (event.getType() == Watcher.Event.EventType.NodeCreated) {
     if (event.getPath().equals(NODE)) {
       _sawDemo = true;
     }
   }
 }
 @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;
   }
 }
示例#18
0
  @Override
  public void process(WatchedEvent event) {
    // 已经连上
    if (event.getState() == Event.KeeperState.SyncConnected) {
      connectedSignal.countDown(); // 结束一个等待CountDownLatch
      log.info("服务器已经连上!");
    }

    log.info("收到[{}]事件通知,触发[{}]事件!", event.getState(), event.getType());
  }
 public void process(WatchedEvent event) {
   if (event.getType() == Event.EventType.NodeChildrenChanged) {
     LOG.debug("Running children changed [" + event.getPath() + "]");
     try {
       getZkRunning();
     } catch (Exception e) {
       e.printStackTrace();
       LOG.error(e);
     }
   } else if (event.getType() == Event.EventType.NodeDeleted) {
     String znodePath = event.getPath();
     LOG.debug("Running znode deleted [" + znodePath + "]");
     try {
       restartServer(znodePath);
     } catch (Exception e) {
       e.printStackTrace();
       LOG.error(e);
     }
   }
 }
 @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();
     }
   }
 }
示例#21
0
 @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();
   }
 }
    @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 (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);
   }
 }
示例#24
0
 @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();
 }
示例#25
0
  @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());
    }
  }
示例#26
0
 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);
   }
 }
 /**
  * Process the {@link WatchedEvent} for the base znode that the {@link AuthenticationKey}s are
  * stored in.
  */
 void processBaseNode(WatchedEvent event) throws KeeperException, InterruptedException {
   switch (event.getType()) {
     case NodeDeleted:
       // The parent node was deleted, no children are possible, remove all keys
       log.debug("Parent ZNode was deleted, removing all AuthenticationKeys");
       secretManager.removeAllKeys();
       break;
     case None:
       // Not connected, don't care
       break;
     case NodeCreated: // intentional fall-through to NodeChildrenChanged
     case NodeChildrenChanged:
       // Process each child, and reset the watcher on the parent node. We know that the node
       // exists
       updateAuthKeys(event.getPath());
       break;
     case NodeDataChanged:
       // The data on the parent changed. We aren't storing anything there so it's a noop
       break;
     default:
       log.warn("Unsupported event type: {}", event.getType());
       break;
   }
 }
示例#28
0
  /**
   * @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) {
    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);
    }
  }
 public void process(WatchedEvent watchedEvent) {
   try {
     Closure callback = null;
     switch (watchedEvent.getType()) {
       case NodeChildrenChanged:
         if (null != onNodeChildrenChanged) {
           callback = onNodeChildrenChanged;
         } else {
           callback = onEvent;
         }
         break;
       case NodeCreated:
         if (null != onNodeCreated) {
           callback = onNodeCreated;
         } else {
           callback = onEvent;
         }
         break;
       case NodeDeleted:
         if (null != onNodeDeleted) {
           callback = onNodeDeleted;
         } else {
           callback = onEvent;
         }
         break;
       case NodeDataChanged:
         if (null != onDataChanged) {
           callback = onDataChanged;
         } else {
           callback = onEvent;
         }
         break;
       case None:
         if (null != onEvent) {
           callback = onEvent;
         }
     }
     if (null != callback) {
       callback.call(watchedEvent);
     } else {
       log.warn("No callbacks defined to accept event: " + watchedEvent);
     }
   } catch (Throwable t) {
     log.debug(t.getMessage());
   }
 }