Add task scheduler 'init' call 58/2758/2
authorSerban Jora <sj2381@att.com>
Mon, 10 Sep 2018 03:58:44 +0000 (23:58 -0400)
committerSerban Jora <sj2381@att.com>
Mon, 10 Sep 2018 11:38:02 +0000 (07:38 -0400)
Change-Id: Ie96e5644d3600a6846548a566681cb4f9940f8a4
Issue-ID: ACUMOS-1690
Signed-off-by: Serban Jora <sj2381@att.com>
docs/release-notes.rst
gateway/src/main/java/org/acumos/federation/gateway/task/PeerSubscriptionTaskScheduler.java
gateway/src/main/java/org/acumos/federation/gateway/task/TaskConfiguration.java

index be4790e..f031989 100644 (file)
@@ -27,6 +27,7 @@ Version 1.18.1, 2018-09-05
 
 * Simplified catalog solutions lookup
 * Fix 'self' peer not found (ACUMS-1694)
+* Fix task scheduler initialization (ACUMS-1690)
 * Fix solution tag handling
 * Move solution and revision updates to service interface
 
index 1721abd..fda8863 100644 (file)
@@ -41,7 +41,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.core.env.Environment;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.scheduling.TaskScheduler;
 import org.springframework.stereotype.Component;
 
 import com.google.common.collect.HashBasedTable;
@@ -59,41 +59,23 @@ public class PeerSubscriptionTaskScheduler {
 
        @Autowired
        private Environment env;
-
        @Autowired
        private PeerService peerService;
-
        @Autowired
        private PeerSubscriptionService peerSubscriptionService;
-
        @Autowired
        private ApplicationContext appCtx;
+       @Autowired
+       private TaskScheduler taskScheduler = null;
 
        private Table<String, Long, PeerTaskHandler> peersSubsTask = HashBasedTable.create();
-       private ThreadPoolTaskScheduler threadPoolTaskScheduler = null;
-
-
-       @PostConstruct
-       public void initScheduler() {
-
-               String name = env.getProperty("federation.instance.name") + "-" + env.getProperty("federation.instance")
-                               + "-taskscheduler";
-
-               if (this.threadPoolTaskScheduler == null) {
-                       log.debug(EELFLoggerDelegate.debugLogger, "creating task scheduler");
-                       this.threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
-                       this.threadPoolTaskScheduler.setPoolSize(20);// Make it configurable later
-                       this.threadPoolTaskScheduler.setBeanName(name);
-                       this.threadPoolTaskScheduler.initialize();
-               }
-       }
 
        @PreDestroy
        public void cleanUpTasks() {
                log.debug(EELFLoggerDelegate.debugLogger, "cleanUpTasks");
                try {
                        log.debug(EELFLoggerDelegate.debugLogger, "cleanUpTasks: " + this.peersSubsTask.size() + " tasks");
-                       this.threadPoolTaskScheduler.shutdown();
+                       //this.taskScheduler.shutdown();
 
                }
                catch (Exception e) {
@@ -238,11 +220,11 @@ public class PeerSubscriptionTaskScheduler {
        
                        this.task = (PeerSubscriptionTask) PeerSubscriptionTaskScheduler.this.appCtx.getBean("peerSubscriptionTask");
                        if (refreshInterval.longValue() == 0) {
-                               this.future = PeerSubscriptionTaskScheduler.this.threadPoolTaskScheduler
+                               this.future = PeerSubscriptionTaskScheduler.this.taskScheduler
                                                                                                .schedule(this.task.handle(thePeer, theSub), new Date(System.currentTimeMillis() + 5000));
                        }
                        else {
-                               this.future = PeerSubscriptionTaskScheduler.this.threadPoolTaskScheduler
+                               this.future = PeerSubscriptionTaskScheduler.this.taskScheduler
                                                                                                .scheduleAtFixedRate(this.task.handle(thePeer, theSub), 1000 * refreshInterval.longValue() );
                        }
                        return this;
@@ -250,7 +232,7 @@ public class PeerSubscriptionTaskScheduler {
                
                public synchronized PeerTaskHandler runTask(MLPPeer thePeer, MLPPeerSubscription theSub) {
                        this.task = (PeerSubscriptionTask) PeerSubscriptionTaskScheduler.this.appCtx.getBean("peerSubscriptionTask");
-                       this.future = PeerSubscriptionTaskScheduler.this.threadPoolTaskScheduler
+                       this.future = PeerSubscriptionTaskScheduler.this.taskScheduler
                                                                                                .schedule(this.task.handle(thePeer, theSub), new Date(System.currentTimeMillis() + 5000));
                        return this;
                }
index 64ba662..75f1c20 100644 (file)
 
 package org.acumos.federation.gateway.task;
 
+import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Scope;
 import org.springframework.scheduling.TaskScheduler;
-import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
 
@@ -36,15 +37,25 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @Configuration
 @EnableScheduling
 @EnableAutoConfiguration
-//@ConfigurationProperties(prefix = "task", ignoreInvalidFields = true)
+@ConfigurationProperties(prefix = "task")
 public class TaskConfiguration {
 
+       private int poolSize = 20;
+
        public TaskConfiguration() {
        }
 
+       public void setPoolSize(int thePoolSize) {
+               this.poolSize = thePoolSize;
+       }
+
        @Bean
        public TaskScheduler taskScheduler() {
-    return new ConcurrentTaskScheduler();
+               ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
+               taskScheduler.setPoolSize(this.poolSize);
+               taskScheduler.setBeanName("gatewayPeerTaskScheduler");
+               taskScheduler.initialize();
+               return taskScheduler;
        }
 
        /**