BGPCEP-718: Hide InterruptedException 70/65470/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Sun, 12 Nov 2017 18:45:35 +0000 (19:45 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 13 Nov 2017 11:38:27 +0000 (11:38 +0000)
coming from closing thread, when closing module.
Avoiding confuse message.

Change-Id: Ica45c84b33f5d3b30ea3f61e5b76cf01bad5c03d
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
config-loader/config-loader-impl/src/main/java/org/opendaylight/protocol/bgp/config/loader/impl/ConfigLoaderImpl.java

index 8c715c5db385395b00c92d085c8bffe50ff8d3bf..aa579a3817e01dd52438f68d69d0c5230982d4a3 100644 (file)
@@ -15,7 +15,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URISyntaxException;
-import java.nio.file.ClosedWatchServiceException;
 import java.nio.file.WatchEvent;
 import java.nio.file.WatchKey;
 import java.nio.file.WatchService;
@@ -54,6 +53,8 @@ public final class ConfigLoaderImpl implements ConfigLoader, AutoCloseable {
     private final BindingNormalizedNodeSerializer bindingSerializer;
     private final String path;
     private final Thread watcherThread;
+    @GuardedBy("this")
+    private boolean closed = false;
 
     public ConfigLoaderImpl(final SchemaContext schemaContext, final BindingNormalizedNodeSerializer bindingSerializer,
             final String path, final WatchService watchService) {
@@ -129,7 +130,9 @@ public final class ConfigLoaderImpl implements ConfigLoader, AutoCloseable {
 
 
     @Override
-    public void close() throws Exception {
+    public synchronized void close() throws Exception {
+        LOG.info("Config Loader service closed");
+        this.closed = true;
         this.watcherThread.interrupt();
     }
 
@@ -148,19 +151,25 @@ public final class ConfigLoaderImpl implements ConfigLoader, AutoCloseable {
         }
 
         private synchronized void handleChanges(final WatchService watchService) {
+            final WatchKey key;
             try {
-                final WatchKey key = watchService.take();
-                if (key != null) {
-                    for (final WatchEvent<?> event : key.pollEvents()) {
-                        handleEvent(event.context().toString());
-                    }
-                    final boolean reset = key.reset();
-                    if (!reset) {
-                        LOG.warn("Could not reset the watch key.");
-                    }
+                key = watchService.take();
+            } catch (final InterruptedException e) {
+                if (!ConfigLoaderImpl.this.closed) {
+                    LOG.warn(INTERRUPTED, e);
+                    Thread.currentThread().interrupt();
+                }
+                return;
+            }
+
+            if (key != null) {
+                for (final WatchEvent<?> event : key.pollEvents()) {
+                    handleEvent(event.context().toString());
+                }
+                final boolean reset = key.reset();
+                if (!reset) {
+                    LOG.warn("Could not reset the watch key.");
                 }
-            } catch (final InterruptedException | ClosedWatchServiceException e) {
-                LOG.warn(INTERRUPTED, e);
             }
         }