Changes for Checkstyle 8.32
[policy/models.git] / models-sim / policy-models-sim-pdp / src / main / java / org / onap / policy / models / sim / pdp / PdpSimulatorActivator.java
index be396de..430b896 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.models.sim.pdp;
 
 import java.util.List;
-import java.util.Properties;
-
+import java.util.Random;
 import lombok.Getter;
 import lombok.Setter;
-
-
-import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.event.comm.TopicSink;
 import org.onap.policy.common.endpoints.event.comm.TopicSource;
 import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
@@ -54,10 +52,16 @@ public class PdpSimulatorActivator {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PdpSimulatorActivator.class);
     private final PdpSimulatorParameterGroup pdpSimulatorParameterGroup;
-    private List<TopicSink> topicSinks;// topics to which pdp sends pdp status
+    private List<TopicSink> topicSinks; // topics to which pdp sends pdp status
     private List<TopicSource> topicSources; // topics to which pdp listens to for messages from pap.
     private static final String[] MSG_TYPE_NAMES = { "messageName" };
 
+    /*
+     * This simulator is only used for testing. Consequently, it is safe to use a simple
+     * random number generator, thus the sonar is disabled.
+     */
+    private static final Random RANDOM = new Random();      // NOSONAR
+
     /**
      * Listens for messages on the topic, decodes them into a message, and then dispatches them.
      */
@@ -77,17 +81,17 @@ public class PdpSimulatorActivator {
      * Instantiate the activator for onappf PDP-A.
      *
      * @param pdpSimulatorParameterGroup the parameters for the onappf PDP-A service
-     * @param topicProperties properties used to configure the topics
      */
-    public PdpSimulatorActivator(final PdpSimulatorParameterGroup pdpSimulatorParameterGroup,
-            final Properties topicProperties) {
+    public PdpSimulatorActivator(final PdpSimulatorParameterGroup pdpSimulatorParameterGroup) {
 
-        topicSinks = TopicEndpoint.manager.addTopicSinks(topicProperties);
-        topicSources = TopicEndpoint.manager.addTopicSources(topicProperties);
+        topicSinks = TopicEndpointManager.getManager()
+                        .addTopicSinks(pdpSimulatorParameterGroup.getTopicParameterGroup().getTopicSinks());
+        topicSources = TopicEndpointManager.getManager()
+                        .addTopicSources(pdpSimulatorParameterGroup.getTopicParameterGroup().getTopicSources());
 
-        final int random = (int) (Math.random() * 1000);
+        final int random = RANDOM.nextInt();
         final String instanceId = "pdp_" + random;
-        LOGGER.debug("PdpSimulatorActivator initializing with instance id:" + instanceId);
+        LOGGER.debug("PdpSimulatorActivator initializing with instance id: {}", instanceId);
         try {
             this.pdpSimulatorParameterGroup = pdpSimulatorParameterGroup;
             this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
@@ -100,8 +104,8 @@ public class PdpSimulatorActivator {
         // @formatter:off
         this.manager = new ServiceManager()
             .addAction("topics",
-                () -> TopicEndpoint.manager.start(),
-                () -> TopicEndpoint.manager.shutdown())
+                TopicEndpointManager.getManager()::start,
+                TopicEndpointManager.getManager()::shutdown)
             .addAction("set alive",
                 () -> setAlive(true),
                 () -> setAlive(false))
@@ -117,7 +121,7 @@ public class PdpSimulatorActivator {
                 () -> Registry.register(PdpSimulatorConstants.REG_PDP_STATUS_PUBLISHER,
                         new PdpStatusPublisher(topicSinks,
                                 pdpSimulatorParameterGroup.getPdpStatusParameters().getTimeIntervalMs())),
-                () -> stopAndRemovePdpStatusPublisher())
+                this::stopAndRemovePdpStatusPublisher)
             .addAction("Register pdp update listener",
                 () -> msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(), pdpUpdateListener),
                 () -> msgDispatcher.unregister(PdpMessageType.PDP_UPDATE.name()))
@@ -125,8 +129,8 @@ public class PdpSimulatorActivator {
                 () -> msgDispatcher.register(PdpMessageType.PDP_STATE_CHANGE.name(), pdpStateChangeListener),
                 () -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name()))
             .addAction("Message Dispatcher",
-                () -> registerMsgDispatcher(),
-                () -> unregisterMsgDispatcher());
+                this::registerMsgDispatcher,
+                this::unregisterMsgDispatcher);
 
         // @formatter:on
     }