You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by dr...@apache.org on 2017/05/02 20:06:19 UTC

[11/50] curator git commit: refactoring

refactoring


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/dca47a88
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/dca47a88
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/dca47a88

Branch: refs/heads/master
Commit: dca47a880f6c68b134cc49c5cfa775ffd3323c0e
Parents: 6c1db4e
Author: randgalt <ra...@apache.org>
Authored: Sun Jan 8 12:33:58 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sun Jan 8 12:33:58 2017 -0500

----------------------------------------------------------------------
 .../curator/x/async/AsyncCuratorFramework.java  | 22 +++++++++++
 .../x/async/api/AsyncCuratorFrameworkDsl.java   |  7 ----
 .../details/AsyncCuratorFrameworkImpl.java      | 39 +++++++++++++-------
 .../src/site/confluence/index.confluence        |  2 +-
 4 files changed, 49 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/dca47a88/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncCuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncCuratorFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncCuratorFramework.java
index 9fc4134..b8de84a 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncCuratorFramework.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncCuratorFramework.java
@@ -55,6 +55,14 @@ public interface AsyncCuratorFramework extends AsyncCuratorFrameworkDsl
     CuratorFramework unwrap();
 
     /**
+     * Returns a facade that changes how watchers are set when {@link #watched()} is called
+     *
+     * @param mode watch mode to use for subsequent calls to {@link #watched()}
+     * @return facade
+     */
+    AsyncCuratorFrameworkDsl with(WatchMode mode);
+
+    /**
      * Returns a facade that adds the given UnhandledErrorListener to all background operations
      *
      * @param listener lister to use
@@ -85,4 +93,18 @@ public interface AsyncCuratorFramework extends AsyncCuratorFrameworkDsl
      * @return facade
      */
     AsyncCuratorFrameworkDsl with(UnhandledErrorListener listener, UnaryOperator<CuratorEvent> resultFilter, UnaryOperator<WatchedEvent> watcherFilter);
