CachedNodeComparator isn't needed. Comparing against mxzid is enough

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

Branch: refs/heads/persistent-watch
Commit: 2abec56e932eae92be7c65e6f15ec699dc152558
Parents: 03c9e44
Author: randgalt <randg...@apache.org>
Authored: Sun Mar 12 15:39:56 2017 -0700
Committer: randgalt <randg...@apache.org>
Committed: Sun Mar 12 15:39:56 2017 -0700

----------------------------------------------------------------------
 .../framework/imps/ReconfigBuilderImpl.java     |   4 +-
 .../framework/recipes/watch/CacheEvent.java     |   3 +-
 .../recipes/watch/CachedNodeComparator.java     |  34 ------
 .../recipes/watch/CachedNodeComparators.java    | 110 -------------------
 .../recipes/watch/CuratorCacheBuilder.java      |  18 +--
 .../recipes/watch/InternalCuratorCache.java     |   6 +-
 .../recipes/watch/InternalNodeCache.java        |   6 +-
 7 files changed, 9 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
index 97be59a..321e060 100644
--- 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
+++ 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -268,7 +268,7 @@ public class ReconfigBuilderImpl implements 
ReconfigBuilder, BackgroundOperation
                     client.processBackgroundOperation(data, event);
                 }
             };
-            client.getZooKeeper().reconfig(joining, leaving, newMembers, 
fromConfig, callback, backgrounding.getContext());
+            //client.getZooKeeper().reconfig(joining, leaving, newMembers, 
fromConfig, callback, backgrounding.getContext());
         }
         catch ( Throwable e )
         {
@@ -287,7 +287,7 @@ public class ReconfigBuilderImpl implements 
ReconfigBuilder, BackgroundOperation
                     @Override
                     public byte[] call() throws Exception
                     {
-                        return client.getZooKeeper().reconfig(joining, 
leaving, newMembers, fromConfig, responseStat);
+                        return null;//client.getZooKeeper().reconfig(joining, 
leaving, newMembers, fromConfig, responseStat);
                     }
                 }
             );

http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CacheEvent.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CacheEvent.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CacheEvent.java
index 8193dad..1475110 100644
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CacheEvent.java
+++ 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CacheEvent.java
@@ -34,8 +34,7 @@ public enum CacheEvent
     NODE_DELETED,
 
     /**
-     * A node in the cache was changed due to the {@link CachedNodeComparator} 
signifying
-     * a difference
+     * A node in the cache was changed
      */
     NODE_CHANGED,
 

