diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-01-25 18:22:46 +0100 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-01-26 02:55:10 +0000 |
commit | be752d30c939d6d9ea266b5cdeb2fb4d110d1b31 (patch) | |
tree | c09adb73ca8f5c1b99e5fceeae5e17874f8a836d | |
parent | 9c2071e0b5281635753d137ba50eb1e05df2f900 (diff) |
TaskQueueManager fixes
Change-Id: I246683edabbd851125fc47772be203c2c7482a9c
Issue-ID: APPC-528
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r-- | appc-client/client-lib/src/main/java/org/onap/appc/client/impl/core/TaskQueueManager.java | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/appc-client/client-lib/src/main/java/org/onap/appc/client/impl/core/TaskQueueManager.java b/appc-client/client-lib/src/main/java/org/onap/appc/client/impl/core/TaskQueueManager.java index b87349411..d0314c81d 100644 --- a/appc-client/client-lib/src/main/java/org/onap/appc/client/impl/core/TaskQueueManager.java +++ b/appc-client/client-lib/src/main/java/org/onap/appc/client/impl/core/TaskQueueManager.java @@ -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()); } } |