@Override public List<String> run() throws KeeperException, InterruptedException { // only read volatile once for consistency ImmutableCacheCopies lic = immutableCache; if (lic.childrenCache.containsKey(zPath)) { return lic.childrenCache.get(zPath); } cacheWriteLock.lock(); try { if (childrenCache.containsKey(zPath)) { return childrenCache.get(zPath); } final ZooKeeper zooKeeper = getZooKeeper(); List<String> children = zooKeeper.getChildren(zPath, watcher); if (children != null) { children = ImmutableList.copyOf(children); } childrenCache.put(zPath, children); immutableCache = new ImmutableCacheCopies(++updateCount, immutableCache, childrenCache); return children; } catch (KeeperException ke) { if (ke.code() != Code.NONODE) { throw ke; } } finally { cacheWriteLock.unlock(); } return null; }
/** * Clears this cache of all information about nodes rooted at the given path. * * @param zPath * path of top node */ public void clear(String zPath) { cacheWriteLock.lock(); try { for (Iterator<String> i = cache.keySet().iterator(); i.hasNext();) { String path = i.next(); if (path.startsWith(zPath)) i.remove(); } for (Iterator<String> i = childrenCache.keySet().iterator(); i.hasNext();) { String path = i.next(); if (path.startsWith(zPath)) i.remove(); } for (Iterator<String> i = statCache.keySet().iterator(); i.hasNext();) { String path = i.next(); if (path.startsWith(zPath)) i.remove(); } immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, childrenCache); } finally { cacheWriteLock.unlock(); } }
@Override public List<String> run() throws KeeperException, InterruptedException { // only read volatile once for consistency ImmutableCacheCopies lic = immutableCache; if (lic.childrenCache.containsKey(zPath)) { return lic.childrenCache.get(zPath); } cacheWriteLock.lock(); try { if (childrenCache.containsKey(zPath)) { return childrenCache.get(zPath); } final ZooKeeper zooKeeper = getZooKeeper(); List<String> children = zooKeeper.getChildren(zPath, watcher); if (children != null) { children = ImmutableList.copyOf(children); } childrenCache.put(zPath, children); immutableCache = new ImmutableCacheCopies(++updateCount, immutableCache, childrenCache); return children; } catch (KeeperException ke) { if (ke.code() != Code.NONODE) { throw ke; } } finally { cacheWriteLock.unlock(); } return null; }
/** * Clears this cache. */ public void clear() { cacheWriteLock.lock(); try { cache.clear(); childrenCache.clear(); statCache.clear(); immutableCache = new ImmutableCacheCopies(++updateCount); } finally { cacheWriteLock.unlock(); } }
private void put(String zPath, byte[] data, ZcStat stat) { cacheWriteLock.lock(); try { cache.put(zPath, data); statCache.put(zPath, stat); immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, immutableCache); } finally { cacheWriteLock.unlock(); } }
private void remove(String zPath) { cacheWriteLock.lock(); try { cache.remove(zPath); childrenCache.remove(zPath); statCache.remove(zPath); immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, childrenCache); } finally { cacheWriteLock.unlock(); } }
/** * Clears this cache of all information about nodes rooted at the given path. * * @param zPath * path of top node */ public void clear(String zPath) { Preconditions.checkState(!closed); cacheWriteLock.lock(); try { for (Iterator<String> i = cache.keySet().iterator(); i.hasNext();) { String path = i.next(); if (path.startsWith(zPath)) i.remove(); } for (Iterator<String> i = childrenCache.keySet().iterator(); i.hasNext();) { String path = i.next(); if (path.startsWith(zPath)) i.remove(); } for (Iterator<String> i = statCache.keySet().iterator(); i.hasNext();) { String path = i.next(); if (path.startsWith(zPath)) i.remove(); } immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, childrenCache); } finally { cacheWriteLock.unlock(); } }
/** * Clears this cache. */ public void clear() { Preconditions.checkState(!closed); cacheWriteLock.lock(); try { cache.clear(); childrenCache.clear(); statCache.clear(); immutableCache = new ImmutableCacheCopies(++updateCount); } finally { cacheWriteLock.unlock(); } }
private void put(String zPath, byte[] data, ZcStat stat) { cacheWriteLock.lock(); try { cache.put(zPath, data); statCache.put(zPath, stat); immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, immutableCache); } finally { cacheWriteLock.unlock(); } }
private void remove(String zPath) { cacheWriteLock.lock(); try { cache.remove(zPath); childrenCache.remove(zPath); statCache.remove(zPath); immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, childrenCache); } finally { cacheWriteLock.unlock(); } }