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. The {@link ZKWatcher} for a process will 024 * execute the appropriate methods of implementations of this class. In order to receive events from 025 * the watcher, every listener must register itself via {@link ZKWatcher#registerListener}. 026 * Subclasses need only override those methods in which they are interested. Note that the watcher 027 * will be blocked when invoking methods in listeners so they must not be long-running. 028 */ 029@InterfaceAudience.Private 030public abstract class ZKListener { 031 032 // Reference to the zk watcher which also contains configuration and constants 033 protected ZKWatcher watcher; 034 035 /** 036 * Construct a ZooKeeper event listener. 037 */ 038 public ZKListener(ZKWatcher watcher) { 039 this.watcher = watcher; 040 } 041 042 /** 043 * Called when a new node has been created. 044 * @param path full path of the new node 045 */ 046 public void nodeCreated(String path) { 047 // no-op 048 } 049 050 /** 051 * Called when a node has been deleted 052 * @param path full path of the deleted node 053 */ 054 public void nodeDeleted(String path) { 055 // no-op 056 } 057 058 /** 059 * Called when an existing node has changed data. 060 * @param path full path of the updated node 061 */ 062 public void nodeDataChanged(String path) { 063 // no-op 064 } 065 066 /** 067 * Called when an existing node has a child node added or removed. 068 * @param path full path of the node whose children have changed 069 */ 070 public void nodeChildrenChanged(String path) { 071 // no-op 072 } 073 074 /** Returns The watcher associated with this listener */ 075 public ZKWatcher getWatcher() { 076 return this.watcher; 077 } 078}