Java Code Examples for org.apache.curator.framework.recipes.cache.NodeCache#close()

The following examples show how to use org.apache.curator.framework.recipes.cache.NodeCache#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZKRegistry.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> doUnsubscribe(final ConfigBooking booking) {
    NodeCache cache = ((ZKConfigBooking) booking).getNodeCache();
    if (cache != null) {
        try {
            cache.close();
        } catch (IOException ignored) {
        }
    }
    return CompletableFuture.completedFuture(null);
}
 
Example 2
Source File: ZkClient.java    From xio with Apache License 2.0 5 votes vote down vote up
public void stopNodeCache(NodeCache cache) {
  try {
    cache.close();
  } catch (IOException e) {
    log.error("Error stopping nodeCache {}", cache, e);
    throw new RuntimeException(e);
  }
}
 
Example 3
Source File: CuratorClientService.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void removeEntryListener(String path) throws Exception {
    NodeCache nodeCache = entryNodeCaches.remove(path);
    if (nodeCache != null) {
        nodeCache.close();
    }
}
 
Example 4
Source File: TestEndToEndScenariosWithHA.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
@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 =========================");
}