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 8DAF817CAE for ; Tue, 19 May 2015 23:56:00 +0000 (UTC) Received: (qmail 1496 invoked by uid 500); 19 May 2015 23:56:00 -0000 Delivered-To: apmail-curator-dev-archive@curator.apache.org Received: (qmail 1439 invoked by uid 500); 19 May 2015 23:56:00 -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 1427 invoked by uid 99); 19 May 2015 23:56:00 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2015 23:56:00 +0000 Date: Tue, 19 May 2015 23:56:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@curator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CURATOR-217) Use new Watcher Removal APIs in Curator Recipes MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CURATOR-217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14551501#comment-14551501 ] ASF GitHub Bot commented on CURATOR-217: ---------------------------------------- Github user Randgalt commented on a diff in the pull request: https://github.com/apache/curator/pull/82#discussion_r30660440 --- Diff: curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalManager.java --- @@ -0,0 +1,138 @@ +/** + * 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.imps; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.HashSet; +import java.util.Set; + +public class WatcherRemovalManager +{ + private final Logger log = LoggerFactory.getLogger(getClass()); + private final CuratorFrameworkImpl client; + private final Set entries = Sets.newHashSet(); // guarded by sync + + WatcherRemovalManager(CuratorFrameworkImpl client) + { + this.client = client; + } + + synchronized Watcher add(String path, Watcher watcher) + { + path = Preconditions.checkNotNull(path, "path cannot be null"); + watcher = Preconditions.checkNotNull(watcher, "watcher cannot be null"); + + WrappedWatcher wrappedWatcher = new WrappedWatcher(watcher, path); + entries.add(wrappedWatcher); + return wrappedWatcher; + } + + @VisibleForTesting + synchronized Set getEntries() + { + return Sets.newHashSet(entries); + } + + void removeWatchers() + { + HashSet localEntries; + synchronized(this) + { + localEntries = Sets.newHashSet(entries); + } + for ( WrappedWatcher entry : localEntries ) + { + try + { + log.debug("Removing watcher for path: " + entry.path); + RemoveWatchesBuilderImpl builder = new RemoveWatchesBuilderImpl(client); + builder.prepInternalRemoval(entry); + builder.pathInForeground(entry.path); --- End diff -- I wonder if this should be a background/async call instead > Use new Watcher Removal APIs in Curator Recipes > ----------------------------------------------- > > Key: CURATOR-217 > URL: https://issues.apache.org/jira/browse/CURATOR-217 > Project: Apache Curator > Issue Type: Sub-task > Components: Recipes > Affects Versions: 3.0.0 > Reporter: Jordan Zimmerman > Assignee: Jordan Zimmerman > Fix For: 3.0.0 > > > Once the new Watcher Removal APIs are available, every Curator Recipe should be reviewed so that they clean up watchers as appropriate. -- This message was sent by Atlassian JIRA (v6.3.4#6332)