http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparator.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparator.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparator.java
deleted file mode 100644
index 2ffd8ab..0000000
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparator.java
+++ /dev/null
@@ -1,34 +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;
-
-/**
- * Provides for alternate methods of node comparison
- */
-public interface CachedNodeComparator
-{
-    /**
-     * Return true if the two nodes should be considered the same
-     *
-     * @param n1 node 1
-     * @param n2 node 2
-     * @return true/false
-     */
-    boolean isSame(CachedNode n1, CachedNode n2);
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparators.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparators.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparators.java
deleted file mode 100644
index 79c90f0..0000000
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CachedNodeComparators.java
+++ /dev/null
@@ -1,110 +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.Arrays;
-
-/**
- * Pre-built node comparators for common uses
- */
-public class CachedNodeComparators
-{
-    private static final CachedNodeComparator dataOnly = new 
CachedNodeComparator()
-    {
-        @Override
-        public boolean isSame(CachedNode n1, CachedNode n2)
-        {
-            return firstCheck(n1, n2) && Arrays.equals(n1.getData(), 
n2.getData());
-        }
-    };
-
-    private static final CachedNodeComparator dataAndType = new 
CachedNodeComparator()
-    {
-        @Override
-        public boolean isSame(CachedNode n1, CachedNode n2)
-        {
-            return firstCheck(n1, n2) && Arrays.equals(n1.getData(), 
n2.getData()) && sameType(n1.getStat().getEphemeralOwner(), 
n2.getStat().getEphemeralOwner());
-        }
-    };
-
-    private static final CachedNodeComparator deep = new CachedNodeComparator()
-    {
-        @Override
-        public boolean isSame(CachedNode n1, CachedNode n2)
-        {
-            return n1.equals(n2);
-        }
-    };
-
-    private static boolean sameType(long e1, long e2)
-    {
-        boolean e1IsEphemeral = (e1 > 0);
-        boolean e2IsEphemeral = (e2 > 0);
-        return e1IsEphemeral == e2IsEphemeral;
-    }
-
-    private static boolean firstCheck(CachedNode n1, CachedNode n2)
-    {
-        if ( n1 == n2 )
-        {
-            return true;
-        }
-        //noinspection RedundantIfStatement
-        if ( (n1 == null) || (n2 == null) )
-        {
-            return false;
-        }
-        return true;
-    }
-
-    /**
-     * Returns a comparator that only compares the byte array of the node, 
ignoring the Stat
-     *
-     * @return data only comparator
-     */
-    public static CachedNodeComparator dataOnly()
-    {
-        return dataOnly;
-    }
-
-    /**
-     * Returns a comparator that compares the byte array of the node, and the 
ephemeralOwner
-     * of the Stat. i.e. the data must match and the ephemeral type must be 
the same
-     *
-     * @return data and type comparator
-     */
-    public static CachedNodeComparator dataAndType()
-    {
-        return dataAndType;
-    }
-
-    /**
-     * Returns a comparator that compares the byte array of the node and the 
stat
-     *
-     * @return deep comparator
-     */
-    public static CachedNodeComparator deep()
-    {
-        return deep;
-    }
-
-    private CachedNodeComparators()
-    {
-    }
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCacheBuilder.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCacheBuilder.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCacheBuilder.java
index a753d18..19c27a9 100644
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCacheBuilder.java
+++ 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/CuratorCacheBuilder.java
@@ -34,7 +34,6 @@ public class CuratorCacheBuilder
     private boolean sendRefreshEvents = true;
     private boolean refreshOnStart = true;
     private boolean sortChildren = true;
-    private CachedNodeComparator nodeComparator = 
CachedNodeComparators.dataAndType();
     private CacheSelector cacheSelector = CacheSelectors.statAndData();
     private CachedNodeMapFactory cachedNodeMapFactory = 
GuavaCachedNodeMap.factory;
     private boolean usingWeakValues = false;
@@ -66,10 +65,10 @@ public class CuratorCacheBuilder
         if ( singleNodeCacheAction != null )
         {
             Preconditions.checkState(cacheSelector == null, "Single node mode 
does not support CacheSelectors");
-            return new InternalNodeCache(client, path, singleNodeCacheAction, 
nodeComparator, cachedNodeMap, sendRefreshEvents, refreshOnStart);
+            return new InternalNodeCache(client, path, singleNodeCacheAction, 
cachedNodeMap, sendRefreshEvents, refreshOnStart);
         }
 
-        return new InternalCuratorCache(client, path, cacheSelector, 
nodeComparator, cachedNodeMap, sendRefreshEvents, refreshOnStart, sortChildren);
+        return new InternalCuratorCache(client, path, cacheSelector, 
cachedNodeMap, sendRefreshEvents, refreshOnStart, sortChildren);
     }
 
     /**
@@ -204,19 +203,6 @@ public class CuratorCacheBuilder
     }
 
     /**
-     * Changes which comparator is used to determine whether a node has 
changed or not.
-     * The default is {@link CachedNodeComparators#dataAndType}
-     *
-     * @param nodeComparator new comparator
-     * @return this
-     */
-    public CuratorCacheBuilder withNodeComparator(CachedNodeComparator 
nodeComparator)
-    {
-        this.nodeComparator = Objects.requireNonNull(nodeComparator, 
"nodeComparator cannot be null");
-        return this;
-    }
-
-    /**
      * Changes which cache selector is used. The default is {@link 
CacheSelectors#statAndData}
      *
      * @param cacheSelector new selector

http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalCuratorCache.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalCuratorCache.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalCuratorCache.java
index 703e83b..9d94c34 100644
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalCuratorCache.java
+++ 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalCuratorCache.java
@@ -48,7 +48,6 @@ class InternalCuratorCache extends CuratorCacheBase 
implements Watcher
     private final CuratorFramework client;
     private final String basePath;
     private final CacheSelector cacheSelector;
-    private final CachedNodeComparator nodeComparator;
     private final boolean sortChildren;
     private final CacheSelector singleNodeCacheSelector = new CacheSelector()
     {
@@ -65,13 +64,12 @@ class InternalCuratorCache extends CuratorCacheBase 
implements Watcher
         }
     };
 
-    InternalCuratorCache(CuratorFramework client, String path, final 
CacheSelector cacheSelector, CachedNodeComparator nodeComparator, CachedNodeMap 
cache, boolean sendRefreshEvents, final boolean refreshOnStart, boolean 
sortChildren)
+    InternalCuratorCache(CuratorFramework client, String path, final 
CacheSelector cacheSelector, CachedNodeMap cache, boolean sendRefreshEvents, 
final boolean refreshOnStart, boolean sortChildren)
     {
         super(path, cache, sendRefreshEvents);
         this.client = Objects.requireNonNull(client, "client cannot be null");
         this.basePath = Objects.requireNonNull(path, "path cannot be null");
         this.cacheSelector = Objects.requireNonNull(cacheSelector, 
"cacheSelector cannot be null");
-        this.nodeComparator = Objects.requireNonNull(nodeComparator, 
"nodeComparator cannot be null");
         this.sortChildren = sortChildren;
         watcher = new PersistentWatcher(client, path)
         {
@@ -171,7 +169,7 @@ class InternalCuratorCache extends CuratorCacheBase 
implements Watcher
                         {
                             notifyListeners(CacheEvent.NODE_CREATED, path, 
newNode);
                         }
-                        else if ( !nodeComparator.isSame(newNode, oldNode) )   
 // NOTE: for PATH_ONLY isSame() is always false. We aren't storing the data so 
cannot do an actual comparison
+                        else if ( newNode.getStat().getMzxid() != 
oldNode.getStat().getMzxid() )
                         {
                             notifyListeners(CacheEvent.NODE_CHANGED, path, 
newNode);
                         }

http://git-wip-us.apache.org/repos/asf/curator/blob/2abec56e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalNodeCache.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalNodeCache.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalNodeCache.java
index 9617cda..dd880f6 100644
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalNodeCache.java
+++ 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/watch/InternalNodeCache.java
@@ -43,7 +43,6 @@ class InternalNodeCache extends CuratorCacheBase
     private final WatcherRemoveCuratorFramework client;
     private final String path;
     private final CacheAction cacheAction;
-    private final CachedNodeComparator nodeComparator;
     private final AtomicBoolean isConnected = new AtomicBoolean(true);
     private static final CachedNode nullNode = new CachedNode();
     private final ConnectionStateListener connectionStateListener = new 
ConnectionStateListener()
@@ -91,13 +90,12 @@ class InternalNodeCache extends CuratorCacheBase
         }
     };
 
-    InternalNodeCache(CuratorFramework client, String path, CacheAction 
cacheAction, CachedNodeComparator nodeComparator, CachedNodeMap cache, boolean 
sendRefreshEvents, boolean refreshOnStart)
+    InternalNodeCache(CuratorFramework client, String path, CacheAction 
cacheAction, CachedNodeMap cache, boolean sendRefreshEvents, boolean 
refreshOnStart)
     {
         super(path, cache, sendRefreshEvents);
         this.client = client.newWatcherRemoveCuratorFramework();
         this.path = PathUtils.validatePath(path);
         this.cacheAction = cacheAction;
-        this.nodeComparator = nodeComparator;
         Preconditions.checkArgument(refreshOnStart, "refreshingWhenStarted() 
must be true when forSingleNode() is used");
     }
 
@@ -224,7 +222,7 @@ class InternalNodeCache extends CuratorCacheBase
         {
             notifyListeners(CacheEvent.NODE_CREATED, path, newData);
         }
-        else if ( !nodeComparator.isSame(previousData, newData) )
+        else if ( previousData.getStat().getMzxid() != 
newData.getStat().getMzxid() )
         {
             notifyListeners(CacheEvent.NODE_CHANGED, path, newData);
         }

Reply via email to