TaskQueueManager fixes 03/29203/2
authorJakub Dudycz <jakub.dudycz@nokia.com>
Thu, 25 Jan 2018 17:22:46 +0000 (18:22 +0100)
committerTakamune Cho <tc012c@att.com>
Fri, 26 Jan 2018 02:55:10 +0000 (02:55 +0000)
Change-Id: I246683edabbd851125fc47772be203c2c7482a9c
Issue-ID: APPC-528
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
appc-client/client-lib/src/main/java/org/onap/appc/client/impl/core/TaskQueueManager.java

index b873494..d0314c8 100644 (file)
@@ -26,34 +26,35 @@ package org.onap.appc.client.impl.core;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
-/** Creates a task queue pool that reuses a fixed number of threads.
- * Assigns one thread for each queue.
+/**
+ * Creates a task queue pool that reuses a fixed number of threads. Assigns one thread for each queue.
  */
 class TaskQueueManager {
-    private final EELFLogger LOG = EELFManager.getInstance().getLogger(TaskQueueManager.class);
+
+    private static final EELFLogger LOG = EELFManager.getInstance().getLogger(TaskQueueManager.class);
+    private static final String DEFAULT_POOL_SIZE = "10";
+    private static final String CLIENT_POOL_SIZE = "client.pool.size";
+
     private ExecutorService executorService;
-    private final static String DEFAULT_POOL_SIZE = "10";
-    private final static String CLIENT_POOL_SIZE = "client.pool.size";
     private TaskQueue[] queues;
     private int poolInt;
 
-    TaskQueueManager(Properties properties){
+    TaskQueueManager(Properties properties) {
         String size = properties.getProperty(CLIENT_POOL_SIZE, DEFAULT_POOL_SIZE);
         poolInt = Integer.parseInt(size);
         this.executorService = Executors.newFixedThreadPool(poolInt);
         initTaskQueues();
     }
 
-    private void initTaskQueues(){
+    private void initTaskQueues() {
         queues = new TaskQueue[poolInt];
-        for(int i=0; i<poolInt; i++){
+        for (int i = 0; i < poolInt; i++) {
             queues[i] = new TaskQueue();
             this.executorService.submit(queues[i]);
         }
@@ -66,33 +67,27 @@ class TaskQueueManager {
 
     /**
      * ensures synchronous handling all responses and timeout belongs to same correlation ID
-     * @param corrID
      * @return - @{@link TaskQueue}
      */
-    private TaskQueue getTaskQueue(String corrID){
+    private TaskQueue getTaskQueue(String corrID) {
         int index = Math.abs(corrID.hashCode()) % poolInt;
         return queues[index];
     }
 
     /**
      * goes over queues for stopping threads
-     * @throws InterruptedException
      */
     void stopQueueManager() throws InterruptedException {
-        for(int i=0; i<poolInt; i++){
+        for (int i = 0; i < poolInt; i++) {
             queues[i].stopQueue();
-            queues[i].addTask(new Runnable() {
-                @Override
-                public void run() {
-                    /**
-                     * wake up the queue for stopping thread
-                     */
-                }
+            queues[i].addTask(() -> {
+             // wake up the queue for stopping thread
             });
         }
         List<Runnable> listTask = executorService.shutdownNow();
-        if (!executorService.awaitTermination(6, TimeUnit.SECONDS))
-            System.err.println("Pool did not terminate");
+        if (!executorService.awaitTermination(6, TimeUnit.SECONDS)) {
+            LOG.error("Pool did not terminate");
+        }
         LOG.info("the amount of tasks that never commenced execution " + listTask.size());
     }
 }