Don't use NotificationListener (ServiceHandler) 19/108119/12
authorMatej Sramcik <matej.sramcik@pantheon.tech>
Thu, 28 Sep 2023 12:26:13 +0000 (14:26 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Thu, 12 Oct 2023 07:44:33 +0000 (07:44 +0000)
Don't use NotificationListener in ServiceHandlerListener.
This is a part of NotificationListener to Listener<?> migration.

JIRA: TRNSPRTPCE-756
Change-Id: Id67a411d17715cb9c9a3cf7127a058d3c742681a
Signed-off-by: Matej Sramcik <matej.sramcik@pantheon.tech>
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetworkModelProvider.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/listeners/ServiceHandlerListener.java

index d1ef447cb756fc213f5448b6426428917c9710a7..4158ab91b5dad66d318c2a8ec3fd375771cfc898 100644 (file)
@@ -25,9 +25,7 @@ import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
 import org.opendaylight.transportpce.networkmodel.util.TpceNetwork;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.service.component.annotations.Activate;
@@ -50,7 +48,7 @@ public class NetworkModelProvider {
     private final NetConfTopologyListener topologyListener;
     private List<Registration> listeners;
     private TpceNetwork tpceNetwork;
-    private ListenerRegistration<TransportpceServicehandlerListener> serviceHandlerListenerRegistration;
+    private Registration serviceHandlerListenerRegistration;
     private NotificationService notificationService;
     private FrequenciesService frequenciesService;
     private PortMappingListener portMappingListener;
@@ -88,8 +86,8 @@ public class NetworkModelProvider {
                 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener));
         listeners.add(dataBroker.registerDataTreeChangeListener(
                 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, MAPPING_II), portMappingListener));
-        TransportpceServicehandlerListener serviceHandlerListner = new ServiceHandlerListener(frequenciesService);
-        serviceHandlerListenerRegistration = notificationService.registerNotificationListener(serviceHandlerListner);
+        serviceHandlerListenerRegistration = notificationService.registerCompositeListener(
+            new ServiceHandlerListener(frequenciesService).getCompositeListener());
     }
 
         /**
index 2c2bd09588b9436f7fde91c214da7b11a3ddd5cb..1f5c6b0f66f9aa622fa511aeac9f80cccd3f0ae9 100644 (file)
@@ -8,24 +8,30 @@
 
 package org.opendaylight.transportpce.networkmodel.listeners;
 
+import java.util.Set;
+import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
 import org.opendaylight.transportpce.networkmodel.service.FrequenciesService;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ServiceHandlerListener implements TransportpceServicehandlerListener {
+public class ServiceHandlerListener {
     private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerListener.class);
     private final FrequenciesService service;
 
+
     public ServiceHandlerListener(FrequenciesService service) {
         LOG.info("Init service handler listener for network");
         this.service = service;
     }
 
-    @Override
+    public CompositeListener getCompositeListener() {
+        return new CompositeListener(Set.of(
+            new CompositeListener.Component<>(ServiceRpcResultSh.class, this::onServiceRpcResultSh)));
+    }
+
     public void onServiceRpcResultSh(ServiceRpcResultSh notification) {
         if (notification.getStatus() != RpcStatusEx.Successful) {
             LOG.info("RpcStatusEx of notification not equals successful. Nothing to do for notification {}",