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:17 UTC

[09/50] curator git commit: prevent double reset()

prevent double reset()


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

Branch: refs/heads/master
Commit: 6c1db4e33842bdd0aaf505c4f57f0615759ca421
Parents: 8f59209
Author: randgalt <ra...@apache.org>
Authored: Sun Jan 8 09:54:29 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sun Jan 8 09:54:29 2017 -0500

----------------------------------------------------------------------
 .../org/apache/curator/x/async/details/InternalWatcher.java     | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/6c1db4e3/curator-x-async/src/main/java/org/apache/curator/x/async/details/InternalWatcher.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/details/InternalWatcher.java b/curator-x-async/src/main/java/org/apache/curator/x/async/details/InternalWatcher.java
index 7578083..52b64e5 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/details/InternalWatcher.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/details/InternalWatcher.java
@@ -18,12 +18,14 @@
  */
 package org.apache.curator.x.async.details;
 
+import com.google.common.base.Preconditions;
 import org.apache.curator.x.async.AsyncEventException;
 import org.apache.curator.x.async.WatchMode;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionStage;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.UnaryOperator;
 
 class InternalWatcher implements Watcher
@@ -69,6 +71,8 @@ class InternalWatcher implements Watcher
                 {
                     AsyncEventException exception = new AsyncEventException()
                     {
+                        private final AtomicBoolean isReset = new AtomicBoolean(false);
+
                         @Override
                         public Event.KeeperState getKeeperState()
                         {
@@ -78,6 +82,7 @@ class InternalWatcher implements Watcher
                         @Override
                         public CompletionStage<WatchedEvent> reset()
                         {
+                            Preconditions.checkState(isReset.compareAndSet(false, true), "Already reset");
                             future = new CompletableFuture<>();
                             return future;
                         }