You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/01/01 22:15:21 UTC
curator git commit: Removed composite stuff. Interesting,
but gilding the lilly
Repository: curator
Updated Branches:
refs/heads/persistent-watch 72fe88c3b -> 8565de6d7
Removed composite stuff. Interesting, but gilding the lilly
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/8565de6d
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/8565de6d
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/8565de6d
Branch: refs/heads/persistent-watch
Commit: 8565de6d75d34b2dd597878167b51cd921a0a00e
Parents: 72fe88c
Author: randgalt <ra...@apache.org>
Authored: Sun Jan 1 17:15:14 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sun Jan 1 17:15:14 2017 -0500
----------------------------------------------------------------------
.../recipes/watch/CompositeCountDownLatch.java | 82 -----
.../recipes/watch/CompositeCuratorCache.java | 321 -------------------
.../watch/CompositeCuratorCacheProxy.java | 53 ---
.../framework/recipes/watch/CuratorCache.java | 3 +
4 files changed, 3 insertions(+), 456 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/8565de6d/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCountDownLatch.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCountDownLatch.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCountDownLatch.java
deleted file mode 100644
index 5c75622..0000000
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCountDownLatch.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.recipes.watch;
-
-import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-class CompositeCountDownLatch extends CountDownLatch
-{
- private final Collection<CountDownLatch> latches;
-
- CompositeCountDownLatch(Collection<CountDownLatch> latches)
- {
- super(0);
- this.latches = ImmutableList.copyOf(latches);
- }
-
- @Override
- public void await() throws InterruptedException
- {
- for ( CountDownLatch latch : latches )
- {
- latch.await();
- }
- }
-
- @Override
- public boolean await(final long timeout, TimeUnit unit) throws InterruptedException
- {
- long timeoutMs = unit.toMillis(timeout);
- for ( CountDownLatch latch : latches )
- {
- if ( timeoutMs < 0 )
- {
- return false;
- }
- long start = System.currentTimeMillis();
- if ( !latch.await(timeoutMs, TimeUnit.MILLISECONDS) )
- {
- return false;
- }
- long elapsed = System.currentTimeMillis() - start;
- timeoutMs -= elapsed;
- }
- return true;
- }
-
- @Override
- public void countDown()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public long getCount()
- {
- long count = 0;
- for ( CountDownLatch latch : latches )
- {
- count += latch.getCount();
- }
- return count;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/8565de6d/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCache.java
deleted file mode 100644
index d81c074..0000000
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCache.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.recipes.watch;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import org.apache.curator.framework.listen.Listenable;
-import org.apache.curator.framework.listen.ListenerContainer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-
-public class CompositeCuratorCache implements CuratorCache
-{
- private final Map<String, CuratorCache> caches;
- private final ListenerContainer<CacheListener> listeners = new ListenerContainer<>();
- private final CacheListener listener = new CacheListener()
- {
- @Override
- public void process(final CacheEvent event, final String path, final CachedNode affectedNode)
- {
- Function<CacheListener, Void> proc = new Function<CacheListener, Void>()
- {
- @Override
- public Void apply(CacheListener listener)
- {
- listener.process(event, path, affectedNode);
- return null;
- }
- };
- listeners.forEach(proc);
- }
- };
-
- public CompositeCuratorCache(CuratorCache... caches)
- {
- this(toMap(Arrays.asList(caches)));
- }
-
- public CompositeCuratorCache(Collection<CuratorCache> caches)
- {
- this(toMap(caches));
- }
-
- private static Map<String, CuratorCache> toMap(Collection<CuratorCache> caches)
- {
- Map<String, CuratorCache> map = new HashMap<>();
- for ( CuratorCache cache : caches )
- {
- map.put(Integer.toString(map.size()), cache);
- }
- return map;
- }
-
- public CompositeCuratorCache(Map<String, CuratorCache> caches)
- {
- this.caches = ImmutableMap.copyOf(caches);
- }
-
- public Iterable<String> cacheKeys()
- {
- return caches.keySet();
- }
-
- public CuratorCache getCache(String key)
- {
- return caches.get(key);
- }
-
- @Override
- public CountDownLatch start()
- {
- List<CountDownLatch> latches = new ArrayList<>();
- for ( CuratorCache cache : caches.values() )
- {
- latches.add(cache.start());
- }
- return new CompositeCountDownLatch(latches);
- }
-
- @Override
- public void close()
- {
- for ( CuratorCache cache : caches.values() )
- {
- cache.getListenable().removeListener(listener);
- cache.close();
- }
- }
-
- @Override
- public Listenable<CacheListener> getListenable()
- {
- return listeners;
- }
-
- @Override
- public CountDownLatch refreshAll()
- {
- List<CountDownLatch> latches = new ArrayList<>();
- for ( CuratorCache cache : caches.values() )
- {
- latches.add(cache.refreshAll());
- }
- return new CompositeCountDownLatch(latches);
- }
-
- @Override
- public CountDownLatch refresh(String path)
- {
- List<CountDownLatch> latches = new ArrayList<>();
- for ( CuratorCache cache : caches.values() )
- {
- latches.add(cache.refresh(path));
- }
- return new CompositeCountDownLatch(latches);
- }
-
- @Override
- public boolean clear(String path)
- {
- boolean cleared = false;
- for ( CuratorCache cache : caches.values() )
- {
- if ( cache.clear(path) )
- {
- cleared = true;
- }
- }
- return cleared;
- }
-
- @Override
- public void clearAll()
- {
- for ( CuratorCache cache : caches.values() )
- {
- cache.clearAll();
- }
- }
-
- @Override
- public boolean exists(String path)
- {
- for ( CuratorCache cache : caches.values() )
- {
- if ( cache.exists(path) )
- {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public Collection<String> paths()
- {
- Set<String> paths = new HashSet<>();
- for ( CuratorCache cache : caches.values() )
- {
- paths.addAll(cache.paths());
- }
- return paths;
- }
-
- @Override
- public Collection<String> childNamesAtPath(String path)
- {
- Set<String> paths = new HashSet<>();
- for ( CuratorCache cache : caches.values() )
- {
- paths.addAll(cache.childNamesAtPath(path));
- }
- return paths;
- }
-
- @Override
- public Map<String, CachedNode> childrenAtPath(String path)
- {
- ImmutableMap.Builder<String, CachedNode> builder = ImmutableMap.builder();
- for ( CuratorCache cache : caches.values() )
- {
- builder.putAll(cache.childrenAtPath(path));
- }
- return builder.build();
- }
-
- @Override
- public CachedNode getMain()
- {
- for ( CuratorCache cache : caches.values() )
- {
- CachedNode node = cache.getMain();
- if ( node != null )
- {
- return node;
- }
- }
- return null;
- }
-
- @Override
- public CachedNode get(String path)
- {
- for ( CuratorCache cache : caches.values() )
- {
- CachedNode node = cache.get(path);
- if ( node != null )
- {
- return node;
- }
- }
- return null;
- }
-
- @Override
- public Collection<CachedNode> getAll()
- {
- // TODO - more efficient version
- List<Iterable<CachedNode>> nodes = new ArrayList<>();
- for ( CuratorCache cache : caches.values() )
- {
- nodes.add(cache.getAll());
- }
- return Lists.newArrayList(Iterables.concat(nodes));
- }
-
- @Override
- public Map<String, CachedNode> view()
- {
- // TODO - more efficient version
- ImmutableMap.Builder<String, CachedNode> builder = ImmutableMap.builder();
- for ( CuratorCache cache : caches.values() )
- {
- builder.putAll(cache.view());
- }
- return builder.build();
- }
-
- @Override
- public boolean isEmpty()
- {
- for ( CuratorCache cache : caches.values() )
- {
- if ( !cache.isEmpty() )
- {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public int size()
- {
- long size = 0;
- for ( CuratorCache cache : caches.values() )
- {
- size += cache.size();
- }
- return (int)Math.min(size, Integer.MAX_VALUE);
- }
-
- @Override
- public void clearDataBytes(String path)
- {
- for ( CuratorCache cache : caches.values() )
- {
- cache.clearDataBytes(path);
- }
- }
-
- @Override
- public boolean clearDataBytes(String path, int ifVersion)
- {
- boolean cleared = false;
- for ( CuratorCache cache : caches.values() )
- {
- if ( cache.clearDataBytes(path, ifVersion) )
- {
- cleared = true;
- }
- }
- return cleared;
- }
-
- @Override
- public long refreshCount()
- {
- long count = 0;
- for ( CuratorCache cache : caches.values() )
- {
- count = Math.min(count, cache.refreshCount());
- }
- return count;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/8565de6d/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCacheProxy.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCacheProxy.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCacheProxy.java
deleted file mode 100644
index 17ca449..0000000
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CompositeCuratorCacheProxy.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.recipes.watch;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-
-public class CompositeCuratorCacheProxy extends CompositeCuratorCache
-{
- public CompositeCuratorCacheProxy(CuratorCache... caches)
- {
- super(caches);
- }
-
- public CompositeCuratorCacheProxy(Collection<CuratorCache> caches)
- {
- super(caches);
- }
-
- public CompositeCuratorCacheProxy(Map<String, CuratorCache> caches)
- {
- super(caches);
- }
-
- @Override
- public CountDownLatch start()
- {
- return new CountDownLatch(0);
- }
-
- @Override
- public void close()
- {
- // NOP
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/8565de6d/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCache.java
index bbc161e..f22563e 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCache.java
@@ -37,6 +37,9 @@ public interface CuratorCache extends Closeable
*/
CountDownLatch start();
+ /**
+ * Close the cache, release resources, etc.
+ */
@Override
void close();