@@ -63,6 +63,7 @@ public class FileSettingsService extends AbstractLifecycleComponent implements C
63
63
64
64
private volatile FileUpdateState fileUpdateState = null ;
65
65
private volatile WatchKey settingsDirWatchKey = null ;
66
+ private volatile WatchKey configDirWatchKey = null ;
66
67
67
68
private volatile boolean active = false ;
68
69
private volatile boolean initialState = true ;
@@ -207,6 +208,17 @@ boolean watching() {
207
208
return this .watchService != null ;
208
209
}
209
210
211
+ private void cleanupWatchKeys () {
212
+ if (settingsDirWatchKey != null ) {
213
+ settingsDirWatchKey .cancel ();
214
+ settingsDirWatchKey = null ;
215
+ }
216
+ if (configDirWatchKey != null ) {
217
+ configDirWatchKey .cancel ();
218
+ configDirWatchKey = null ;
219
+ }
220
+ }
221
+
210
222
synchronized void startWatcher (ClusterState clusterState , boolean onStartup ) {
211
223
if (watching () || active == false ) {
212
224
refreshExistingFileStateIfNeeded (clusterState );
@@ -246,10 +258,11 @@ synchronized void startWatcher(ClusterState clusterState, boolean onStartup) {
246
258
// We watch the config directory always, even if initially we had an operator directory
247
259
// it can be deleted and created later. The config directory never goes away, we only
248
260
// register it once for watching.
249
- enableSettingsWatcher (null , operatorSettingsDir ().getParent ());
261
+ configDirWatchKey = enableSettingsWatcher (configDirWatchKey , operatorSettingsDir ().getParent ());
250
262
} catch (Exception e ) {
251
263
if (watchService != null ) {
252
264
try {
265
+ cleanupWatchKeys ();
253
266
this .watchService .close ();
254
267
} catch (Exception ignore ) {} finally {
255
268
this .watchService = null ;
@@ -323,10 +336,7 @@ synchronized void stopWatcher() {
323
336
logger .debug ("stopping watcher ..." );
324
337
if (watching ()) {
325
338
try {
326
- if (settingsDirWatchKey != null ) {
327
- settingsDirWatchKey .cancel ();
328
- settingsDirWatchKey = null ;
329
- }
339
+ cleanupWatchKeys ();
330
340
fileUpdateState = null ;
331
341
watchService .close ();
332
342
if (watcherThreadLatch != null ) {
0 commit comments