Пример #1
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);
   }
 }
Пример #2
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());
      }
    }
Пример #3
0
 public void process(WatchedEvent event) {
   if (event.getType() == EventType.NodeDataChanged) {
     displayConfig();
   } else {
     System.out.println("数据没有发生改变,而是" + event.getType() + ":" + event.getState());
   }
 }
 @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();
   }
 }
Пример #5
0
 @Override
 public void process(WatchedEvent event) throws Exception {
   if (event.getType() == EventType.NodeDeleted) {
     createNode();
   } else if (event.getType() == EventType.NodeDataChanged) {
     watchNode();
   }
 }
Пример #6
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();
   }
 }
Пример #7
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();
   }
 }
Пример #8
0
 @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;
     }
   }
 }
Пример #9
0
  @Override
  public void process(WatchedEvent event) {
    // 已经连上
    if (event.getState() == Event.KeeperState.SyncConnected) {
      connectedSignal.countDown(); // 结束一个等待CountDownLatch
      log.info("服务器已经连上!");
    }

    log.info("收到[{}]事件通知,触发[{}]事件!", event.getState(), event.getType());
  }
Пример #10
0
 public synchronized void process(WatchedEvent event) {
   if (event.getState() == KeeperState.SyncConnected
       || event.getState() == KeeperState.ConnectedReadOnly) {
     connected = true;
     notifyAll();
     clientConnected.countDown();
   } else {
     connected = false;
     notifyAll();
   }
 }
 @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);
   }
 }
Пример #12
0
 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();
     }
   }
 }
Пример #13
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;
        }
    }
  }
Пример #14
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);
                }
              }
            }
          }
        }
Пример #15
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();
          }
        }
Пример #16
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();
 }
Пример #17
0
 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;
     }
   }
 }
Пример #18
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 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;
    }
  }
Пример #20
0
 /*
  * (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();
   }
 }
Пример #21
0
 @Override
 public synchronized void process(WatchedEvent event) {
   if (event.getState() == KeeperState.AuthFailed) {
     authFailed.incrementAndGet();
   } else {
     super.process(event);
   }
 }
Пример #22
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();
   }
 }
 @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);
     }
   }
 }
Пример #24
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;
    }
  }
Пример #25
0
 public synchronized void process(WatchedEvent event) {
   try {
     System.out.println("Got an event " + event.toString());
     events.put(event);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
  @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);
    }
  }
  @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");
  }
Пример #28
0
 @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();
     }
   }
 }
 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);
     }
   }
 }
Пример #30
0
 @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();
     }
   }
 }