diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java index fa546ee83..af215cbad 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java @@ -33,7 +33,6 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperation, ErrorListenerEnsembleable { private final CuratorFrameworkImpl client; - private final WatcherRemovalManager watcherRemovalManager; private Backgrounding backgrounding; private Watching watching; @@ -45,14 +44,8 @@ public GetConfigBuilderImpl(CuratorFrameworkImpl client) { public GetConfigBuilderImpl(CuratorFrameworkImpl client, Backgrounding backgrounding, Watcher watcher, Stat stat) { this.client = (CuratorFrameworkImpl) client.usingNamespace(null); - this.watcherRemovalManager = client.getWatcherRemovalManager(); this.backgrounding = backgrounding; - // We are using `client.usingNamespace(null)` to avoid `unfixNamespace` for "/zookeeper/config"(CURATOR-667) - // events. But `client.usingNamespace(null)` will loss possible `WatcherRemovalManager`(CURATOR-710). So, let's - // reset it. - // - // See also `NamespaceWatchedEvent`. - this.watching = new Watching(this.client, watcher).setWatcherRemovalManager(watcherRemovalManager); + this.watching = new Watching(this.client, watcher); this.stat = stat; } @@ -115,19 +108,19 @@ public BackgroundEnsembleable usingWatcher(CuratorWatcher watcher) { @Override public BackgroundEnsembleable watched() { - watching = new Watching(client, true).setWatcherRemovalManager(watcherRemovalManager); + watching = new Watching(client, true); return new InternalBackgroundEnsembleable(); } @Override public BackgroundEnsembleable usingWatcher(Watcher watcher) { - watching = new Watching(client, watcher).setWatcherRemovalManager(watcherRemovalManager); + watching = new Watching(client, watcher); return new InternalBackgroundEnsembleable(); } @Override public BackgroundEnsembleable usingWatcher(CuratorWatcher watcher) { - watching = new Watching(client, watcher).setWatcherRemovalManager(watcherRemovalManager); + watching = new Watching(client, watcher); return new InternalBackgroundEnsembleable(); } diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java index ba5ce42cc..01e96f5e3 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java @@ -37,9 +37,13 @@ class WatcherRemovalFacade extends CuratorFrameworkImpl implements WatcherRemove private final WatcherRemovalManager removalManager; WatcherRemovalFacade(CuratorFrameworkImpl client) { + this(client, new WatcherRemovalManager(client)); + } + + private WatcherRemovalFacade(CuratorFrameworkImpl client, WatcherRemovalManager removalManager) { super(client); this.client = client; - removalManager = new WatcherRemovalManager(client); + this.removalManager = removalManager; } @Override @@ -73,7 +77,8 @@ public CuratorFramework nonNamespaceView() { @Override public CuratorFramework usingNamespace(String newNamespace) { - return client.usingNamespace(newNamespace); + final CuratorFrameworkImpl newClient = (CuratorFrameworkImpl) client.usingNamespace(newNamespace); + return new WatcherRemovalFacade(newClient, removalManager); } @Override diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/Watching.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/Watching.java index 5cde149fc..b381f4136 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/Watching.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/Watching.java @@ -28,12 +28,10 @@ public class Watching { private final CuratorWatcher curatorWatcher; private final boolean watched; private final CuratorFrameworkImpl client; - private WatcherRemovalManager watcherRemovalManager; private NamespaceWatcher namespaceWatcher; public Watching(CuratorFrameworkImpl client, boolean watched) { this.client = client; - this.watcherRemovalManager = client.getWatcherRemovalManager(); this.watcher = null; this.curatorWatcher = null; this.watched = watched; @@ -41,7 +39,6 @@ public Watching(CuratorFrameworkImpl client, boolean watched) { public Watching(CuratorFrameworkImpl client, Watcher watcher) { this.client = client; - this.watcherRemovalManager = client.getWatcherRemovalManager(); this.watcher = watcher; this.curatorWatcher = null; this.watched = false; @@ -49,7 +46,6 @@ public Watching(CuratorFrameworkImpl client, Watcher watcher) { public Watching(CuratorFrameworkImpl client, CuratorWatcher watcher) { this.client = client; - this.watcherRemovalManager = client.getWatcherRemovalManager(); this.watcher = null; this.curatorWatcher = watcher; this.watched = false; @@ -57,17 +53,11 @@ public Watching(CuratorFrameworkImpl client, CuratorWatcher watcher) { public Watching(CuratorFrameworkImpl client) { this.client = client; - this.watcherRemovalManager = client.getWatcherRemovalManager(); watcher = null; watched = false; curatorWatcher = null; } - Watching setWatcherRemovalManager(WatcherRemovalManager watcherRemovalManager) { - this.watcherRemovalManager = watcherRemovalManager; - return this; - } - Watcher getWatcher(String unfixedPath) { namespaceWatcher = null; if (watcher != null) { @@ -95,8 +85,8 @@ void commitWatcher(int rc, boolean isExists) { doCommit = (rc == KeeperException.Code.OK.intValue()); } - if (doCommit && namespaceWatcher != null && watcherRemovalManager != null) { - watcherRemovalManager.add(namespaceWatcher); + if (doCommit && namespaceWatcher != null && client.getWatcherRemovalManager() != null) { + client.getWatcherRemovalManager().add(namespaceWatcher); } } }