sijie commented on a change in pull request #838: Issue-326: Replace observer/observable with a simplified watcher/watchable implementation URL: https://github.com/apache/bookkeeper/pull/838#discussion_r156726460
########## File path: bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/Watchable.java ########## @@ -0,0 +1,120 @@ +/* + * 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.bookkeeper.common.util; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.function.Function; +import org.apache.bookkeeper.common.collections.RecyclableHashSet; +import org.apache.bookkeeper.common.collections.RecyclableHashSet.Recycler; + +/** + * This class represents an watchable object, or "data" + * in the model-view paradigm. It can be subclassed to represent an + * object that the application wants to have watched. + * + * <p>An watchable object can have one or more watchers. An watcher + * may be any object that implements interface <tt>Watcher</tt>. After an + * watchable instance changes, an application calling the + * <code>Watchable</code>'s <code>notifyWatchers</code> method + * causes all of its watchers to be notified of the change by a call + * to their <code>update</code> method. + * + * <p>A watcher is automatically removed from the watchers list once an event + * is fired to the watcher. + * + * <p>Note that this notification mechanism has nothing to do with threads + * and is completely separate from the <tt>wait</tt> and <tt>notify</tt> + * mechanism of class <tt>Object</tt>. + * + * <p>When an watchable object is newly created, its set of watchers is + * empty. Two watchers are considered the same if and only if the + * <tt>equals</tt> method returns true for them. + */ +public class Watchable<T> implements Recyclable { Review comment: yes. it is needed when it holds a reference to a recyclable object. FileInfo needs to recycle this when it is closed. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
