Examples of ChildData


Examples of org.apache.curator.framework.recipes.cache.ChildData

  }

  private void refreshConfiguration() throws IOException {
    LOGGER.info("Refreshing configuration from ZooKeeper");
    byte[] data = null;
    ChildData childData = agentNodeCache.getCurrentData();
    if (childData != null) {
      data = childData.getData();
    }
    flumeConfiguration = configFromBytes(data);
    eventBus.post(getConfiguration());
  }
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

            new PathChildrenCacheListener()
            {
              @Override
              public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
              {
                final ChildData child = event.getData();
                switch (event.getType()) {
                  case CHILD_ADDED:
                    final String path = child.getPath();
                    final DataSegmentChangeRequest request = jsonMapper.readValue(
                        child.getData(), DataSegmentChangeRequest.class
                    );

                    log.info("New request[%s] with node[%s].", request.asString(), path);

                    try {
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

      // create the watcher for future configuration updatess
        pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
            public void childEvent(CuratorFramework aClient, PathChildrenCacheEvent event)
                    throws Exception {
                Type eventType = event.getType();
                ChildData data = event.getData();
               
                String path = null;
                if (data != null) {
                    path = data.getPath();
                   
                    // scrub configRootPath out of the key name
                    String key = removeRootPath(path);

                    byte[] value = data.getData();
                    String stringValue = new String(value, charset);

                    logger.debug("received update to pathName [{}], eventType [{}]", path, eventType);
                    logger.debug("key [{}], and value [{}]", key, stringValue);
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

    public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
    {
      switch (event.getType()) {
        case CHILD_ADDED:
          synchronized (lock) {
            final ChildData child = event.getData();
            final String containerKey = ZKPaths.getNodeFromPath(child.getPath());

            final ContainerClass container = strategy.deserializeContainer(child.getData());

            // This would normally be a race condition, but the only thing that should be mutating the containers
            // map is this listener, which should never run concurrently.  If the same container is going to disappear
            // and come back, we expect a removed event in between.
            if (containers.containsKey(containerKey)) {
              log.error("New node[%s] but there was already one.  That's not good, ignoring new one.", child.getPath());
            } else {
              final String inventoryPath = String.format("%s/%s", config.getInventoryPath(), containerKey);
              PathChildrenCache inventoryCache = cacheFactory.make(curatorFramework, inventoryPath);
              inventoryCache.getListenable().addListener(new InventoryCacheListener(containerKey, inventoryPath));

              containers.put(containerKey, new ContainerHolder(container, inventoryCache));

              log.info("Starting inventory cache for %s, inventoryPath %s", containerKey, inventoryPath);
              inventoryCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
              strategy.newContainer(container);
            }

            break;
          }
        case CHILD_REMOVED:
          synchronized (lock) {
            final ChildData child = event.getData();
            final String containerKey = ZKPaths.getNodeFromPath(child.getPath());

            final ContainerHolder removed = containers.remove(containerKey);
            if (removed == null) {
              log.warn("Container[%s] removed that wasn't a container!?", child.getPath());
              break;
            }

            // This close() call actually calls shutdownNow() on the executor registered with the Cache object, it
            // better have its own executor or ignore shutdownNow() calls...
            log.info("Closing inventory cache for %s. Also removing listeners.", containerKey);
            removed.getCache().getListenable().clear();
            removed.getCache().close();
            strategy.deadContainer(removed.getContainer());

            // also remove node from uninitilized, in case a nodes gets removed while we are starting up
            synchronized (removed) {
              markInventoryInitialized(removed);
            }

            break;
          }
        case CHILD_UPDATED:
          synchronized (lock) {
            final ChildData child = event.getData();
            final String containerKey = ZKPaths.getNodeFromPath(child.getPath());

            final ContainerClass container = strategy.deserializeContainer(child.getData());

            ContainerHolder oldContainer = containers.get(containerKey);
            if (oldContainer == null) {
              log.warn("Container update[%s], but the old container didn't exist!?  Ignoring.", child.getPath());
            } else {
              synchronized (oldContainer) {
                oldContainer.setContainer(strategy.updateContainer(oldContainer.getContainer(), container));
              }
            }
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

          return;
        }

        switch (event.getType()) {
          case CHILD_ADDED: {
            final ChildData child = event.getData();
            final String inventoryKey = ZKPaths.getNodeFromPath(child.getPath());

            final InventoryClass addedInventory = strategy.deserializeInventory(child.getData());

            synchronized (holder) {
              holder.setContainer(strategy.addInventory(holder.getContainer(), inventoryKey, addedInventory));
            }
            break;
          }

          case CHILD_UPDATED: {
            final ChildData child = event.getData();
            final String inventoryKey = ZKPaths.getNodeFromPath(child.getPath());

            final InventoryClass updatedInventory = strategy.deserializeInventory(child.getData());

            synchronized (holder) {
              holder.setContainer(strategy.updateInventory(holder.getContainer(), inventoryKey, updatedInventory));
            }

            break;
          }

          case CHILD_REMOVED: {
            final ChildData child = event.getData();
            final String inventoryKey = ZKPaths.getNodeFromPath(child.getPath());

            synchronized (holder) {
              holder.setContainer(strategy.removeInventory(holder.getContainer(), inventoryKey));
            }
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

                public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
                {
                  log.debug("Path[%s] got event[%s]", parentPath, event);
                  switch (event.getType()) {
                    case CHILD_REMOVED:
                      final ChildData child = event.getData();
                      final ZKPaths.PathAndNode childPath = ZKPaths.getPathAndNode(child.getPath());
                      final byte[] value = finalSubPaths.get(childPath.getNode());
                      if (value != null) {
                        log.info("Node[%s] dropped, reinstating.", child.getPath());
                        createAnnouncement(child.getPath(), value);
                      }
                      break;
                    case CONNECTION_LOST:
                      // Lost connection, which means session is broken, take inventory of what has been seen.
                      // This is to protect from a race condition in which the ephemeral node could have been
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

   * Retrieve the current layout ID from ZooKeeper, or null if it does not exist.
   *
   * @return the current layout ID, or null if it does not exist.
   */
  public String getLayoutID() {
    ChildData currentData = mCache.getCurrentData();
    if (currentData == null) {
      return null;
    } else {
      return Bytes.toString(currentData.getData());
    }
  }
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

   */
  @Override
  public Container findOne(String id) {
    Container container = null;
    String containerPath = path(id);
    ChildData childData = ensureCache().getCurrentData(containerPath);
    byte[] data = null;

    if (childData != null) {
      data = childData.getData();
    }
    if (data != null) {
      container = new Container(id, ZooKeeperUtils.bytesToMap(data));
    }

View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

   *
   * @param logger logger to write to
   * @param event  event to log
   */
  public static void logCacheEvent(Logger logger, PathChildrenCacheEvent event) {
    ChildData data = event.getData();
    StringBuilder builder = new StringBuilder();
    builder.append("Path cache event: ");
    if (data != null && data.getPath() != null) {
      builder.append("path=").append(data.getPath()).append(", ");
    }
    builder.append("type=").append(event.getType());

    logger.info(builder.toString());
    if (data != null && logger.isTraceEnabled()) {
      String content;
      byte[] bytes = data.getData();
      if (bytes == null || bytes.length == 0) {
        content = "empty";
      }
      else {
        try {
          content = new String(data.getData(), "UTF-8");
        }
        catch (UnsupportedEncodingException e) {
          content = "Could not convert content to UTF-8: " + e.toString();
        }
      }
      logger.trace("Data for path {}: {}", data.getPath(), content);
    }
  }
View Full Code Here

Examples of org.apache.curator.framework.recipes.cache.ChildData

        }
    }

    protected void treeCacheEvent(PathChildrenCacheEvent event) {
        String zkPath = zooKeeperPath;
        ChildData childData = event.getData();
        if (childData == null) {
            return;
        }
        String path = childData.getPath();
        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());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.