Fix that APP-C LCM Command Running After OAM Stop 11/8811/3
authorHao Kuang <Hao.Kuang@amdocs.com>
Fri, 25 Aug 2017 16:15:26 +0000 (16:15 +0000)
committerSkip Wonnell <skip@att.com>
Mon, 28 Aug 2017 20:29:58 +0000 (20:29 +0000)
The fix code does that waiting for threads in the queue completely
interrupted than let bundle:stop() method return.

Issue-Id: APPC-162
Change-Id: I8b34fc48fd2ae5ae1ad67d11ee3ad5f349171b47
Signed-off-by: Hao Kuang <Hao.Kuang@amdocs.com>
appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java

index b78f399..9e1efb6 100644 (file)
@@ -30,6 +30,7 @@ import org.openecomp.appc.executionqueue.MessageExpirationListener;
 import org.openecomp.appc.executionqueue.helper.Util;
 import org.openecomp.appc.executionqueue.impl.object.QueueMessage;
 
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionException;
@@ -70,7 +71,23 @@ public class QueueManager {
      * Destory method used by blueprint
      */
     public void stop() {
-        messageExecutor.shutdownNow();
+        // Disable new tasks from being submitted
+        messageExecutor.shutdown();
+        List<Runnable> rejectedRunnables = messageExecutor.shutdownNow();
+        logger.info(String.format("Rejected %d waiting tasks include ", rejectedRunnables.size()));
+
+        try {
+            messageExecutor.shutdownNow(); // Cancel currently executing tasks
+            // Wait a while for tasks to respond to being cancelled
+            while (!messageExecutor.awaitTermination(100, TimeUnit.MILLISECONDS)) {
+                logger.debug("QueueManager is being shut down because it still has threads not interrupted");
+            }
+        } catch (InterruptedException ie) {
+            // (Re-)Cancel if current thread also interrupted
+            messageExecutor.shutdownNow();
+            // Preserve interrupt status
+            Thread.currentThread().interrupt();
+        }
     }
 
     public void setListener(MessageExpirationListener listener) {