Search in sources :

Example 1 with TreeCache

use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.

the class ZookeeperRegistryCenter method get.

@Override
public String get(final String key) {
    TreeCache cache = findTreeCache(key);
    if (null == cache) {
        return getDirectly(key);
    }
    ChildData resultInCache = cache.getCurrentData(key);
    if (null != resultInCache) {
        return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
    }
    return getDirectly(key);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Example 2 with TreeCache

use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.

the class MonitorService method dumpDirectly.

private void dumpDirectly(final String path, final List<String> result) {
    for (String each : regCenter.getChildrenKeys(path)) {
        String zkPath = path + "/" + each;
        String zkValue = regCenter.get(zkPath);
        if (null == zkValue) {
            zkValue = "";
        }
        TreeCache treeCache = (TreeCache) regCenter.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);
    }
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Example 3 with TreeCache

use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.

the class JobNodeStorage method addDataListener.

/**
     * 注册数据监听器.
     * 
     * @param listener 数据监听器
     */
public void addDataListener(final TreeCacheListener listener) {
    TreeCache cache = (TreeCache) regCenter.getRawCache("/" + jobName);
    cache.getListenable().addListener(listener);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

Example 4 with TreeCache

use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.

the class CloudJobConfigurationListener method getCache.

private TreeCache getCache() {
    TreeCache result = (TreeCache) regCenter.getRawCache(CloudJobConfigurationNode.ROOT);
    if (null != result) {
        return result;
    }
    regCenter.addCacheData(CloudJobConfigurationNode.ROOT);
    return (TreeCache) regCenter.getRawCache(CloudJobConfigurationNode.ROOT);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache)

Example 5 with TreeCache

use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.

the class JobNodeStorageTest method assertAddDataListener.

@Test
public void assertAddDataListener() {
    TreeCache treeCache = mock(TreeCache.class);
    @SuppressWarnings("unchecked") Listenable<TreeCacheListener> listeners = mock(Listenable.class);
    TreeCacheListener listener = mock(TreeCacheListener.class);
    when(treeCache.getListenable()).thenReturn(listeners);
    when(regCenter.getRawCache("/test_job")).thenReturn(treeCache);
    jobNodeStorage.addDataListener(listener);
    verify(listeners).addListener(listener);
}
Also used : TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) TreeCacheListener(org.apache.curator.framework.recipes.cache.TreeCacheListener) Test(org.junit.Test)

Aggregations

TreeCache (org.apache.curator.framework.recipes.cache.TreeCache)6 ChildData (org.apache.curator.framework.recipes.cache.ChildData)2 TreeCacheListener (org.apache.curator.framework.recipes.cache.TreeCacheListener)1 KeeperException (org.apache.zookeeper.KeeperException)1 Test (org.junit.Test)1