@Override
 public void delete(String path) {
   try {
     client.delete(path);
   } catch (ZkNoNodeException e) {
   }
 }
  @SuppressWarnings("unchecked")
  public T poll() throws Exception {

    try {

      List<String> list = zkClient.getChildren(root);
      if (list.size() == 0) {
        return null;
      }
      Collections.sort(
          list,
          new Comparator<String>() {
            public int compare(String lhs, String rhs) {
              return getNodeNumber(lhs, Node_NAME).compareTo(getNodeNumber(rhs, Node_NAME));
            }
          });

      for (String nodeName : list) {

        String nodeFullPath = root.concat("/").concat(nodeName);
        try {
          T node = (T) zkClient.readData(nodeFullPath);
          zkClient.delete(nodeFullPath);
          return node;
        } catch (ZkNoNodeException e) {
          // ignore
        }
      }

      return null;

    } catch (Exception e) {
      throw ExceptionUtil.convertToRuntimeException(e);
    }
  }
Exemple #3
0
 @Export
 public void clean() {
   List<String> groups = zkClient.getChildren(ZkPaths.rootPath());
   for (String group : groups) {
     if (zkClient.countChildren(ZkPaths.groupPath(group)) == 0) {
       zkClient.delete(ZkPaths.groupPath(group));
     }
   }
 }
Exemple #4
0
 /** 使用正确的密码删除节点 */
 static void deleteParent() throws Exception {
   try {
     zkClient = new ZkClient(SERVER_LIST, 50000);
     // zkClient.addAuthInfo(authentication_type, correctAuthentication.getBytes());
     if (zkClient.exists(PATH)) {
       zkClient.delete(PATH);
       System.out.println(PATH + "删除成功");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #5
0
  /** 不使用密码 删除节点 */
  static void deleteNodeByNoAuthentication() throws Exception {

    String prefix = "[不使用任何授权信息]";

    try {
      System.out.println(prefix + "删除节点:" + PATH_DEL);
      zkClient = new ZkClient(SERVER_LIST, 50000);
      if (zkClient.exists(PATH_DEL)) {
        zkClient.delete(PATH_DEL);
        System.out.println(prefix + "删除成功");
      }
    } catch (Exception e) {
      System.err.println(prefix + "删除失败,原因是:" + e.getMessage());
    }
  }
Exemple #6
0
  /** 使用正确的密码删除节点 */
  static void deleteNodeByCorrectAuthentication() throws Exception {

    String prefix = "[使用正确的授权信息]";

    try {
      System.out.println(prefix + "删除节点:" + PATH_DEL);
      zkClient = new ZkClient(SERVER_LIST, 50000);
      // zkClient.addAuthInfo(authentication_type, correctAuthentication.getBytes());
      if (zkClient.exists(PATH_DEL)) {
        zkClient.delete(PATH_DEL);
        System.out.println(prefix + "删除成功");
      }
    } catch (Exception e) {
      System.out.println(prefix + "删除失败,原因是:" + e.getMessage());
    }
  }
Exemple #7
0
 public T dequeue() throws InterruptedException {
   if (_isBlocking) {
     Element<T> element = getFirstElement();
     _zkClient.delete(getElementPath(element.getName()));
     return element.getData();
   } else {
     throw new UnsupportedOperationException("Non-blocking ZooKeeperQueue is not yet supported");
     /* FIXME DOES NOT WORK
     try {
       String headName = getSmallestElement(_zkClient.getChildren(_elementsPath));
       String headPath = getElementPath(headName);
       return (T) _zkClient.readData(headPath);
     } catch (ZkNoNodeException e) {
       return null;
     }
     */
   }
 }
 public static void delete(String path) {
   zkClient.delete(path);
 }