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/05/02 04:08:04 UTC
curator git commit: refactoring
Repository: curator
Updated Branches:
refs/heads/CURATOR-397 2cbbf9992 -> 6e21af2c5
refactoring
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/6e21af2c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/6e21af2c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/6e21af2c
Branch: refs/heads/CURATOR-397
Commit: 6e21af2c565d95b7c281dd5211487a0682ab1a1a
Parents: 2cbbf99
Author: randgalt <ra...@apache.org>
Authored: Mon May 1 23:07:58 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon May 1 23:07:58 2017 -0500
----------------------------------------------------------------------
.../async/modeled/ModeledCuratorFramework.java | 2 +-
.../x/async/modeled/cached/ModeledCache.java | 6 +--
.../modeled/cached/ModeledCacheEventType.java | 42 -----------------
.../modeled/cached/ModeledCacheListener.java | 47 ++++++++++++++++++--
.../async/modeled/cached/ModeledCachedNode.java | 6 +--
.../CachedModeledCuratorFrameworkImpl.java | 18 ++++----
.../async/modeled/details/ModeledCacheImpl.java | 37 ++++++++++-----
.../details/ModeledCuratorFrameworkImpl.java | 2 +-
.../modeled/TestModeledCuratorFramework.java | 2 +-
9 files changed, 89 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java
index 31b630d..a8e8f5c 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java
@@ -178,7 +178,7 @@ public interface ModeledCuratorFramework<T>
* @return AsyncStage
* @see org.apache.curator.x.async.AsyncStage
*/
- AsyncStage<List<ZPath>> getChildren();
+ AsyncStage<List<ZPath>> children();
/**
* Return the children of this instance's path
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
index 3536a65..84b9898 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
@@ -33,7 +33,7 @@ public interface ModeledCache<T>
* @param path path to the node to check
* @return data if the node is alive, or null
*/
- Optional<ModeledCachedNode<T>> getCurrentData(ZPath path);
+ Optional<ModeledCachedNode<T>> currentData(ZPath path);
/**
* Return the modeled current set of children at the given path, mapped by child name. There are no
@@ -42,12 +42,12 @@ public interface ModeledCache<T>
* @param path path to the node to check
* @return a possibly-empty list of children if the node is alive, or null
*/
- Map<ZPath, ModeledCachedNode<T>> getCurrentChildren(ZPath path);
+ Map<ZPath, ModeledCachedNode<T>> currentChildren(ZPath path);
/**
* Return the listener container so that you can add/remove listeners
*
* @return listener container
*/
- Listenable<ModeledCacheListener<T>> getListenable();
+ Listenable<ModeledCacheListener<T>> listenable();
}
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheEventType.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheEventType.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheEventType.java
deleted file mode 100644
index e7754ea..0000000
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheEventType.java
+++ /dev/null
@@ -1,42 +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.x.async.modeled.cached;
-
-public enum ModeledCacheEventType
-{
- /**
- * A child was added to the path
- */
- NODE_ADDED,
-
- /**
- * A child's data was changed
- */
- NODE_UPDATED,
-
- /**
- * A child was removed from the path
- */
- NODE_REMOVED,
-
- /**
- * Signals that the initial cache has been populated.
- */
- INITIALIZED
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheListener.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheListener.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheListener.java
index 9ddef87..544de78 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheListener.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCacheListener.java
@@ -1,3 +1,21 @@
+/**
+ * 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.x.async.modeled.cached;
import org.apache.curator.x.async.modeled.ZPath;
@@ -6,6 +24,29 @@ import org.apache.zookeeper.data.Stat;
@FunctionalInterface
public interface ModeledCacheListener<T>
{
+ enum Type
+ {
+ /**
+ * A child was added to the path
+ */
+ NODE_ADDED,
+
+ /**
+ * A child's data was changed
+ */
+ NODE_UPDATED,
+
+ /**
+ * A child was removed from the path
+ */
+ NODE_REMOVED,
+
+ /**
+ * Signals that the initial cache has been populated.
+ */
+ INITIALIZED
+ }
+
/**
* The given path was added, updated or removed
*
@@ -14,7 +55,7 @@ public interface ModeledCacheListener<T>
* @param stat the node's stat (previous stat for removal)
* @param model the node's model (previous model for removal)
*/
- void accept(ModeledCacheEventType type, ZPath path, Stat stat, T model);
+ void accept(Type type, ZPath path, Stat stat, T model);
/**
* The cache has finished initializing
@@ -26,7 +67,7 @@ public interface ModeledCacheListener<T>
/**
* Returns a version of this listener that only begins calling
- * {@link #accept(ModeledCacheEventType, org.apache.curator.x.async.modeled.ZPath, org.apache.zookeeper.data.Stat, Object)}
+ * {@link #accept(org.apache.curator.x.async.modeled.cached.ModeledCacheListener.Type, org.apache.curator.x.async.modeled.ZPath, org.apache.zookeeper.data.Stat, Object)}
* once {@link #initialized()} has been called. i.e. changes that occur as the cache is initializing are not sent
* to the listener
*
@@ -39,7 +80,7 @@ public interface ModeledCacheListener<T>
private volatile boolean isInitialized = false;
@Override
- public void accept(ModeledCacheEventType type, ZPath path, Stat stat, T model)
+ public void accept(Type type, ZPath path, Stat stat, T model)
{
if ( isInitialized )
{
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCachedNode.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCachedNode.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCachedNode.java
index 3a8e742..68fdadc 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCachedNode.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCachedNode.java
@@ -31,19 +31,19 @@ public interface ModeledCachedNode<T>
*
* @return path
*/
- ZPath getPath();
+ ZPath path();
/**
* The node's last known stat if available
*
* @return stat
*/
- Stat getStat();
+ Stat stat();
/**
* The node's current model
*
* @return model
*/
- T getModel();
+ T model();
}
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledCuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledCuratorFrameworkImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledCuratorFrameworkImpl.java
index 3318403..c45d28b 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledCuratorFrameworkImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledCuratorFrameworkImpl.java
@@ -120,13 +120,13 @@ class CachedModeledCuratorFrameworkImpl<T> implements CachedModeledCuratorFramew
public AsyncStage<T> read(Stat storingStatIn)
{
ZPath path = client.modelSpec().path();
- Optional<ModeledCachedNode<T>> data = cache.getCurrentData(path);
+ Optional<ModeledCachedNode<T>> data = cache.currentData(path);
return data.map(node -> {
if ( storingStatIn != null )
{
- DataTree.copyStat(node.getStat(), storingStatIn);
+ DataTree.copyStat(node.stat(), storingStatIn);
}
- return new ModelStage<>(node.getModel());
+ return new ModelStage<>(node.model());
}).orElseGet(() -> new ModelStage<>(new KeeperException.NoNodeException(path.fullPath())));
}
@@ -158,23 +158,23 @@ class CachedModeledCuratorFrameworkImpl<T> implements CachedModeledCuratorFramew
public AsyncStage<Stat> checkExists()
{
ZPath path = client.modelSpec().path();
- Optional<ModeledCachedNode<T>> data = cache.getCurrentData(path);
- return data.map(node -> new ModelStage<>(node.getStat())).orElseGet(() -> new ModelStage<>((Stat)null));
+ Optional<ModeledCachedNode<T>> data = cache.currentData(path);
+ return data.map(node -> new ModelStage<>(node.stat())).orElseGet(() -> new ModelStage<>((Stat)null));
}
@Override
- public AsyncStage<List<ZPath>> getChildren()
+ public AsyncStage<List<ZPath>> children()
{
- Set<ZPath> paths = cache.getCurrentChildren(client.modelSpec().path()).keySet();
+ Set<ZPath> paths = cache.currentChildren(client.modelSpec().path()).keySet();
return new ModelStage<>(Lists.newArrayList(paths));
}
@Override
public AsyncStage<Map<ZPath, AsyncStage<T>>> readChildren()
{
- Map<ZPath, AsyncStage<T>> map = cache.getCurrentChildren(client.modelSpec().path()).entrySet()
+ Map<ZPath, AsyncStage<T>> map = cache.currentChildren(client.modelSpec().path()).entrySet()
.stream()
- .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), new ModelStage<>(entry.getValue().getModel())))
+ .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), new ModelStage<>(entry.getValue().model())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return new ModelStage<>(map);
}
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
index c1ab8cd..fb4bc70 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
@@ -1,3 +1,21 @@
+/**
+ * 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.x.async.modeled.details;
import org.apache.curator.framework.CuratorFramework;
@@ -9,7 +27,6 @@ import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.x.async.modeled.ModelSerializer;
import org.apache.curator.x.async.modeled.ZPath;
import org.apache.curator.x.async.modeled.cached.ModeledCache;
-import org.apache.curator.x.async.modeled.cached.ModeledCacheEventType;
import org.apache.curator.x.async.modeled.cached.ModeledCacheListener;
import org.apache.curator.x.async.modeled.cached.ModeledCachedNode;
import org.apache.zookeeper.data.Stat;
@@ -66,7 +83,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
}
@Override
- public Optional<ModeledCachedNode<T>> getCurrentData(ZPath path)
+ public Optional<ModeledCachedNode<T>> currentData(ZPath path)
{
Entry<T> entry = entries.remove(path);
if ( entry != null )
@@ -77,7 +94,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
}
@Override
- public Map<ZPath, ModeledCachedNode<T>> getCurrentChildren(ZPath path)
+ public Map<ZPath, ModeledCachedNode<T>> currentChildren(ZPath path)
{
return entries.entrySet()
.stream()
@@ -87,7 +104,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
}
@Override
- public Listenable<ModeledCacheListener<T>> getListenable()
+ public Listenable<ModeledCacheListener<T>> listenable()
{
return listenerContainer;
}
@@ -103,7 +120,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
ZPath path = ZPath.from(event.toString());
T model = serializer.deserialize(event.getData().getData());
entries.put(path, new Entry<>(event.getData().getStat(), model));
- ModeledCacheEventType type = (event.getType() == TreeCacheEvent.Type.NODE_ADDED) ? ModeledCacheEventType.NODE_ADDED : ModeledCacheEventType.NODE_UPDATED;
+ ModeledCacheListener.Type type = (event.getType() == TreeCacheEvent.Type.NODE_ADDED) ? ModeledCacheListener.Type.NODE_ADDED : ModeledCacheListener.Type.NODE_UPDATED;
accept(type, path, event.getData().getStat(), model);
break;
}
@@ -114,7 +131,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
Entry<T> entry = entries.remove(path);
T model = (entry != null) ? entry.model : serializer.deserialize(event.getData().getData());
Stat stat = (entry != null) ? entry.stat : event.getData().getStat();
- accept(ModeledCacheEventType.NODE_REMOVED, path, stat, model);
+ accept(ModeledCacheListener.Type.NODE_REMOVED, path, stat, model);
break;
}
@@ -133,7 +150,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
}
}
- private void accept(ModeledCacheEventType type, ZPath path, Stat stat, T model)
+ private void accept(ModeledCacheListener.Type type, ZPath path, Stat stat, T model)
{
listenerContainer.forEach(l -> {
l.accept(type, path, stat, model);
@@ -153,19 +170,19 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
}
@Override
- public ZPath getPath()
+ public ZPath path()
{
return path;
}
@Override
- public Stat getStat()
+ public Stat stat()
{
return entry.stat;
}
@Override
- public U getModel()
+ public U model()
{
return entry.model;
}
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
index aba87f3..eaa4f43 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
@@ -203,7 +203,7 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T
}
@Override
- public AsyncStage<List<ZPath>> getChildren()
+ public AsyncStage<List<ZPath>> children()
{
AsyncStage<List<String>> asyncStage = watchableClient.getChildren().forPath(modelSpec.path().fullPath());
ModelStage<List<ZPath>> modelStage = new ModelStage<>(asyncStage.event());
http://git-wip-us.apache.org/repos/asf/curator/blob/6e21af2c/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestModeledCuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestModeledCuratorFramework.java b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestModeledCuratorFramework.java
index 3d98c1a..40e30f0 100644
--- a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestModeledCuratorFramework.java
+++ b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestModeledCuratorFramework.java
@@ -117,6 +117,6 @@ public class TestModeledCuratorFramework extends CompletableBaseClassForTests
complete(client.at("three").set(model));
Set<ZPath> expected = Sets.newHashSet(path.at("one"), path.at("two"), path.at("three"));
- complete(client.getChildren(), (children, e) -> Assert.assertEquals(Sets.newHashSet(children), expected));
+ complete(client.children(), (children, e) -> Assert.assertEquals(Sets.newHashSet(children), expected));
}
}