本文整理汇总了Java中org.apache.curator.framework.recipes.cache.NodeCache.close方法的典型用法代码示例。如果您正苦于以下问题:Java NodeCache.close方法的具体用法?Java NodeCache.close怎么用?Java NodeCache.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.cache.NodeCache
的用法示例。
在下文中一共展示了NodeCache.close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: close
import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
/**
* 关闭(释放相关资源)
*/
public void close() {
for (NodeCache nodeCache : nodeCaches) {
try {
nodeCache.close();
} catch (IOException e) {
logger.error("关闭节点监听器出错:", e);
}
}
zkTemplate.close();
}
示例3: stop
import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@Override
public void stop() {
singleThreadExecutor.shutdown();
nodes.forEach(CloseableUtils::closeQuietly);
for (NodeCache node : nodes) {
try {
node.close();
} catch (IOException e) {
// ignored.
logger.warn("[{}] Close ZK node cache failed. message={}", gondola.getHostId(), e.getMessage());
}
}
Utils.stopThreads(threads);
}
示例4: close
import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public synchronized void close() { // TODO: implemente with AtomicReference<CloseFuture>
logger.info("Close zookeeper client");
try {
for (NodeCache cache : cachePool) {
logger.info("Close cache {}", cache);
cache.getListenable().clear();
cache.close();
}
cachePool.clear();
} catch (IOException e) {
logger.error("Error while closing zookeeper node listening caches", e);
}
client.close();
}
示例5: stopNodeCache
import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
public void stopNodeCache(NodeCache cache) {
try {
cache.close();
} catch (IOException e) {
log.error("Error stopping nodeCache {}", cache, e);
throw new RuntimeException(e);
}
}
示例6: onStop
import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@Override
public void onStop(final CuratorFramework curator) throws IOException
{
for (NodeCache childrenCache : childrens) {
childrenCache.close();
}
}
示例7: setup
import org.apache.curator.framework.recipes.cache.NodeCache; //导入方法依赖的package包/类
@BeforeMethod(alwaysRun = true, timeOut = 30_000)
public void setup() throws Exception {
// Get the zkConnection string from minicluster
String zkConnection = "localhost:" + hBaseUtils.getZkCluster().getClientPort();
zkClient = provideInitializedZookeeperClient(zkConnection);
// Synchronize TSO start
barrierTillTSOAddressPublication = new CountDownLatch(1);
final NodeCache currentTSOZNode = new NodeCache(zkClient, CURRENT_TSO_PATH);
currentTSOZNode.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
byte[] currentTSOAndEpochAsBytes = currentTSOZNode.getCurrentData().getData();
String currentTSOAndEpoch = new String(currentTSOAndEpochAsBytes, Charsets.UTF_8);
if (currentTSOAndEpoch.endsWith("#0")) { // Wait till a TSO instance publishes the epoch
barrierTillTSOAddressPublication.countDown();
}
}
});
currentTSOZNode.start(true);
// Configure TSO 1
TSOServerConfig config1 = new TSOServerConfig();
config1.setPort(TSO1_PORT);
config1.setConflictMapSize(1000);
config1.setLeaseModule(new TestHALeaseManagementModule(TEST_LEASE_PERIOD_MS, TSO_LEASE_PATH, CURRENT_TSO_PATH, zkConnection, NAMESPACE));
Injector injector1 = Guice.createInjector(new TestTSOModule(hbaseConf, config1));
LOG.info("===================== Starting TSO 1 =====================");
tso1 = injector1.getInstance(TSOServer.class);
leaseManager1 = (PausableLeaseManager) injector1.getInstance(LeaseManagement.class);
tso1.startAndWait();
TestUtils.waitForSocketListening("localhost", TSO1_PORT, 100);
LOG.info("================ Finished loading TSO 1 ==================");
// Configure TSO 2
TSOServerConfig config2 = new TSOServerConfig();
config2.setPort(TSO2_PORT);
config2.setConflictMapSize(1000);
config2.setLeaseModule(new TestHALeaseManagementModule(TEST_LEASE_PERIOD_MS, TSO_LEASE_PATH, CURRENT_TSO_PATH, zkConnection, NAMESPACE));
Injector injector2 = Guice.createInjector(new TestTSOModule(hbaseConf, config2));
LOG.info("===================== Starting TSO 2 =====================");
tso2 = injector2.getInstance(TSOServer.class);
injector2.getInstance(LeaseManagement.class);
tso2.startAndWait();
// Don't do this here: TestUtils.waitForSocketListening("localhost", 4321, 100);
LOG.info("================ Finished loading TSO 2 ==================");
// Wait till the master TSO is up
barrierTillTSOAddressPublication.await();
currentTSOZNode.close();
// Configure HBase TM
LOG.info("===================== Starting TM =====================");
HBaseOmidClientConfiguration hbaseOmidClientConf = new HBaseOmidClientConfiguration();
hbaseOmidClientConf.setConnectionType(HA);
hbaseOmidClientConf.setConnectionString(zkConnection);
hbaseOmidClientConf.getOmidClientConfiguration().setZkCurrentTsoPath(CURRENT_TSO_PATH);
hbaseOmidClientConf.getOmidClientConfiguration().setZkNamespace(NAMESPACE);
hbaseOmidClientConf.setHBaseConfiguration(hbaseConf);
hbaseConf.setInt(HBASE_CLIENT_RETRIES_NUMBER, 3);
tm = HBaseTransactionManager.builder(hbaseOmidClientConf).build();
LOG.info("===================== TM Started =========================");
}