@@ -44,6 +44,7 @@ public class ZooKeeperWatcherBase implements Watcher {
44
44
.getLogger (ZooKeeperWatcherBase .class );
45
45
46
46
private final int zkSessionTimeOut ;
47
+ private final boolean allowReadOnlyMode ;
47
48
private volatile CountDownLatch clientConnectLatch = new CountDownLatch (1 );
48
49
private final CopyOnWriteArraySet <Watcher > childWatchers =
49
50
new CopyOnWriteArraySet <Watcher >();
@@ -53,18 +54,20 @@ public class ZooKeeperWatcherBase implements Watcher {
53
54
private final ConcurrentHashMap <EventType , Counter > eventCounters =
54
55
new ConcurrentHashMap <EventType , Counter >();
55
56
56
- public ZooKeeperWatcherBase (int zkSessionTimeOut ) {
57
- this (zkSessionTimeOut , NullStatsLogger .INSTANCE );
57
+ public ZooKeeperWatcherBase (int zkSessionTimeOut , boolean allowReadOnlyMode ) {
58
+ this (zkSessionTimeOut , allowReadOnlyMode , NullStatsLogger .INSTANCE );
58
59
}
59
60
60
- public ZooKeeperWatcherBase (int zkSessionTimeOut , StatsLogger statsLogger ) {
61
- this (zkSessionTimeOut , new HashSet <Watcher >(), statsLogger );
61
+ public ZooKeeperWatcherBase (int zkSessionTimeOut , boolean allowReadOnlyMode , StatsLogger statsLogger ) {
62
+ this (zkSessionTimeOut , allowReadOnlyMode , new HashSet <Watcher >(), statsLogger );
62
63
}
63
64
64
65
public ZooKeeperWatcherBase (int zkSessionTimeOut ,
66
+ boolean allowReadOnlyMode ,
65
67
Set <Watcher > childWatchers ,
66
68
StatsLogger statsLogger ) {
67
69
this .zkSessionTimeOut = zkSessionTimeOut ;
70
+ this .allowReadOnlyMode = allowReadOnlyMode ;
68
71
this .childWatchers .addAll (childWatchers );
69
72
this .statsLogger = statsLogger ;
70
73
}
@@ -130,6 +133,14 @@ public void process(WatchedEvent event) {
130
133
LOG .info ("ZooKeeper client is connected now." );
131
134
clientConnectLatch .countDown ();
132
135
break ;
136
+ case ConnectedReadOnly :
137
+ if (allowReadOnlyMode ) {
138
+ LOG .info ("ZooKeeper client is connected in read-only mode now." );
139
+ clientConnectLatch .countDown ();
140
+ } else {
141
+ LOG .warn ("ZooKeeper client is connected in read-only mode, which is not allowed." );
142
+ }
143
+ break ;
133
144
case Disconnected :
134
145
LOG .info ("ZooKeeper client is disconnected from zookeeper now,"
135
146
+ " but it is OK unless we received EXPIRED event." );
0 commit comments