Fix xacml pdp registration issue
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / startstop / XacmlPdpActivator.java
index 9695c7b..4db11d0 100644 (file)
@@ -38,6 +38,7 @@ import org.onap.policy.pdpx.main.PolicyXacmlPdpRuntimeException;
 import org.onap.policy.pdpx.main.comm.XacmlPdpMessage;
 import org.onap.policy.pdpx.main.comm.XacmlPdpPapRegistration;
 import org.onap.policy.pdpx.main.comm.listeners.XacmlPdpStateChangeListener;
+import org.onap.policy.pdpx.main.comm.listeners.XacmlPdpUpdateListener;
 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
 import org.onap.policy.pdpx.main.rest.XacmlPdpRestServer;
 import org.slf4j.Logger;
@@ -65,16 +66,20 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
 
     /**
      * Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then
-     * dispatches them to {@link #pdpUpdateListener}.
+     * dispatches them to appropriate listener.
      */
     private final MessageTypeDispatcher msgDispatcher;
 
     /**
-     * Listens for {@link PdpUpdate} messages and then routes them to the listener associated with the
-     * ID of the originating request.
+     * Listens for {@link PdpStateChange} messages from the PAP.
      */
     private final XacmlPdpStateChangeListener pdpStateChangeListener;
 
+    /**
+     * Listens for {@link PdpUpdate} messages from the PAP.
+     */
+    private final XacmlPdpUpdateListener pdpUpdateListener;
+
     /**
      * The current activator.
      */
@@ -93,16 +98,19 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
      * @param topicProperties properties used to configure the topics
      */
     public XacmlPdpActivator(final XacmlPdpParameterGroup xacmlPdpParameterGroup, Properties topicProperties) {
+        LOGGER.info("Activator initializing using {} and {}", xacmlPdpParameterGroup, topicProperties);
+
         TopicEndpoint.manager.addTopicSinks(topicProperties);
         TopicEndpoint.manager.addTopicSources(topicProperties);
 
         try {
-            TopicSinkClient sinkClient = new TopicSinkClient(TOPIC);
+            final TopicSinkClient sinkClient = new TopicSinkClient(TOPIC);
+            this.message = new XacmlPdpMessage();
             this.xacmlPdpParameterGroup = xacmlPdpParameterGroup;
             this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
-            this.pdpStateChangeListener = new XacmlPdpStateChangeListener(sinkClient);
+            this.pdpStateChangeListener = new XacmlPdpStateChangeListener(sinkClient, message);
+            this.pdpUpdateListener = new XacmlPdpUpdateListener(sinkClient, message);
             this.register = new XacmlPdpPapRegistration(sinkClient);
-            this.message = new XacmlPdpMessage();
         } catch (RuntimeException | TopicSinkClientException e) {
             throw new PolicyXacmlPdpRuntimeException(e.getMessage(), e);
         }
@@ -113,10 +121,14 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
         addAction("XACML PDP parameters", () -> ParameterService.register(xacmlPdpParameterGroup),
             () -> ParameterService.deregister(xacmlPdpParameterGroup.getName()));
 
-        addAction("Request ID Dispatcher",
+        addAction("PdpStateChange Dispatcher",
             () -> msgDispatcher.register(PdpMessageType.PDP_STATE_CHANGE.name(), this.pdpStateChangeListener),
             () -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name()));
 
+        addAction("PdpUpdate Dispatcher",
+            () -> msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(), this.pdpUpdateListener),
+            () -> msgDispatcher.unregister(PdpMessageType.PDP_UPDATE.name()));
+
         addAction("Message Dispatcher",
             () -> registerMsgDispatcher(),
             () -> unregisterMsgDispatcher());
@@ -142,10 +154,10 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
 
         addAction("Initial Registration with PAP",
             () -> {
-                register.pdpRegistration(message.formatStatusMessage(PdpState.PASSIVE));
+                register.pdpRegistration(message.formatInitialStatusMessage(PdpState.PASSIVE));
             },
             () -> {
-                register.pdpRegistration(message.formatStatusMessage(PdpState.TERMINATED));
+                register.pdpRegistration(message.formatInitialStatusMessage(PdpState.TERMINATED));
             });
         // @formatter:on