Return-Path: X-Original-To: apmail-curator-dev-archive@minotaur.apache.org Delivered-To: apmail-curator-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8DE5817E61 for ; Mon, 11 May 2015 22:22:22 +0000 (UTC) Received: (qmail 24622 invoked by uid 500); 11 May 2015 22:22:22 -0000 Delivered-To: apmail-curator-dev-archive@curator.apache.org Received: (qmail 24577 invoked by uid 500); 11 May 2015 22:22:22 -0000 Mailing-List: contact dev-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list dev@curator.apache.org Received: (qmail 24566 invoked by uid 99); 11 May 2015 22:22:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 May 2015 22:22:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 16508E07EE; Mon, 11 May 2015 22:22:22 +0000 (UTC) From: cammckenzie To: dev@curator.apache.org Reply-To: dev@curator.apache.org References: In-Reply-To: Subject: [GitHub] curator pull request: Curator 161 Content-Type: text/plain Message-Id: <20150511222222.16508E07EE@git1-us-west.apache.org> Date: Mon, 11 May 2015 22:22:22 +0000 (UTC) Github user cammckenzie commented on a diff in the pull request: https://github.com/apache/curator/pull/56#discussion_r30088622 --- Diff: curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java --- @@ -0,0 +1,214 @@ +package org.apache.curator.framework.imps; + +import java.util.concurrent.Callable; +import java.util.concurrent.Executor; + +import org.apache.curator.RetryLoop; +import org.apache.curator.TimeTrace; +import org.apache.curator.framework.api.BackgroundCallback; +import org.apache.curator.framework.api.BackgroundPathable; +import org.apache.curator.framework.api.BackgroundPathableQuietly; +import org.apache.curator.framework.api.CuratorEvent; +import org.apache.curator.framework.api.CuratorEventType; +import org.apache.curator.framework.api.CuratorWatcher; +import org.apache.curator.framework.api.Pathable; +import org.apache.curator.framework.api.RemoveWatchesLocal; +import org.apache.curator.framework.api.RemoveWatchesBuilder; +import org.apache.curator.framework.api.RemoveWatchesType; +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooKeeper; + + +public class RemoveWatchesBuilderImpl implements RemoveWatchesBuilder, RemoveWatchesType, RemoveWatchesLocal, BackgroundOperation +{ + private CuratorFrameworkImpl client; + private Watcher watcher; + private WatcherType watcherType; + private boolean local; + private boolean quietly; + private Backgrounding backgrounding; + + public RemoveWatchesBuilderImpl(CuratorFrameworkImpl client) + { + this.client = client; + this.watcher = null; + this.watcherType = WatcherType.Any; + this.local = false; + this.quietly = false; + this.backgrounding = new Backgrounding(); + } + + @Override + public RemoveWatchesType remove(Watcher watcher) + { + this.watcher = watcher == null ? null : client.getNamespaceWatcherMap().getNamespaceWatcher(watcher); + return this; + } + + @Override + public RemoveWatchesType remove(CuratorWatcher watcher) + { + this.watcher = watcher == null ? null : client.getNamespaceWatcherMap().getNamespaceWatcher(watcher); + return this; + } + + @Override + public RemoveWatchesType removeAll() + { + this.watcher = null; + return this; + } + + @Override + public RemoveWatchesLocal ofType(WatcherType watcherType) + { + this.watcherType = watcherType; + + return this; + } + + @Override + public Pathable inBackground(BackgroundCallback callback, Object context) + { + backgrounding = new Backgrounding(callback, context); + return this; + } + + @Override + public Pathable inBackground(BackgroundCallback callback, Object context, Executor executor) + { + backgrounding = new Backgrounding(client, callback, context, executor); + return this; + } + + @Override + public Pathable inBackground(BackgroundCallback callback) + { + backgrounding = new Backgrounding(callback); + return this; + } + + @Override + public Pathable inBackground(BackgroundCallback callback, Executor executor) + { + backgrounding = new Backgrounding(client, callback, executor); + return this; + } + + @Override + public Pathable inBackground() + { + backgrounding = new Backgrounding(true); + return this; + } + + @Override + public Pathable inBackground(Object context) + { + backgrounding = new Backgrounding(context); + return this; + } + + @Override + public BackgroundPathableQuietly locally() + { + local = true; + return this; + } + + @Override + public BackgroundPathable quietly() + { + quietly = true; + return this; + } + + @Override + public Void forPath(String path) throws Exception + { + final String adjustedPath = client.fixForNamespace(path); + + if(backgrounding.inBackground()) + { + pathInBackground(adjustedPath); + } + else + { + pathInForeground(adjustedPath); + } + + return null; + } + + private void pathInBackground(String path) + { + OperationAndData.ErrorCallback errorCallback = null; + client.processBackgroundOperation(new OperationAndData(this, path, backgrounding.getCallback(), errorCallback, backgrounding.getContext()), null); + } + + private void pathInForeground(final String path) throws Exception + { + RetryLoop.callWithRetry(client.getZookeeperClient(), + new Callable() + { + @Override + public Void call() throws Exception + { + try + { + ZooKeeper zkClient = client.getZooKeeper(); + if(watcher == null) --- End diff -- What is it that seems wrong? If no Watcher is specified this means that we're removing all watches for a given path. If a Watcher is specified then this means we're removing a specific watch from a given path. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---