@Test public void testRebuildNode() throws Exception { Timing timing = new Timing(); PathChildrenCache cache = null; CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); try { client.start(); client.create().creatingParentsIfNeeded().forPath("/test/one", "one".getBytes()); final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger counter = new AtomicInteger(); final Semaphore semaphore = new Semaphore(1); cache = new PathChildrenCache(client, "/test", true) { @Override void getDataAndStat(String fullPath) throws Exception { semaphore.acquire(); counter.incrementAndGet(); super.getDataAndStat(fullPath); latch.countDown(); } }; cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); Assert.assertTrue(timing.awaitLatch(latch)); int saveCounter = counter.get(); client.setData().forPath("/test/one", "alt".getBytes()); cache.rebuildNode("/test/one"); Assert.assertEquals(cache.getCurrentData("/test/one").getData(), "alt".getBytes()); Assert.assertEquals(saveCounter, counter.get()); semaphore.release(1000); timing.sleepABit(); } finally { CloseableUtils.closeQuietly(cache); TestCleanState.closeAndTestClean(client); } }
public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(state.get() == State.STARTED, "cache has been closed"); ensurePath(); internalRebuildNode(fullPath); offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); }
PathChildrenCache implements Closeable { public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(state.get() == State.STARTED, "cache has been closed"); ensurePath(); internalRebuildNode(fullPath); offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); } }
PathChildrenCache implements Closeable { public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(state.get() == State.STARTED, "cache has been closed"); ensurePath(); internalRebuildNode(fullPath); offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); } @Deprecated @SuppressWarnings("deprecation")  PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode); @Deprecated @SuppressWarnings("deprecation")  PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final ExecutorService executorService);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService); }
PathChildrenCache implements Closeable { public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(state.get() == State.STARTED, "cache has been closed"); ensurePath(); internalRebuildNode(fullPath); offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); } @Deprecated @SuppressWarnings("deprecation")  PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode); @Deprecated @SuppressWarnings("deprecation")  PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final ExecutorService executorService);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService); void start(); @Deprecated void start(boolean buildInitial); void start(StartMode mode); void rebuild(); void rebuildNode(String fullPath); @Override void close(); ListenerContainer<PathChildrenCacheListener> getListenable(); List<ChildData> getCurrentData(); ChildData getCurrentData(String fullPath); void clearDataBytes(String fullPath); boolean clearDataBytes(String fullPath, int ifVersion); void clearAndRefresh(); void clear(); }
PathChildrenCache implements Closeable { public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(state.get() == State.STARTED, "cache has been closed"); ensurePath(); internalRebuildNode(fullPath); offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); } @Deprecated @SuppressWarnings("deprecation")  PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode); @Deprecated @SuppressWarnings("deprecation")  PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, ThreadFactory threadFactory);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final ExecutorService executorService);  PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService); void start(); @Deprecated void start(boolean buildInitial); void start(StartMode mode); void rebuild(); void rebuildNode(String fullPath); @Override void close(); ListenerContainer<PathChildrenCacheListener> getListenable(); List<ChildData> getCurrentData(); ChildData getCurrentData(String fullPath); void clearDataBytes(String fullPath); boolean clearDataBytes(String fullPath, int ifVersion); void clearAndRefresh(); void clear(); static final ThreadFactory defaultThreadFactory; }