diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2019-03-02 05:13:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-02 05:13:27 +0000 |
commit | 01cf3b35295bfee2c9b27d97d1c6a53f6872a350 (patch) | |
tree | 64b1c6dba88fc147d62c16cc227c200bdf8572b3 /src/main/java/org/onap/dcae/VesApplication.java | |
parent | 356715b370e80e7f9337b916793404a14bc3d658 (diff) | |
parent | e7360f7e7e77672b885087af68a3d96ebbc8c313 (diff) |
Merge "Restart Issue"
Diffstat (limited to 'src/main/java/org/onap/dcae/VesApplication.java')
-rw-r--r-- | src/main/java/org/onap/dcae/VesApplication.java | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/src/main/java/org/onap/dcae/VesApplication.java b/src/main/java/org/onap/dcae/VesApplication.java index 2dcd8fa8..d658b4aa 100644 --- a/src/main/java/org/onap/dcae/VesApplication.java +++ b/src/main/java/org/onap/dcae/VesApplication.java @@ -25,6 +25,7 @@ import java.nio.file.Paths; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.json.JSONObject; @@ -41,6 +42,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Lazy; @@ -54,47 +56,77 @@ public class VesApplication { private static final int MAX_THREADS = 20; public static LinkedBlockingQueue<JSONObject> fProcessingInputQueue; private static ApplicationSettings properties; + private static ConfigurableApplicationContext context; + private static ConfigLoader configLoader; + private static EventProcessor eventProcessor; + private static ScheduledThreadPoolExecutor scheduledThreadPoolExecutor; + private static SpringApplication app; + private static EventPublisher eventPublisher; + private static ScheduledFuture<?> scheduleFeatures; + private static ExecutorService executor; public static void main(String[] args) { - SpringApplication app = new SpringApplication(VesApplication.class); + app = new SpringApplication(VesApplication.class); + properties = new ApplicationSettings(args, CLIUtils::processCmdLine); + scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); + init(); + app.setAddCommandLineProperties(true); + context = app.run(); + configLoader.updateConfig(); - properties = new ApplicationSettings(args, CLIUtils::processCmdLine); + } + + public static void restartApplication() { + Thread thread = new Thread(() -> { + context.close(); + properties.reloadProperties(); + scheduleFeatures.cancel(true); + init(); + context = SpringApplication.run(VesApplication.class); + }); + thread.setDaemon(false); + thread.start(); + } + + private static void init() { + fProcessingInputQueue = new LinkedBlockingQueue<>(properties.maximumAllowedQueuedEvents()); + createConfigLoader(); + createSchedulePoolExecutor(); + createExecutors(); + } - fProcessingInputQueue = new LinkedBlockingQueue<>(properties.maximumAllowedQueuedEvents()); + private static void createExecutors() { + eventPublisher = EventPublisher.createPublisher(oplog, getDmapConfig()); + eventProcessor = new EventProcessor(new EventSender(eventPublisher, properties)); - EventPublisher publisher = EventPublisher.createPublisher(oplog, - DMaaPConfigurationParser - .parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())) - .get()); - spawnDynamicConfigUpdateThread(publisher, properties); - EventProcessor ep = new EventProcessor( - new EventSender(EventPublisher.createPublisher(oplog, getDmapConfig()), properties)); + executor = Executors.newFixedThreadPool(MAX_THREADS); + for (int i = 0; i < MAX_THREADS; ++i) { + executor.execute(eventProcessor); + } + } - ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS); - for (int i = 0; i < MAX_THREADS; ++i) { - executor.execute(ep); - } + private static void createSchedulePoolExecutor() { + scheduleFeatures = scheduledThreadPoolExecutor.scheduleAtFixedRate(configLoader::updateConfig, + properties.configurationUpdateFrequency(), + properties.configurationUpdateFrequency(), + TimeUnit.MINUTES); + } - app.setAddCommandLineProperties(true); - app.run(); + private static void createConfigLoader() { + configLoader = ConfigLoader.create(getEventPublisher()::reconfigure, + Paths.get(properties.dMaaPConfigurationFileLocation()), + properties.configurationFileLocation()); } - private static void spawnDynamicConfigUpdateThread(EventPublisher eventPublisher, ApplicationSettings properties) { - ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); - ConfigLoader configLoader = ConfigLoader - .create(eventPublisher::reconfigure, - Paths.get(properties.dMaaPConfigurationFileLocation()), - properties.configurationFileLocation()); - scheduledThreadPoolExecutor - .scheduleAtFixedRate(configLoader::updateConfig, - properties.configurationUpdateFrequency(), - properties.configurationUpdateFrequency(), - TimeUnit.MINUTES); + + private static EventPublisher getEventPublisher() { + return EventPublisher.createPublisher(oplog, DMaaPConfigurationParser + .parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())).get()); } private static Map<String, PublisherConfig> getDmapConfig() { - return DMaaPConfigurationParser. - parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())).get(); + return DMaaPConfigurationParser + .parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())).get(); } @Bean |