1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.procedure2.store;
20
21 import java.util.concurrent.CopyOnWriteArrayList;
22 import java.util.concurrent.atomic.AtomicBoolean;
23
24
25
26
27 public abstract class ProcedureStoreBase implements ProcedureStore {
28 private final CopyOnWriteArrayList<ProcedureStoreListener> listeners =
29 new CopyOnWriteArrayList<ProcedureStoreListener>();
30
31 private final AtomicBoolean running = new AtomicBoolean(false);
32
33
34
35
36
37
38
39
40 protected boolean setRunning(boolean isRunning) {
41 return running.getAndSet(isRunning) != isRunning;
42 }
43
44 @Override
45 public boolean isRunning() {
46 return running.get();
47 }
48
49 @Override
50 public void registerListener(ProcedureStoreListener listener) {
51 listeners.add(listener);
52 }
53
54 @Override
55 public boolean unregisterListener(ProcedureStoreListener listener) {
56 return listeners.remove(listener);
57 }
58
59 protected void sendPostSyncSignal() {
60 if (!this.listeners.isEmpty()) {
61 for (ProcedureStoreListener listener : this.listeners) {
62 listener.postSync();
63 }
64 }
65 }
66
67 protected void sendAbortProcessSignal() {
68 if (!this.listeners.isEmpty()) {
69 for (ProcedureStoreListener listener : this.listeners) {
70 listener.abortProcess();
71 }
72 }
73 }
74 }