本文整理汇总了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;
}
示例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());
}
示例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();
}
示例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()));
}
);
}
示例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();
}
}
示例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!");
}
}
示例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));
}
示例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");
}
}
}
示例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);
}
示例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());
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
*/
}