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


Java TreeCache.start方法代码示例

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


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

示例1: watchTree

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
public boolean watchTree(String path, TreeCacheListener listener) {
    TreeCache tc = nodeTreeCache.get(path);
    if (tc != null) {
        return false; // node been listened
    }

    try {
        tc = TreeCache.newBuilder(client, path).build();
        tc.start();

        if (executor != null) {
            tc.getListenable().addListener(listener, executor);
        } else {
            tc.getListenable().addListener(listener);
        }

        nodeTreeCache.put(path, tc);
        return true;
    } catch (Throwable e) {
        throw checkException(String.format("Unable to watch tree for path: %s", path), e);
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:23,代码来源:ZKClient.java

示例2: addChildNodeListener

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@SuppressWarnings("resource")
@Override
public void addChildNodeListener(String path, ChildNodeListener listener) {
	TreeCache cache = new TreeCache(client, path);
	cache.getListenable().addListener((curatorFramework, event) -> {
		if (null != event && null != event.getData() && null != event.getType()) {
			String servicePath = event.getData().getPath();
			if (servicePath.split("/").length > 3) {
				if (null != event.getData().getData()) {
					listener.childChanged(servicePath, event.getType().toString(),
							new String(event.getData().getData()));
				} else {
					listener.childChanged(servicePath, event.getType().toString(), null);
				}
			}
		}
	});
	try {
		cache.start();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:24,代码来源:CuratorZookeeperClient.java

示例3: start

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
public static void start() throws Exception {
    if (!started) {
        synchronized (RegistryManager.class) {
            if (!started) {
                String zookeeperAddress = ConfigManager.getInstance().getProperty(Constants.ZOOKEEPER_ADDRESS);

                RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
                client = CuratorFrameworkFactory.newClient(zookeeperAddress, retryPolicy);

                client.start();

                TreeCache treeCache = TreeCache.newBuilder(client, Constants.SERVICE_ZK_PATH_PREFIX).setCacheData(false).build();
                treeCache.getListenable().addListener(new ProviderNodeEventListener(), curatorEventThreadPool);
                treeCache.start();

                started = client.blockUntilConnected(1000, TimeUnit.MILLISECONDS);
            }
        }
    }
}
 
开发者ID:zxcpro,项目名称:zing,代码行数:21,代码来源:RegistryManager.java

示例4: checkTreeCache

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
private static void checkTreeCache(CuratorFramework curatorFramework, String path) throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    TreeCache treeCache = TreeCache.newBuilder(curatorFramework, path)
            .setCacheData(true)
            .setMaxDepth(3)
            .build();

    if (treeCache == null) {
        LOGGER.error("treeCache is null");
    }

    treeCache.getListenable().addListener((client, event) -> {
        if (event.getType().equals(TreeCacheEvent.Type.INITIALIZED)) {
            semaphore.release();
        }
    });

    treeCache.start();

    semaphore.tryAcquire(2, TimeUnit.SECONDS);


    Map<String, ChildData> map = treeCache.getCurrentChildren("/propertyService");

   if (map == null) {
       LOGGER.error("map is null");
   }

    map.entrySet().forEach(entry -> {
        LOGGER.info("{} - {}", entry.getKey(), Bytes.toString(entry.getValue().getData()));
    });
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:33,代码来源:CuratorTest.java

示例5: addCacheData

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@Override
public void addCacheData(final String cachePath) {
	TreeCache cache = new TreeCache(client, cachePath);
	try {
		cache.start();
		// CHECKSTYLE:OFF
	} catch (final Exception ex) {
		// CHECKSTYLE:ON
		RegExceptionHandler.handleException(ex);
	}
	caches.put(cachePath + "/", cache);
}
 
开发者ID:imadcn,项目名称:idworker,代码行数:13,代码来源:ZookeeperRegistryCenter.java

示例6: addCacheData

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@Override
public void addCacheData(final String cachePath) {
    TreeCache cache = new TreeCache(client, cachePath);
    try {
        cache.start();
    //CHECKSTYLE:OFF
    } catch (final Exception ex) {
    //CHECKSTYLE:ON
        RegExceptionHandler.handleException(ex);
    }
    caches.put(cachePath + "/", cache);
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:13,代码来源:ZookeeperRegistryCenter.java

示例7: testNamespaces

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@Test
public void testNamespaces() throws Exception {
    final URL res = Namespaces.class.getResource(nsDoc);
    final CuratorFramework zk = newClient(curator.getConnectString(), new RetryNTimes(10, 1000));
    zk.start();
    final TreeCache cache = new TreeCache(zk, ZNODE_NAMESPACES);
    cache.start();

    final NamespaceService svc1 = new Namespaces(zk, cache, res.getPath() + randomFilename());

    assertEquals(0, svc1.getNamespaces().size());

    final NamespaceService svc2 = new Namespaces(zk, cache, res.getPath());

    assertEquals(2, svc2.getNamespaces().size());
    assertEquals(LDP.URI, svc2.getNamespace("ldp").get());
    assertEquals("ldp", svc2.getPrefix(LDP.URI).get());

    assertFalse(svc2.getNamespace("jsonld").isPresent());
    assertFalse(svc2.getPrefix(JSONLD.URI).isPresent());
    assertTrue(svc2.setPrefix("jsonld", JSONLD.URI));
    assertEquals(3, svc2.getNamespaces().size());
    assertEquals(JSONLD.URI, svc2.getNamespace("jsonld").get());
    assertEquals("jsonld", svc2.getPrefix(JSONLD.URI).get());

    final Namespaces svc3 = new Namespaces(zk, cache);
    await().atMost(5, SECONDS).until(() -> 3 == svc3.getNamespaces().size());
    assertEquals(JSONLD.URI, svc3.getNamespace("jsonld").get());
    assertFalse(svc3.setPrefix("jsonld", JSONLD.URI));
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:31,代码来源:NamespacesTest.java

示例8: ZKAsyncMultiMap

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
ZKAsyncMultiMap(Vertx vertx, CuratorFramework curator, String mapName) {
  super(curator, vertx, ZK_PATH_ASYNC_MULTI_MAP, mapName);

  // /io.vertx/asyncMultiMap/subs
  curatorCache = new TreeCache(curator, mapPath);
  try {
    curatorCache.start();
  } catch (Exception e) {
    throw new VertxException(e);
  }
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:12,代码来源:ZKAsyncMultiMap.java

示例9: addCacheData

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@Override
public void addCacheData(final String cachePath) {
    TreeCache cache = new TreeCache(client, cachePath);
    try {
        cache.start();
    }
    catch (final Exception ex) {
        RegisterExceptionHandler.handleException(ex);
    }
    caches.put(cachePath + "/", cache);
}
 
开发者ID:ErinDavid,项目名称:elastic-config,代码行数:12,代码来源:ZookeeperRegistryCenter.java

示例10: startWatch

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
private boolean startWatch(long logIndex, CuratorFramework zkclient) {
    String flag = getClassName() + ".startWatch";
    TreeCache cache = new TreeCache(zkclient, ZK_ROOT);
    try {

        cache.start();
        this.addListener(logIndex, cache);
    } catch (Exception e) {
        FRCLogger.getInstance().warn(logIndex, flag, "ZkWatchRunnable thread run fail!", e);
        return false;
    }
    return true;
}
 
开发者ID:songbin,项目名称:frc,代码行数:14,代码来源:ZkClient.java

示例11: main

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    // Connect to zk
    try (
            CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeprUrls, new ExponentialBackoffRetry(1000, 3));) {

        client.start();
        System.err.println("CuratorFramework start....");
        // Register watcher
        TreeCache treeCache = new TreeCache(client, BasePath);
        treeCache.getListenable().addListener((curatorClient, treeCacheEvent) -> {
            ChildData childData = treeCacheEvent.getData();
            if (childData == null) {
                System.err.println("No data in event" + treeCacheEvent);
            } else {
                System.err.println("Receive event:"
                        + "type:" + treeCacheEvent.getType()
                        + ", path:" + childData.getPath()
                        + ", data:" + String.valueOf(childData.getData())
                        + ", stat:" + childData.getStat());
            }
        });

        treeCache.start();
        System.err.println("tree cache start..");

        TimeUnit.MINUTES.sleep(5);
        treeCache.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:34,代码来源:CuratorWatcher2.java

示例12: main

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
    CuratorFramework client = CreateClientExamples.createSimple("127.0.0.1:2181");
    client.getUnhandledErrorListenable().addListener((message, e) -> {
        System.err.println("error=" + message);
        e.printStackTrace();
    });
    client.getConnectionStateListenable().addListener((c, newState) -> {
        System.out.println("state=" + newState);
    });
    client.start();

    TreeCache cache = TreeCache.newBuilder(client, "/").setCacheData(false).build();
    cache.getListenable().addListener((c, event) -> {
        if ( event.getData() != null )
        {
            System.out.println("type=" + event.getType() + " path=" + event.getData().getPath());
        }
        else
        {
            System.out.println("type=" + event.getType());
        }
    });
    cache.start();

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    in.readLine();
}
 
开发者ID:apache,项目名称:curator,代码行数:29,代码来源:TreeCacheExample.java

示例13: initLocalCache

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
private void initLocalCache(String watchRootPath) throws Exception {
    cache = new TreeCache(client, watchRootPath);
    cache.start();
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:5,代码来源:ZKClient.java

示例14: test_tree_cache

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@Test
public void test_tree_cache() throws Exception {
    String rootPath = "/namespace-test";
    CuratorFramework zk = curator.usingNamespace("namespace-test");
    String groupPath = "/group-1";
    String s = zk.create().forPath(groupPath,"group-1-data".getBytes());
    Assert.assertEquals(groupPath, s);
    Stat stat = zk.checkExists().forPath("/group-1");
    Assert.assertNotNull(stat);
    stat = zk.checkExists().forPath(rootPath);
    Assert.assertNull(stat);

    final TreeCacheEvent.Type[] saveEventType = new TreeCacheEvent.Type[1];
    final long[] saveTime = new long[1];
    TreeCache treeCache = new TreeCache(curator, rootPath);
    treeCache.start();
    ChildData childData = treeCache.getCurrentData("/namespace-test/group-1");

    treeCache.getListenable().addListener(new TreeCacheListener() {

        @Override
        public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
            logger.info("event type={}", event.getType());
            switch (event.getType()) {
                case NODE_ADDED:
                    saveEventType[0] = TreeCacheEvent.Type.NODE_ADDED;
                    saveTime[0] = System.currentTimeMillis();
                    logger.info("child[path={}, date={}] added", event.getData().getPath(), new String(event.getData().getData()));
                    break;
                case NODE_UPDATED:
                    saveEventType[0] = TreeCacheEvent.Type.NODE_UPDATED;
                    saveTime[0] = System.currentTimeMillis();
                    logger.info("child[path={}, date={}] updated", event.getData().getPath(), new String(event.getData().getData()));
                    break;
                case NODE_REMOVED:
                    saveEventType[0] = TreeCacheEvent.Type.NODE_REMOVED;
                    saveTime[0] = System.currentTimeMillis();
                    logger.info("child[path={}, date={}] updated", event.getData().getPath(), new String(event.getData().getData()));
                    break;
                case CONNECTION_SUSPENDED:
                    break;
                case CONNECTION_RECONNECTED:
                    break;
                case CONNECTION_LOST:
                    break;
                case INITIALIZED:
                    break;
            }
        }
    });
    String hostPath = groupPath + "/localhost:8001";
    zk.create().forPath(hostPath);
    long wtStart = System.currentTimeMillis();
    Thread.sleep(300);
    // use 15 ms
    // System.out.println("listener wait time="+(saveTime[0] - wtStart));
    Assert.assertEquals(TreeCacheEvent.Type.NODE_ADDED, saveEventType[0]);
    // System.out.println(new String(zk.getData().forPath(hostPath)));

    // create three node
    String threePath = groupPath + "/hosts/localhost:8001";
    zk.create().creatingParentsIfNeeded().forPath(threePath);
    zk.setData().forPath(threePath, "{tree}".getBytes());
    // test update
    zk.setData().forPath(hostPath, "{}".getBytes());
    Thread.sleep(300);
    Assert.assertEquals(TreeCacheEvent.Type.NODE_UPDATED, saveEventType[0]);

    // test set parent node's data
    zk.setData().forPath("/group-1", "{grou-data}".getBytes());
    Thread.sleep(300);
    Assert.assertEquals(TreeCacheEvent.Type.NODE_UPDATED, saveEventType[0]);
}
 
开发者ID:netboynb,项目名称:coco,代码行数:74,代码来源:CuratorTest.java

示例15: TenantDebugger

import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
public TenantDebugger(Curator curator) throws Exception {
    cache = new TreeCache(curator.framework(), "/config/v2/tenants");
    cache.getListenable().addListener(this);
    cache.start();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:6,代码来源:TenantDebugger.java


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