changeset 912:f3957e7bf48c

Lookups lifecycle support in Main and GlobalConfigMain
author Devel 1
date Thu, 19 Apr 2018 12:02:09 +0200
parents 7f83606b0a27
children d1158607d5f0
files stress-tester/src/main/java/com/passus/st/CliHelper.java stress-tester/src/main/java/com/passus/st/ConverterMain.java stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java stress-tester/src/main/java/com/passus/st/Main.java stress-tester/src/main/java/com/passus/st/Main2.java stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java
diffstat 6 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/CliHelper.java	Thu Apr 19 10:52:33 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/CliHelper.java	Thu Apr 19 12:02:09 2018 +0200
@@ -156,6 +156,10 @@
 
         return client;
     }
+    
+    public void beforeExit(ConfigurationContext context) {
+        LookupsDomainConfigurator.destroy(context);
+    }
 
     public void readLookupsToContext(CommandLine cl, ConfigurationContext context) throws Exception {
         if (cl.hasOption("lf")) {
--- a/stress-tester/src/main/java/com/passus/st/ConverterMain.java	Thu Apr 19 10:52:33 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/ConverterMain.java	Thu Apr 19 12:02:09 2018 +0200
@@ -150,6 +150,7 @@
             client.join();
             eventSrc.stop();
             client.stop();
+            cliHelper.beforeExit(context);
         } catch (ParseException e) {
             System.out.println(e.getMessage());
             printHelp(options);
--- a/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java	Thu Apr 19 10:52:33 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java	Thu Apr 19 12:02:09 2018 +0200
@@ -98,6 +98,7 @@
             }
 
             testJob.stop();
+            testJobConfigurator.destroy(config, errors, context);
             logger.debug("TestJob stopped");
         } catch (ParseException e) {
             System.out.println(e.getMessage());
--- a/stress-tester/src/main/java/com/passus/st/Main.java	Thu Apr 19 10:52:33 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/Main.java	Thu Apr 19 12:02:09 2018 +0200
@@ -346,6 +346,7 @@
             collector.flush(true);
 
             printMetrics();
+            cliHelper.beforeExit(context);
         } catch (ParseException e) {
             System.out.println(e.getMessage());
             printHelp(options);
--- a/stress-tester/src/main/java/com/passus/st/Main2.java	Thu Apr 19 10:52:33 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/Main2.java	Thu Apr 19 12:02:09 2018 +0200
@@ -368,6 +368,7 @@
             collector.flush(true);
 
             printMetrics();
+            cliHelper.beforeExit(context);
         } catch (ParseException e) {
             System.out.println(e.getMessage());
             printHelp(options);
--- a/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java	Thu Apr 19 10:52:33 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java	Thu Apr 19 12:02:09 2018 +0200
@@ -10,6 +10,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
 
 @Plugin(name = LookupsDomainConfigurator.DOMAIN, category = PluginConstants.CATEGORY_DOMAIN_CONFIGURATOR)
@@ -54,6 +55,7 @@
         if (!errors.hasError()) {
             try {
                 List<Lookup> lookups = ConfigurationUtils.convertToList(rootNode, Lookup.class);
+                lookups.forEach(Lookup::start);
                 context.add(ConfigurationContextConsts.LOOKUPS, lookups);
             } catch (Exception e) {
                 throw new RuntimeException(e.getMessage(), e);
@@ -61,4 +63,14 @@
 
         }
     }
+
+    @Override
+    public void destroy(Configuration config, ConfigurationContext context) {
+        destroy(context);
+    }
+
+    public static void destroy(ConfigurationContext context) {
+        List<Lookup> lookups = (List<Lookup>) context.get(ConfigurationContextConsts.LOOKUPS, Collections.EMPTY_LIST);
+        lookups.forEach(Lookup::stop);
+    }
 }