001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.zookeeper;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022/**
023 * Base class for internal listeners of ZooKeeper events.
024 *
025 * The {@link ZKWatcher} for a process will execute the appropriate
026 * methods of implementations of this class.  In order to receive events from
027 * the watcher, every listener must register itself via {@link ZKWatcher#registerListener}.
028 *
029 * Subclasses need only override those methods in which they are interested.
030 *
031 * Note that the watcher will be blocked when invoking methods in listeners so
032 * they must not be long-running.
033 */
034@InterfaceAudience.Private
035public abstract class ZKListener {
036
037  // Reference to the zk watcher which also contains configuration and constants
038  protected ZKWatcher watcher;
039
040  /**
041   * Construct a ZooKeeper event listener.
042   */
043  public ZKListener(ZKWatcher watcher) {
044    this.watcher = watcher;
045  }
046
047  /**
048   * Called when a new node has been created.
049   * @param path full path of the new node
050   */
051  public void nodeCreated(String path) {
052    // no-op
053  }
054
055  /**
056   * Called when a node has been deleted
057   * @param path full path of the deleted node
058   */
059  public void nodeDeleted(String path) {
060    // no-op
061  }
062
063  /**
064   * Called when an existing node has changed data.
065   * @param path full path of the updated node
066   */
067  public void nodeDataChanged(String path) {
068    // no-op
069  }
070
071  /**
072   * Called when an existing node has a child node added or removed.
073   * @param path full path of the node whose children have changed
074   */
075  public void nodeChildrenChanged(String path) {
076    // no-op
077  }
078
079  /**
080   * @return The watcher associated with this listener
081   */
082  public ZKWatcher getWatcher() {
083    return this.watcher;
084  }
085}