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


Java NodeCache.start方法代码示例

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


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

示例1: startup

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@Override
public void startup()
{
	if( isCluster() )
	{
		CuratorFramework curator = getCurator();
		debugCache = new NodeCache(curator, CLUSTER_DEBUG_FULL_PATH);
		try
		{
			debugCache.start();
			createNode(SERVER_REL_PATH, "");
			membersCache = createPathCache(SERVER_REL_PATH, false);
			ensureDebug = curator.newNamespaceAwareEnsurePath(CLUSTER_DEBUG_FULL_PATH);
		}
		catch( Exception e )
		{
			Throwables.propagate(e);
		}
	}
	hasStarted = true;
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:ZookeeperServiceImpl.java

示例2: test_zkNode

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@Test
public void test_zkNode() throws Exception {
    CuratorFramework zk = curator.usingNamespace("namespace-test");
    String groupPath = "/group-1/localhost:9001";
    String s = zk.create().creatingParentsIfNeeded().forPath(groupPath);
    Assert.assertEquals(s, "/group-1/localhost:9001");
    NodeCache nodeCache = new NodeCache(zk, "/group-1", true);
    nodeCache.start();
    nodeCache.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            logger.info("node cache change");
        }
    });
    zk.setData().forPath("/group-1", "test-0".getBytes());
    zk.setData().forPath("/group-1", "test-2".getBytes());
}
 
开发者ID:netboynb,项目名称:coco,代码行数:19,代码来源:CuratorTest.java

示例3: initProvider

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private void initProvider(CuratorFramework client, String serviceName) throws Exception {
    this.client = client;
    this.serviceName = serviceName;
    tmpFile = confFile(true);
    confFile = confFile(false);
    String configPath = ZookeeperUtils.configPath(serviceName);

    byte[] bytes = client.getData().forPath(configPath);
    saveFile(bytes);
    cache = new NodeCache(client, configPath);
    cache.getListenable().addListener(() -> {
        try {
            if (cache.getCurrentData() != null) {
                byte[] data = cache.getCurrentData().getData();
                if (data.length > 0) {
                    saveFile(data);
                }
            }
        } catch (Exception e) {
            logger.warn("Error while processing config file change event. message={}", e.getMessage());
        }
    });
    cache.start();
}
 
开发者ID:yahoo,项目名称:gondola,代码行数:25,代码来源:ZookeeperConfigProvider.java

示例4: addNodeCacheListener

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public void addNodeCacheListener(String path) throws Exception {
    Stat existStat = curatorFramework
            .checkExists()
            .forPath(path);
    if (existStat == null)
        curatorFramework
                .create()
                .creatingParentsIfNeeded()
                .withMode(CreateMode.PERSISTENT)
                .forPath(path);
    NodeCache nodeCache = new NodeCache(curatorFramework, path, false);
    nodeCache.start();
    nodeCache.getListenable().addListener(() -> {
                ChildData currentData = nodeCache.getCurrentData();
                LOG.info("New Cache Data: {}", currentData == null ? "null" : new String(currentData.getData()));
            }
    );
}
 
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:19,代码来源:CuratorNodeCache.java

示例5: main

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    CuratorFramework framework = CuratorFrameworkFactory.builder()
            .connectString("localhost:2181").retryPolicy(new RetryNTimes(3, 2000)).build();
    try {
        framework.start();
        final NodeCache nodeCache = new NodeCache(framework, "/test");
        nodeCache.getListenable().addListener(new NodeCacheListener() {
            @Override
            public void nodeChanged() throws Exception {
                ChildData data = nodeCache.getCurrentData();
                System.out.println(new String(data.getData()) + " / " + data);
            }
        });
        nodeCache.start();

        Thread.sleep(30000);

        nodeCache.close();
    } finally {
        framework.close();
    }
}
 
开发者ID:DDTH,项目名称:ddth-zookeeper,代码行数:23,代码来源:TestCuratorNodeWatch.java

示例6: start

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
/**
 * Start.
 *
 * @throws Exception the exception
 */
