diff options
Diffstat (limited to 'appc-client/client-lib/src')
-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()); } } |