Repository: curator Updated Branches: refs/heads/CURATOR-3.0 c6a22ba50 -> 6acf09871
CURATOR-294: Make ChildData immutable; PathChildrenCache replaces instead of mutates. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/38de6285 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/38de6285 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/38de6285 Branch: refs/heads/CURATOR-3.0 Commit: 38de6285ab83e0cee2d66443710a8804a7e605d1 Parents: 649e0ba Author: Scott Blum <[email protected]> Authored: Thu Jan 28 12:38:57 2016 -0500 Committer: Scott Blum <[email protected]> Committed: Mon Feb 1 14:11:55 2016 -0500 ---------------------------------------------------------------------- .../framework/recipes/cache/ChildData.java | 22 +++++++------------- .../recipes/cache/PathChildrenCache.java | 5 ++++- 2 files changed, 12 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/38de6285/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/ChildData.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/ChildData.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/ChildData.java index 21e0bc4..e3c60cf 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/ChildData.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/ChildData.java @@ -20,20 +20,19 @@ package org.apache.curator.framework.recipes.cache; import org.apache.zookeeper.data.Stat; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicReference; import org.apache.curator.utils.PathUtils; public class ChildData implements Comparable<ChildData> { - private final String path; - private final Stat stat; - private final AtomicReference<byte[]> data; + private final String path; + private final Stat stat; + private final byte[] data; public ChildData(String path, Stat stat, byte[] data) { this.path = PathUtils.validatePath(path); this.stat = stat; - this.data = new AtomicReference<byte[]>(data); + this.data = data; } /** @@ -71,7 +70,7 @@ public class ChildData implements Comparable<ChildData> ChildData childData = (ChildData)o; - if ( !Arrays.equals(data.get(), childData.data.get()) ) + if ( !Arrays.equals(data, childData.data) ) { return false; } @@ -92,7 +91,7 @@ public class ChildData implements Comparable<ChildData> { int result = path != null ? path.hashCode() : 0; result = 31 * result + (stat != null ? stat.hashCode() : 0); - result = 31 * result + (data != null ? Arrays.hashCode(data.get()) : 0); + result = 31 * result + Arrays.hashCode(data); return result; } @@ -126,12 +125,7 @@ public class ChildData implements Comparable<ChildData> */ public byte[] getData() { - return data.get(); - } - - void clearData() - { - data.set(null); + return data; } @Override @@ -140,7 +134,7 @@ public class ChildData implements Comparable<ChildData> return "ChildData{" + "path='" + path + '\'' + ", stat=" + stat + - ", data=" + Arrays.toString(data.get()) + + ", data=" + Arrays.toString(data) + '}'; } } http://git-wip-us.apache.org/repos/asf/curator/blob/38de6285/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java index 12769e1..ae30da9 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java @@ -448,7 +448,10 @@ public class PathChildrenCache implements Closeable { if ( (ifVersion < 0) || (ifVersion == data.getStat().getVersion()) ) { - data.clearData(); + if ( data.getData() != null ) + { + currentData.replace(fullPath, data, new ChildData(data.getPath(), data.getStat(), null)); + } return true; } }
