当前位置: 首页>>代码示例>>Java>>正文


Java NodeCache.getCurrentData方法代码示例

本文整理汇总了Java中org.apache.curator.framework.recipes.cache.NodeCache.getCurrentData方法的典型用法代码示例。如果您正苦于以下问题:Java NodeCache.getCurrentData方法的具体用法?Java NodeCache.getCurrentData怎么用?Java NodeCache.getCurrentData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.framework.recipes.cache.NodeCache的用法示例。


在下文中一共展示了NodeCache.getCurrentData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onNodeChanged

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public void onNodeChanged(final NodeCache cache, final ConfigDescriptor desc)
{
    ChildData childData = cache.getCurrentData();
    try {
        Optional<String> valueOpt = Optional.empty();
        if (childData != null && childData.getData() != null && childData.getData().length > 0) {
            valueOpt = Optional.of(new String(childData.getData(), Charsets.UTF_8));
        }
        emitEvent(desc.getConfigName(), valueOpt);
    }
    catch (Exception ex) {
        log.warn("Failed to handle onNodeChanged w/ new data for config key {}, data {}", desc.getConfigName(), childData, ex);
    }
}
 
开发者ID:kikinteractive,项目名称:ice,代码行数:15,代码来源:ZooKeeperDynamicConfigSource.java

示例2: processNodeData

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private Map<String, String> processNodeData(String path, NodeCache nodeCache) {
    ChildData currentData = nodeCache.getCurrentData();
    if (currentData == null) {
        throw new RuntimeException(String.format("node of path: %s do not exists", path));
    }
    String currentDataStr = new String(currentData.getData());
    logger.info("current data is : {}", currentDataStr);
    List<String> strings = Splitter.on("=").splitToList(currentDataStr);
    Map<String, String> map = Maps.newHashMap();
    map.put(strings.get(0), strings.get(1));
    return map;
}
 
开发者ID:rollenholt,项目名称:iConfig,代码行数:13,代码来源:IConfig.java

示例3: get

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public T get() {
    checkClosed();
    if (resource == null) {
        if (zkNodeExists == NOT_EXISTS) { // for performance, short circuit it outside sync block.
            return emptyObject;
        }
        synchronized (lock) {
            checkClosed();
            if (resource == null) {
                NodeCache cache = nodeCache.get();
                tryAddListener(cache);
                ChildData currentData = cache.getCurrentData();
                if (currentData == null || currentData.getData() == null) {
                    zkNodeExists = NOT_EXISTS;
                    if (!emptyLogged) { // 只在刚开始一次或者几次打印这个log
                        logger.warn("found no zk path for:{}, using empty data:{}", path(cache),
                                emptyObject);
                        emptyLogged = true;
                    }
                    return emptyObject;
                }
                zkNodeExists = EXISTS;
                try {
                    resource = factory.apply(currentData.getData(), currentData.getStat());
                    if (onResourceChange != null) {
                        onResourceChange.accept(resource, emptyObject);
                    }
                } catch (Exception e) {
                    factoryFailedListener.accept(e);
                    throwIfUnchecked(e);
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return resource;
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:38,代码来源:ZkBasedNodeResource.java

示例4: tryAddListener

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private void tryAddListener(NodeCache cache) {
    if (!hasAddListener) {
        NodeCacheListener nodeCacheListener = () -> {
            T oldResource;
            synchronized (lock) {
                ChildData data = cache.getCurrentData();
                oldResource = resource;
                if (data != null && data.getData() != null) {
                    zkNodeExists = EXISTS;
                    ListenableFuture<T> future = refreshFactory.apply(data.getData(),
                            data.getStat());
                    addCallback(future, new FutureCallback<T>() {

                        @Override
                        public void onSuccess(@Nullable T result) {
                            resource = result;
                            cleanup(resource, oldResource, cache);
                        }

                        @Override
                        public void onFailure(Throwable t) {
                            factoryFailedListener.accept(t);
                            logger.error("", t);
                        }
                    }, directExecutor());
                } else {
                    zkNodeExists = NOT_EXISTS;
                    resource = null;
                    emptyLogged = false;
                    cleanup(resource, oldResource, cache);
                }
            }
        };
        cache.getListenable().addListener(nodeCacheListener);
        nodeCacheRemoveListener = () -> cache.getListenable().removeListener(nodeCacheListener);
        hasAddListener = true;
    }
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:39,代码来源:ZkBasedNodeResource.java

示例5: addListener

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private static void addListener(final NodeCache cache) {
	// a PathChildrenCacheListener is optional. Here, it's used just to log
	// changes
	NodeCacheListener listener = new NodeCacheListener() {

		@Override
		public void nodeChanged() throws Exception {
			if (cache.getCurrentData() != null)
				System.out.println("Node changed: " + cache.getCurrentData().getPath() + ", value: " + new String(cache.getCurrentData().getData()));
		}
	};
	cache.getListenable().addListener(listener);
}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:14,代码来源:NodeCacheExample.java

示例6: onChange

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@Override
public void onChange(final CuratorFramework curator, final NodeCache cache, final String path)
{
    logger.debug("Config change ..");

    if (cache.getCurrentData() == null) {
        logger.warn("Empty config data ..");
    }

    final ChildData eData         = cache.getCurrentData();
    final String data             = eData != null ? new String(eData.getData()) : null;
    final Configuration newConfig = data != null ? serializer.fromJson(data) : new Configuration();
    final Configuration oldConfig = reference.get() != null ? reference.get() : new Configuration();

    if (newConfig == null) {
        logger.warn(String.format("Ignoring entity for path '%s', It cannot be NULL", path));

        return;
    }

    if (newConfig.equals(oldConfig)) {
        logger.debug(String.format("No changes detected..."));

        return;
    }

    logger.debug("Apply configuration : " + newConfig);

    reference.set(newConfig);
    dispatcher.dispatchEvents(newConfig, oldConfig);
}
 
开发者ID:interruptus,项目名称:interruptus,代码行数:32,代码来源:ConfigurationZookeeperListener.java

示例7: show

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private static void show(NodeCache cache) {
	if (cache.getCurrentData() != null)
		System.out.println(cache.getCurrentData().getPath() + " = " + new String(cache.getCurrentData().getData()));
	else
		System.out.println("cache don't set a value");
}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:7,代码来源:NodeCacheExample.java


注:本文中的org.apache.curator.framework.recipes.cache.NodeCache.getCurrentData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。