1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.zookeeper;
21
22 import java.util.concurrent.CountDownLatch;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.zookeeper.KeeperException;
28
29
30
31
32 @InterfaceAudience.Private
33 public class DeletionListener extends ZooKeeperListener {
34
35 private static final Log LOG = LogFactory.getLog(DeletionListener.class);
36
37 private final String pathToWatch;
38 private final CountDownLatch deletedLatch;
39
40 private volatile Throwable exception;
41
42
43
44
45
46
47
48
49 public DeletionListener(ZooKeeperWatcher zkWatcher, String pathToWatch,
50 CountDownLatch deletedLatch) {
51 super(zkWatcher);
52 this.pathToWatch = pathToWatch;
53 this.deletedLatch = deletedLatch;
54 exception = null;
55 }
56
57
58
59
60
61
62 public boolean hasException() {
63 return exception != null;
64 }
65
66
67
68
69
70
71 public Throwable getException() {
72 return exception;
73 }
74
75 @Override
76 public void nodeDataChanged(String path) {
77 if (!path.equals(pathToWatch)) {
78 return;
79 }
80 try {
81 if (!(ZKUtil.setWatchIfNodeExists(watcher, pathToWatch))) {
82 deletedLatch.countDown();
83 }
84 } catch (KeeperException ex) {
85 exception = ex;
86 deletedLatch.countDown();
87 LOG.error("Error when re-setting the watch on " + pathToWatch, ex);
88 }
89 }
90
91 @Override
92 public void nodeDeleted(String path) {
93 if (!path.equals(pathToWatch)) {
94 return;
95 }
96 if (LOG.isDebugEnabled()) {
97 LOG.debug("Processing delete on " + pathToWatch);
98 }
99 deletedLatch.countDown();
100 }
101 }