Migrate topology-lldp-discovery to simplified Listener 77/102677/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Oct 2022 18:06:54 +0000 (20:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Oct 2022 18:06:54 +0000 (20:06 +0200)
Rather than using the composite notification service, use the simpler
NotificationService.Listener.

Change-Id: Icdd28937645c74c5a5a268103409790473937c55
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
applications/topology-lldp-discovery/src/main/java/org/opendaylight/openflowplugin/applications/topology/lldp/LLDPActivator.java
applications/topology-lldp-discovery/src/main/java/org/opendaylight/openflowplugin/applications/topology/lldp/LLDPDiscoveryListener.java

index 5d6f82dfa9f472500ed682ef5182b7052ff85059..4221f3427b005287a2ed32f5998411e9f36e5b2f 100644 (file)
@@ -12,9 +12,9 @@ import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.config.rev160511.TopologyLldpDiscoveryConfig;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,7 +24,7 @@ public class LLDPActivator implements AutoCloseable {
 
     private static String lldpSecureKey;
 
-    private final ListenerRegistration<NotificationListener> lldpNotificationRegistration;
+    private final Registration lldpNotificationRegistration;
 
     @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
     @Inject
@@ -35,7 +35,8 @@ public class LLDPActivator implements AutoCloseable {
 
         LOG.info("Starting LLDPActivator with lldpSecureKey: {}", lldpSecureKey);
 
-        lldpNotificationRegistration = notificationService.registerNotificationListener(lldpDiscoveryListener);
+        lldpNotificationRegistration =
+            notificationService.registerListener(PacketReceived.class, lldpDiscoveryListener);
 
         LOG.info("LLDPDiscoveryListener started.");
     }
index 2766e169eefd77445d8f5e6cbb7814453f99a8fe..bde92720cd4eb73a484a5b84309a54beb3a42ba0 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.applications.topology.lldp;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
 import org.opendaylight.openflowplugin.applications.topology.lldp.utils.LLDPDiscoveryUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
@@ -17,13 +18,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public class LLDPDiscoveryListener implements PacketProcessingListener {
+public class LLDPDiscoveryListener implements Listener<PacketReceived> {
     private static final Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryListener.class);
 
     private final LLDPLinkAger lldpLinkAger;
@@ -35,11 +35,11 @@ public class LLDPDiscoveryListener implements PacketProcessingListener {
             final LLDPLinkAger lldpLinkAger, final EntityOwnershipService entityOwnershipService) {
         this.notificationService = notificationService;
         this.lldpLinkAger = lldpLinkAger;
-        this.eos = entityOwnershipService;
+        eos = entityOwnershipService;
     }
 
     @Override
-    public void onPacketReceived(final PacketReceived lldp) {
+    public void onNotification(final PacketReceived lldp) {
         NodeConnectorRef src = LLDPDiscoveryUtils.lldpToNodeConnectorRef(lldp.getPayload(), true);
         if (src != null) {
             final NodeKey nodeKey = lldp.getIngress().getValue().firstKeyOf(Node.class);
@@ -51,7 +51,7 @@ public class LLDPDiscoveryListener implements PacketProcessingListener {
                 final LinkDiscovered ld = ldb.build();
                 final boolean linkWasPresent = lldpLinkAger.isLinkPresent(ld);
                 lldpLinkAger.put(ld);
-                if (LLDPDiscoveryUtils.isEntityOwned(this.eos, nodeKey.getId().getValue())) {
+                if (LLDPDiscoveryUtils.isEntityOwned(eos, nodeKey.getId().getValue())) {
                     if (linkWasPresent) {
                         LOG.trace("Link {} already present in the cache, skip publishing the notification.", ld);
                     } else {