protected void findKeys(List<String> keys, String path) {
    log.trace("enter findKeysCached for path: " + path);
    Map<String, ChildData> children = cache.getCurrentChildren(path);

    if (children == null) return;
    for (Map.Entry<String, ChildData> entry : children.entrySet()) {
      ChildData child = entry.getValue();
      if (child.getData() == null || child.getData().length == 0) {
        findKeys(keys, child.getPath());
      } else {
        keys.add(sanitizeKey(child.getPath()));
      }
    }
    log.trace("leaving findKeysCached for path: " + path);
  }
 private static void list(PathChildrenCache cache) {
   if (cache.getCurrentData().size() == 0) {
     System.out.println("* empty *");
   } else {
     for (ChildData data : cache.getCurrentData()) {
       System.out.println(data.getPath() + " = " + new String(data.getData()));
     }
   }
 }
  protected void treeCacheEvent(PathChildrenCacheEvent event) {

    ChildData childData = event.getData();
    if (childData == null) {
      return;
    }
    String path = childData.getPath();
    PathChildrenCacheEvent.Type type = event.getType();
    byte[] data = childData.getData();
    if (data == null || data.length == 0 || path == null) {
      return;
    }
    if (path.startsWith(zkPath)) {
      path = path.substring(zkPath.length());
    }

    // Lets just use the group name as the service path.
    path = Strings.splitAndTrimAsList(path, "/").get(0);

    boolean remove = false;
    switch (type) {
      case CHILD_ADDED:
      case CHILD_UPDATED:
        break;
      case CHILD_REMOVED:
        remove = true;
        break;
      default:
        return;
    }
    ServiceDTO dto = null;
    try {
      dto = mapper.readValue(data, ServiceDTO.class);
      expandPropertyResolvers(dto);
      if (remove) {
        LOG.info("Removed gateway service: " + path + ": " + new String(data, "UTF-8"));
        serviceMap.serviceRemoved(path, dto);
      } else {
        LOG.info("Updated gateway service: " + path + ": " + new String(data, "UTF-8"));
        serviceMap.serviceUpdated(path, dto);
      }
    } catch (IOException e) {
      LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
    } catch (URISyntaxException e) {
      LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
    }
  }
Esempio n. 4
0
 private void dumpDirectly(final String path, final List<String> result) {
   for (String each : coordinatorRegistryCenter.getChildrenKeys(path)) {
     String zkPath = path + "/" + each;
     String zkValue = coordinatorRegistryCenter.get(zkPath);
     if (null == zkValue) {
       zkValue = "";
     }
     TreeCache treeCache = (TreeCache) coordinatorRegistryCenter.getRawCache("/" + jobName);
     ChildData treeCacheData = treeCache.getCurrentData(zkPath);
     String treeCachePath = null == treeCacheData ? "" : treeCacheData.getPath();
     String treeCacheValue = null == treeCacheData ? "" : new String(treeCacheData.getData());
     if (zkValue.equals(treeCacheValue) && zkPath.equals(treeCachePath)) {
       result.add(Joiner.on(" | ").join(zkPath, zkValue));
     } else {
       result.add(Joiner.on(" | ").join(zkPath, zkValue, treeCachePath, treeCacheValue));
     }
     dumpDirectly(zkPath, result);
   }
 }