aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java79
1 files changed, 37 insertions, 42 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
index 74fbb2c660..dc58a24e5f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
@@ -20,62 +20,57 @@
package org.openecomp.sdc.be.components.distribution.engine;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.concurrent.*;
public class NotificationExecutorService {
- private static Logger logger = LoggerFactory.getLogger(NotificationExecutorService.class.getName());
+ private static final Logger logger = LoggerFactory.getLogger(NotificationExecutorService.class);
- public ExecutorService createExcecutorService(DistributionNotificationTopicConfig distributionNotificationTopic) {
+ public ExecutorService createExcecutorService(DistributionNotificationTopicConfig distributionNotificationTopic) {
- Integer minThreadPoolSize = distributionNotificationTopic.getMinThreadPoolSize();
- if (minThreadPoolSize == null) {
- minThreadPoolSize = 0;
- }
+ Integer minThreadPoolSize = distributionNotificationTopic.getMinThreadPoolSize();
+ if (minThreadPoolSize == null) {
+ minThreadPoolSize = 0;
+ }
- Integer maxThreadPoolSize = distributionNotificationTopic.getMaxThreadPoolSize();
- if (maxThreadPoolSize == null) {
- maxThreadPoolSize = 10;
- }
+ Integer maxThreadPoolSize = distributionNotificationTopic.getMaxThreadPoolSize();
+ if (maxThreadPoolSize == null) {
+ maxThreadPoolSize = 10;
+ }
- ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder();
- threadFactoryBuilder.setNameFormat("distribution-notification-thread-%d");
- ThreadFactory threadFactory = threadFactoryBuilder.build();
+ ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder();
+ threadFactoryBuilder.setNameFormat("distribution-notification-thread-%d");
+ ThreadFactory threadFactory = threadFactoryBuilder.build();
- ExecutorService executorService = new ThreadPoolExecutor(minThreadPoolSize, maxThreadPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory);
+ ExecutorService executorService = new ThreadPoolExecutor(minThreadPoolSize, maxThreadPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory);
- return executorService;
- }
+ return executorService;
+ }
- public void shutdownAndAwaitTermination(ExecutorService pool, long maxTimeToWait) {
+ public void shutdownAndAwaitTermination(ExecutorService pool, long maxTimeToWait) {
- logger.debug("shutdown NotificationExecutorService");
- pool.shutdown(); // Disable new tasks from being submitted
- try {
- // Wait a while for existing tasks to terminate
- if (!pool.awaitTermination(maxTimeToWait, TimeUnit.SECONDS)) {
- pool.shutdownNow(); // Cancel currently executing tasks
- // Wait a while for tasks to respond to being cancelled
- if (!pool.awaitTermination(maxTimeToWait, TimeUnit.SECONDS)) {
- logger.debug("Failed to close executor service");
- }
- }
- } catch (InterruptedException ie) {
- // (Re-)Cancel if current thread also interrupted
- pool.shutdownNow();
- // Preserve interrupt status
- Thread.currentThread().interrupt();
- }
- }
+ logger.debug("shutdown NotificationExecutorService");
+ pool.shutdown(); // Disable new tasks from being submitted
+ try {
+ // Wait a while for existing tasks to terminate
+ if (!pool.awaitTermination(maxTimeToWait, TimeUnit.SECONDS)) {
+ pool.shutdownNow(); // Cancel currently executing tasks
+ // Wait a while for tasks to respond to being cancelled
+ if (!pool.awaitTermination(maxTimeToWait, TimeUnit.SECONDS)) {
+ logger.debug("Failed to close executor service");
+ }
+ }
+ } catch (InterruptedException ie) {
+ // (Re-)Cancel if current thread also interrupted
+ pool.shutdownNow();
+ // Preserve interrupt status
+ Thread.currentThread().interrupt();
+ }
+ }
}