public void start() throws Exception { //NOSONAR
  LOG.info("Starting node tracker");
  zkClient.getUnhandledErrorListenable().addListener(errorsListener);
  if (createZkNode()) {
    controlCache = new NodeCache(zkClient, CONTROL_SERVER_NODE_PATH);
    controlCache.getListenable().addListener(new NodeCacheListener() {

      @Override
      public void nodeChanged() throws Exception {
        ChildData currentData = controlCache.getCurrentData();
        if (currentData == null) {
          LOG.warn("Control service node died!");
          onNoMaster();
        } else {
          LOG.warn("Control service node changed!");
          onMasterChange(currentData);
        }
      }
    });
    controlCache.start();
  } else {
    LOG.warn("Failed to create ZK node!");
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:30,代码来源:ControlNodeTracker.java

示例7: registerListener

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private void registerListener(final CuratorFramework curator, final String path, final ZookeeperConfigurationListener listener) throws Exception
{
    final NodeCache cache   = new NodeCache(curator, path, true);
    
    cache.start();
    cache.getListenable().addListener(new NodeCacheListener()
    {
        @Override
        public void nodeChanged() throws Exception
        {
            listener.onChange(curator, cache, path);
        }
    });

    childrens.add(cache);
    logger.info(String.format("Add listener %s for %s", listener, path));
}
 
开发者ID:interruptus,项目名称:interruptus,代码行数:18,代码来源:AttachConfigurationListener.java

示例8: loadZkWatch

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private static void loadZkWatch(Set<String> setPaths, final CuratorFramework zkConn,
                                final ZookeeperProcessListen zkListen) throws Exception {
    if (null != setPaths && !setPaths.isEmpty()) {
        for (String path : setPaths) {
            final NodeCache node = new NodeCache(zkConn, path);
            node.start(true);
            runWatch(node, zkListen);
            LOGGER.info("ZktoxmlMain loadZkWatch path:" + path + " regist success");
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:12,代码来源:ZktoXmlMain.java

示例9: serviceStart

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@Override
protected void serviceStart() throws Exception {
    framework.start();
    nodeCache = new NodeCache(framework, zkMountTablePath, false);
    nodeCache.getListenable().addListener(new NodeCacheListener() {
        @Override
        public void nodeChanged() throws Exception {
            handleMountTableChange(nodeCache.getCurrentData().getData());
        }
    });
    nodeCache.start(false);
}
 
开发者ID:bytedance,项目名称:nnproxy,代码行数:13,代码来源:MountsManager.java

示例10: configureCurrentTSOServerZNodeCache

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private void configureCurrentTSOServerZNodeCache(String currentTsoPath) {
    try {
        currentTSOZNode = new NodeCache(zkClient, currentTsoPath);
        currentTSOZNode.getListenable().addListener(this);
        currentTSOZNode.start(true);
    } catch (Exception e) {
        throw new IllegalStateException("Cannot start watcher on current TSO Server ZNode: " + e.getMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:10,代码来源:TSOClient.java

示例11: listenForZNode

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
/**
 * Listen for a single node
 *
 * @param path
 * @param listener
 * @throws Exception
 */
public void listenForZNode(String path, ZookeeperEventListener listener) throws Exception {
    init();
    // TODO: simplify code of this method to:
    // ZNodeListener nodeListener = new ZNodeListener(path, listener, client);

    NodeCache cache = new NodeCache(client, path);
    cache.start();

    NodeCacheListener cacheListener = new ZNodeListener(
            listener.getHandler(), cache);

    cache.getListenable().addListener(cacheListener);
    cachePool.add(cache);
}
 
开发者ID:odiszapc,项目名称:stem,代码行数:22,代码来源:ZookeeperClient.java

示例12: forcReadListenForZNode

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public void forcReadListenForZNode(String path, ZookeeperEventListener listener) throws Exception {
    init();
    NodeCache cache = new NodeCache(client, path);
    cache.start();

    NodeCacheListener cacheListener = new ZNodeListener(
            listener.getHandler(), cache);

    cache.getListenable().addListener(cacheListener);
    cacheListener.nodeChanged();
    cachePool.add(cache);
}
 
开发者ID:odiszapc,项目名称:stem,代码行数:13,代码来源:ZookeeperClient.java

示例13: create

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
private void create() throws Exception {
  client =
      CuratorFrameworkFactory.builder().connectString(ensemble).sessionTimeoutMs(sessionTimeout)
          .retryPolicy(new RetryForever(1000)).canBeReadOnly(true).build();
  client.start();
  cache = new NodeCache(client, NODE);
  cache.start(true);
}
 
开发者ID:apache,项目名称:hbase,代码行数:9,代码来源:ZooKeeperScanPolicyObserver.java

示例14: startNodeCache

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public void startNodeCache(NodeCache cache) {
  try {
    cache.start();
  } catch (Exception e) {
    log.error("Error starting nodeCache {}", cache, e);
    throw new RuntimeException(e);
  }
}
 
开发者ID:xjdr,项目名称:xio,代码行数:9,代码来源:ZkClient.java

示例15: init

import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public void init() {
    try
    {
        logger.info("init...");
        client = CuratorFrameworkFactory.newClient(
            ConfigurationManager.getConfiguration().getString(ZOOKEEPER_SERVER),
            new ExponentialBackoffRetry(1000, 3));
        client.start();

        // in this example we will cache data. Notice that this is optional.
        cache = new NodeCache(client, getZKPath());
        cache.start();

        cache.getListenable().addListener(this);

        nodeChanged();

    } catch (Exception e) {
        logger.info("error ", e);
    }
    /*
    finally
    {
        CloseableUtils.closeQuietly(cache);
        CloseableUtils.closeQuietly(client);
    }
    */
}
 
开发者ID:lyogavin,项目名称:Pistachio,代码行数:29,代码来源:CustomizationRegistry.java


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