+
+    /**
+     * Set any combination of listener, filters or watch mode
+     *
+     * @param mode watch mode to use for subsequent calls to {@link #watched()} (cannot be <code>null</code>)
+     * @param listener lister to use or <code>null</code>
+     * @param resultFilter filter to use or <code>null</code>
+     * @param watcherFilter filter to use or <code>null</code>
+     * @see #with(WatchMode)
+     * @see #with(java.util.function.UnaryOperator, java.util.function.UnaryOperator)
+     * @see #with(org.apache.curator.framework.api.UnhandledErrorListener)
+     * @return facade
+     */
+    AsyncCuratorFrameworkDsl with(WatchMode mode, UnhandledErrorListener listener, UnaryOperator<CuratorEvent> resultFilter, UnaryOperator<WatchedEvent> watcherFilter);
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/dca47a88/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncCuratorFrameworkDsl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncCuratorFrameworkDsl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncCuratorFrameworkDsl.java
index a8151cd..0807160 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncCuratorFrameworkDsl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncCuratorFrameworkDsl.java
@@ -43,13 +43,6 @@ public interface AsyncCuratorFrameworkDsl extends WatchableAsyncCuratorFramework
     WatchableAsyncCuratorFramework watched();
 
     /**
-     * Same as {@link #watched()} but allows specifying the watch mode
-     *
-     * @return watcher facade
-     */
-    WatchableAsyncCuratorFramework watched(WatchMode mode);
-
-    /**
      * Start a create builder
      *
      * @return builder object

http://git-wip-us.apache.org/repos/asf/curator/blob/dca47a88/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java
index aa82644..167cf50 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java
@@ -42,10 +42,11 @@ public class AsyncCuratorFrameworkImpl implements AsyncCuratorFramework
     private final CuratorFrameworkImpl client;
     private final Filters filters;
     private final WatchMode watchMode;
+    private final boolean watched;
 
     public AsyncCuratorFrameworkImpl(CuratorFramework client)
     {
-        this(reveal(client), new Filters(null, null, null), null);
+        this(reveal(client), new Filters(null, null, null), WatchMode.stateChangeAndSuccess, false);
     }
 
     private static CuratorFrameworkImpl reveal(CuratorFramework client)
@@ -60,11 +61,12 @@ public class AsyncCuratorFrameworkImpl implements AsyncCuratorFramework
         }
     }
 
-    public AsyncCuratorFrameworkImpl(CuratorFrameworkImpl client, Filters filters, WatchMode watchMode)
+    public AsyncCuratorFrameworkImpl(CuratorFrameworkImpl client, Filters filters, WatchMode watchMode, boolean watched)
     {
         this.client = Objects.requireNonNull(client, "client cannot be null");
         this.filters = Objects.requireNonNull(filters, "filters cannot be null");
-        this.watchMode = watchMode;
+        this.watchMode = Objects.requireNonNull(watchMode, "watchMode cannot be null");
+        this.watched = watched;
     }
 
     @Override
@@ -156,31 +158,37 @@ public class AsyncCuratorFrameworkImpl implements AsyncCuratorFramework
     @Override
     public WatchableAsyncCuratorFramework watched()
     {
-        return new AsyncCuratorFrameworkImpl(client, filters, WatchMode.stateChangeAndSuccess);
+        return new AsyncCuratorFrameworkImpl(client, filters, watchMode, true);
     }
 
     @Override
-    public WatchableAsyncCuratorFramework watched(WatchMode mode)
+    public AsyncCuratorFrameworkDsl with(WatchMode mode)
     {
-        return new AsyncCuratorFrameworkImpl(client, filters, mode);
+        return new AsyncCuratorFrameworkImpl(client, filters, mode, watched);
+    }
+
+    @Override
+    public AsyncCuratorFrameworkDsl with(WatchMode mode, UnhandledErrorListener listener, UnaryOperator<CuratorEvent> resultFilter, UnaryOperator<WatchedEvent> watcherFilter)
+    {
+        return new AsyncCuratorFrameworkImpl(client, new Filters(listener, filters.getResultFilter(), filters.getWatcherFilter()), mode, watched);
     }
 
     @Override
     public AsyncCuratorFrameworkDsl with(UnhandledErrorListener listener)
     {
-        return new AsyncCuratorFrameworkImpl(client, new Filters(listener, filters.getResultFilter(), filters.getWatcherFilter()), watchMode);
+        return new AsyncCuratorFrameworkImpl(client, new Filters(listener, filters.getResultFilter(), filters.getWatcherFilter()), watchMode, watched);
     }
 
     @Override
     public AsyncCuratorFrameworkDsl with(UnaryOperator<CuratorEvent> resultFilter, UnaryOperator<WatchedEvent> watcherFilter)
     {
-        return new AsyncCuratorFrameworkImpl(client, new Filters(filters.getListener(), resultFilter, watcherFilter), watchMode);
+        return new AsyncCuratorFrameworkImpl(client, new Filters(filters.getListener(), resultFilter, watcherFilter), watchMode, watched);
     }
 
     @Override
     public AsyncCuratorFrameworkDsl with(UnhandledErrorListener listener, UnaryOperator<CuratorEvent> resultFilter, UnaryOperator<WatchedEvent> watcherFilter)
     {
-        return new AsyncCuratorFrameworkImpl(client, new Filters(listener, resultFilter, watcherFilter), watchMode);
+        return new AsyncCuratorFrameworkImpl(client, new Filters(listener, resultFilter, watcherFilter), watchMode, watched);
     }
 
     @Override
@@ -192,24 +200,29 @@ public class AsyncCuratorFrameworkImpl implements AsyncCuratorFramework
     @Override
     public AsyncExistsBuilder checkExists()
     {
-        return new AsyncExistsBuilderImpl(client, filters, watchMode);
+        return new AsyncExistsBuilderImpl(client, filters, getBuilderWatchMode());
     }
 
     @Override
     public AsyncGetDataBuilder getData()
     {
-        return new AsyncGetDataBuilderImpl(client, filters, watchMode);
+        return new AsyncGetDataBuilderImpl(client, filters, getBuilderWatchMode());
     }
 
     @Override
     public AsyncGetChildrenBuilder getChildren()
     {
-        return new AsyncGetChildrenBuilderImpl(client, filters, watchMode);
+        return new AsyncGetChildrenBuilderImpl(client, filters, getBuilderWatchMode());
     }
 
     @Override
     public AsyncGetConfigBuilder getConfig()
     {
-        return new AsyncGetConfigBuilderImpl(client, filters, watchMode);
+        return new AsyncGetConfigBuilderImpl(client, filters, getBuilderWatchMode());
+    }
+
+    private WatchMode getBuilderWatchMode()
+    {
+        return watched ? watchMode : null;
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/dca47a88/curator-x-async/src/site/confluence/index.confluence
----------------------------------------------------------------------
diff --git a/curator-x-async/src/site/confluence/index.confluence b/curator-x-async/src/site/confluence/index.confluence
index c896df7..6ccc048 100644
--- a/curator-x-async/src/site/confluence/index.confluence
+++ b/curator-x-async/src/site/confluence/index.confluence
@@ -72,7 +72,7 @@ problems, you can tell Curator Async to not send them by calling:
 {code}
 // only complete the CompletionStage when the watcher is successfully triggered
 // i.e. don't complete on connection issues
-async.watched(WatchMode.successOnly)...
+async.with(WatchMode.successOnly).watched()...
 {code}
 
 h4. AsyncEventException