1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 package org.apache.hadoop.hbase.zookeeper; 20 21 import org.apache.hadoop.hbase.classification.InterfaceAudience; 22 23 /** 24 * Base class for internal listeners of ZooKeeper events. 25 * 26 * The {@link ZooKeeperWatcher} for a process will execute the appropriate 27 * methods of implementations of this class. In order to receive events from 28 * the watcher, every listener must register itself via {@link ZooKeeperWatcher#registerListener}. 29 * 30 * Subclasses need only override those methods in which they are interested. 31 * 32 * Note that the watcher will be blocked when invoking methods in listeners so 33 * they must not be long-running. 34 */ 35 @InterfaceAudience.Private 36 public abstract class ZooKeeperListener { 37 38 // Reference to the zk watcher which also contains configuration and constants 39 protected ZooKeeperWatcher watcher; 40 41 /** 42 * Construct a ZooKeeper event listener. 43 */ 44 public ZooKeeperListener(ZooKeeperWatcher watcher) { 45 this.watcher = watcher; 46 } 47 48 /** 49 * Called when a new node has been created. 50 * @param path full path of the new node 51 */ 52 public void nodeCreated(String path) { 53 // no-op 54 } 55 56 /** 57 * Called when a node has been deleted 58 * @param path full path of the deleted node 59 */ 60 public void nodeDeleted(String path) { 61 // no-op 62 } 63 64 /** 65 * Called when an existing node has changed data. 66 * @param path full path of the updated node 67 */ 68 public void nodeDataChanged(String path) { 69 // no-op 70 } 71 72 /** 73 * Called when an existing node has a child node added or removed. 74 * @param path full path of the node whose children have changed 75 */ 76 public void nodeChildrenChanged(String path) { 77 // no-op 78 } 79 80 /** 81 * @return The watcher associated with this listener 82 */ 83 public ZooKeeperWatcher getWatcher() { 84 return this.watcher; 85 } 86 }