1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.linecorp.centraldogma.server.internal.replication;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.concurrent.Executor;
21
22 import org.apache.curator.framework.recipes.shared.SharedCountListener;
23 import org.apache.curator.framework.recipes.shared.SharedCountReader;
24 import org.apache.curator.framework.recipes.shared.VersionedValue;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 final class SettableSharedCount implements SharedCountReader {
29
30 private static final Logger logger = LoggerFactory.getLogger(SettableSharedCount.class);
31
32 private final List<SharedCountListener> listeners;
33 private int count;
34
35 SettableSharedCount(int count) {
36 this.count = count;
37 listeners = new ArrayList<>();
38 }
39
40 void setCount(int count) {
41 this.count = count;
42 for (SharedCountListener listener : listeners) {
43 try {
44 listener.countHasChanged(this, count);
45 } catch (Exception e) {
46 logger.warn("Unexpected exception caught while notifying {}", listener, e);
47 }
48 }
49 }
50
51 @Override
52 public int getCount() {
53 return count;
54 }
55
56 @Override
57 public VersionedValue<Integer> getVersionedValue() {
58 throw new UnsupportedOperationException();
59 }
60
61 @Override
62 public void addListener(SharedCountListener listener) {
63 listeners.add(listener);
64 }
65
66 @Override
67 public void addListener(SharedCountListener listener, Executor executor) {
68 throw new UnsupportedOperationException();
69 }
70
71 @Override
72 public void removeListener(SharedCountListener listener) {
73 throw new UnsupportedOperationException();
74 }
75 }