curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CURATOR-217) Use new Watcher Removal APIs in Curator Recipes
Date Wed, 20 May 2015 00:09:00 GMT

    [ https://issues.apache.org/jira/browse/CURATOR-217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14551523#comment-14551523
] 

ASF GitHub Bot commented on CURATOR-217:
----------------------------------------

Github user cammckenzie commented on a diff in the pull request:

    https://github.com/apache/curator/pull/82#discussion_r30661149
  
    --- 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<WrappedWatcher> 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<? extends Watcher> getEntries()
    +    {
    +        return Sets.newHashSet(entries);
    +    }
    +
    +    void removeWatchers()
    +    {
    +        HashSet<WrappedWatcher> 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 --
    
    That would probably be a good idea. You could do it as a guaranteed background operation.


> 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)

Mime
View raw message