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


Java NodeCacheListener类代码示例

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


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

示例1: runWatch

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
/**
 * @param cache    NodeCache
 * @param zkListen
 * @throws Exception
 * @Created 2016/9/20
 */
private static void runWatch(final NodeCache cache, final ZookeeperProcessListen zkListen)
        throws Exception {
    cache.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() {
            LOGGER.info("ZktoxmlMain runWatch  process path  event start ");
            String notPath = cache.getCurrentData().getPath();
            LOGGER.info("NodeCache changed, path is: " + notPath);
            // notify
            zkListen.notify(notPath);
            LOGGER.info("ZktoxmlMain runWatch  process path  event over");
        }
    });
}
 
开发者ID:actiontech,项目名称:dble,代码行数:22,代码来源:ZktoXmlMain.java

示例2: test_zkNode

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的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: start

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
@Override
public void start() throws Exception {
    // Create the zookeeper node
    createNode();
    // Initial data load (avoid race conditions w/"NodeCache.start(true)")
    updateFromZkBytes(_curator.getData().forPath(_zkPath), _defaultValue);

    // Re-load the data and watch for changes.
    _nodeCache.getListenable().addListener(new NodeCacheListener() {
        @Override
        public void nodeChanged() throws Exception {
            ChildData childData = _nodeCache.getCurrentData();
            if (childData != null) {
                updateFromZkBytes(childData.getData(), _defaultValue);
            }
        }
    });
    _nodeCache.start();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:20,代码来源:ZkValueStore.java

示例4: start

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
public void start() throws Exception {
    started.set(true);
    if (curatorFramework.checkExists().forPath(path) == null) {
        try {
            curatorFramework.create().creatingParentsIfNeeded().forPath(path, "{}".getBytes());
        } catch (KeeperException.NodeExistsException ex) {
            log.info("Node exists on create, continuing");
        }
    }

    this.nodeCacheListener = new NodeCacheListener() {
        @Override
        public void nodeChanged() throws Exception {
            notifyListeners(get());
        }
    };

    this.nodeCache.getListenable().addListener(nodeCacheListener);
    this.nodeCache.start(true);
}
 
开发者ID:librato,项目名称:watchconf,代码行数:21,代码来源:DynamicConfigZKAdapter.java

示例5: main

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的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.NodeCacheListener; //导入依赖的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: createValue_TriggersListenerOnPropagate

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
@Test
public void createValue_TriggersListenerOnPropagate() throws Exception {
    String value = "foo";

    final CountDownLatch latch = new CountDownLatch(1);

    container.addListener(new NodeCacheListener() {
        @Override
        public void nodeChanged() throws Exception {
            latch.countDown();
        }
    });

    framework.create().creatingParentsIfNeeded().forPath("/dev/test", value.getBytes(Charsets.UTF_8));

    latch.await();

    assertEquals(value, container.get());
}
 
开发者ID:ReadyTalk,项目名称:cultivar,代码行数:20,代码来源:NodeContainerIntegTest.java

示例8: runOneIteration

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
@Override
protected void runOneIteration() {
    String newValue = PropertyReader.getProperty(propOverride);

    if (!Objects.equal(newValue, lastValue)) {
        for (final Map.Entry<NodeCacheListener, Executor> o : listeners.entrySet()) {
            o.getValue().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        o.getKey().nodeChanged();
                    } catch (Exception ex) {
                        LOG.warn("Exception when processing node change.", ex);
                    }
                }
            });
        }
    }
}
 
开发者ID:ReadyTalk,项目名称:cultivar,代码行数:20,代码来源:PropertyOverrideNodeContainer.java

示例9: start

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
@Override
public void start() throws Exception {
    if (!isStarted.compareAndSet(false, true)) {
        throw new RuntimeException("Service already started!");
    }
    if (framework.getState() != CuratorFrameworkState.STARTED) {
        throw new RuntimeException("CuratorFramework is not started!");
    }
    nodeCache.getListenable().addListener(new NodeCacheListener() {
        @Override
        public void nodeChanged() throws Exception {
            build();
        }
    });
    nodeCache.start(true);
    build();
}
 
开发者ID:librato,项目名称:rollout-java,代码行数:18,代码来源:RolloutZKClient.java

示例10: registerListener

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的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

示例11: serviceStart

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的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

示例12: listenForZNode

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的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

示例13: forcReadListenForZNode

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的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

示例14: _initCacheWatcher

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
private void _initCacheWatcher() {
    cacheNodeWatcher = CacheBuilder.newBuilder()
            .concurrencyLevel(Runtime.getRuntime().availableProcessors()).maximumSize(10000)
            .expireAfterAccess(3600, TimeUnit.SECONDS)
            .removalListener(new RemovalListener<String, NodeCache>() {
                @Override
                public void onRemoval(RemovalNotification<String, NodeCache> event) {
                    try {
                        event.getValue().close();
                    } catch (IOException e) {
                        LOGGER.warn(e.getMessage(), e);
                    }
                }
            }).build(new CacheLoader<String, NodeCache>() {
                @Override
                public NodeCache load(final String path) throws Exception {
                    final NodeCache nodeCache = new NodeCache(curatorFramework, path);
                    nodeCache.getListenable().addListener(new NodeCacheListener() {
                        @Override
                        public void nodeChanged() throws Exception {
                            ChildData data = nodeCache.getCurrentData();
                            _invalidateCache(path, data != null ? data.getData() : null);
                        }
                    });
                    nodeCache.start();
                    return nodeCache;
                }
            });
}
 
开发者ID:DDTH,项目名称:ddth-zookeeper,代码行数:30,代码来源:ZooKeeperClient.java

示例15: registerUpdater

import org.apache.curator.framework.recipes.cache.NodeCacheListener; //导入依赖的package包/类
public void registerUpdater(ConfigurationUpdater updater) {
  NodeCache cache = getOrCreateNodeCache(updater.getPath());

  cache
      .getListenable()
      .addListener(
          new NodeCacheListener() {
            @Override
            public void nodeChanged() {
              updater.update(cache.getCurrentData().getData());
            }
          });
}
 
开发者ID:xjdr,项目名称:xio,代码行数:14,代码来源:ZkClient.java


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