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);
    }
  }
 @Override
 public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
   switch (event.getType()) {
     case INITIALIZED:
     case CONNECTION_RECONNECTED:
       if (!isRegistered(consumerNodeId)) {
         registerConsumerNode();
       }
       break;
   }
 }
 @Override
 public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
   switch (event.getType()) {
     case CHILD_ADDED:
     case CHILD_UPDATED:
     case CHILD_REMOVED:
       rebuildHandler();
       break;
     default:
       break;
   }
 }
Example #4
0
 public void update(PathChildrenCacheEvent event) {
   LOGGER.debug("{}", event);
   String domain = ZKPaths.getNodeFromPath(event.getData().getPath());
   switch (event.getType()) {
     case CHILD_ADDED:
       try {
         if (shouldConnectTo(domain)) {
           connectors.put(
               domain, startConnector(domain, toHostAndPort(event.getData().getData())));
         }
       } catch (ExecutionException e) {
         LOGGER.error("Failed to start tunnel connector to {}: {}", domain, e.getCause());
       } catch (InterruptedException ignored) {
       }
       break;
     case CHILD_REMOVED:
       String cell = connectors.remove(domain);
       if (cell != null) {
         getNucleus().kill(cell);
       }
       break;
   }
 }