diff options
Diffstat (limited to 'examples')
8 files changed, 21 insertions, 31 deletions
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java index ccf4539aa..60fa169dd 100644 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java @@ -69,11 +69,8 @@ public class TestApexActionListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent actionEvent) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + ThreadUtilities.sleep(100); + if (actionEvent != null) { System.out.println("Action event from engine:" + actionEvent.getName()); resultEvents.add(actionEvent); diff --git a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java index d935af5f0..968b20499 100644 --- a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java +++ b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java @@ -31,9 +31,9 @@ import java.util.List; public class AutoLearn implements Serializable { private static final long serialVersionUID = 3825970380434170754L; - private List<Double> avDiffs = null; + private transient List<Double> avDiffs = null; - private List<Long> counts = null; + private transient List<Long> counts = null; /** * Checks if the Autolearn instance is initialized. diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java index cb7e3c824..c29a3cb6e 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java @@ -38,6 +38,7 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.ApexEngine; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -148,7 +149,7 @@ public class TestAnomalyDetectionTslUseCase { assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId()); triggerEvent.clear(); result.clear(); - Thread.sleep(1); + ThreadUtilities.sleep(1); apexEngine1.stop(); } @@ -215,7 +216,7 @@ public class TestAnomalyDetectionTslUseCase { result.clear(); } apexEngine1.stop(); - Thread.sleep(1000); + ThreadUtilities.sleep(1000); } /** diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java index ec7c197b7..006d3de6f 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java @@ -69,11 +69,8 @@ public class TestApexActionListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent actionEvent) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + ThreadUtilities.sleep(100); + if (actionEvent != null) { System.out.println("Action event from engine:" + actionEvent.getName()); resultEvents.add(actionEvent); diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java index 3052c31a7..10d69a457 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java @@ -38,6 +38,7 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.ApexEngine; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -146,7 +147,7 @@ public class TestAutoLearnTslUseCase { assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId()); triggerEvent.clear(); result.clear(); - Thread.sleep(1); + ThreadUtilities.sleep(10); apexEngine1.stop(); } @@ -234,12 +235,11 @@ public class TestAutoLearnTslUseCase { LOGGER.info("Iteration " + iteration + ": \tpreval\t" + prevval + "\tval\t" + val + "\tavval\t" + avval); result.clear(); - Thread.sleep(1); + ThreadUtilities.sleep(10); } apexEngine1.stop(); - Thread.sleep(1000); - + ThreadUtilities.sleep(1000); } /** diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java index 2dfd1af61..b2722fd78 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java @@ -71,11 +71,8 @@ public class TestSaleAuthListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent saleauthEvent) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + ThreadUtilities.sleep(100); + if (saleauthEvent != null) { System.out.println("SaleAuth event from engine:" + saleauthEvent.getName()); resultEvents.add(saleauthEvent); diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java index 369e6172c..bb754d99f 100644 --- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java +++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java @@ -32,6 +32,7 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; */ public class AaiAndGuardSim { private static final String BASE_URI = "http://localhost:54321/AAIAndGuardSim"; + private static final int MAX_LOOPS = 100000; private HttpServer server; /** @@ -64,13 +65,10 @@ public class AaiAndGuardSim { public static void main(final String[] args) throws Exception { final AaiAndGuardSim sim = new AaiAndGuardSim(); - while (true) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - break; - } + for (int index = 0; index < MAX_LOOPS; index++) { + ThreadUtilities.sleep(100); } + sim.tearDown(); } } diff --git a/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java b/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java index f6de1285e..78871c385 100644 --- a/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java +++ b/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java @@ -57,7 +57,7 @@ public class ApexServletListener implements ServletContextListener { final String configFileName = servletContextEvent.getServletContext().getInitParameter("config-file"); final String modelFileName = servletContextEvent.getServletContext().getInitParameter("model-file"); - LOGGER.info("Apex Servliet has been started, config-file= " + configFileName + ", model-file=" + modelFileName); + LOGGER.info("Apex Servliet has been started, config-file={}, model-file={}", configFileName, modelFileName); // Check that a configuration file have been specified if (servletContextEvent.getServletContext().getInitParameter("config-file") == null) { @@ -68,7 +68,7 @@ public class ApexServletListener implements ServletContextListener { } // Construct the Apex command line arguments - final List<String> argsList = new ArrayList<String>(); + final List<String> argsList = new ArrayList<>(); argsList.add("-config-file"); argsList.add(configFileName); |