Migrate test-provider to CompositeListener
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestTopologyNotification.java
index d5f3d6ca4a197b832b079fdc782fbda755b94690..81532f99845da5ec880b489e0cf927f922b10cfa 100644 (file)
@@ -8,20 +8,21 @@
 package org.opendaylight.openflowplugin.test;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.Set;
 import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryListener;
+import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
+import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener.Component;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkOverutilized;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkUtilizationNormal;
+import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class OpenflowpluginTestTopologyNotification {
-
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestTopologyNotification.class);
 
-    private final TopologyEventListener topologyEventListener = new TopologyEventListener();
     private final NotificationService notificationService;
 
     public OpenflowpluginTestTopologyNotification(final NotificationService notificationService) {
@@ -30,45 +31,17 @@ public class OpenflowpluginTestTopologyNotification {
 
     public void init() {
         // For switch events
-        notificationService.registerNotificationListener(topologyEventListener);
+        notificationService.registerCompositeListener(new CompositeListener(Set.of(
+            new Component<>(LinkDiscovered.class, this::onNotification),
+            new Component<>(LinkOverutilized.class, this::onNotification),
+            new Component<>(LinkRemoved.class, this::onNotification),
+            new Component<>(LinkUtilizationNormal.class, this::onNotification))));
     }
 
-    private static final class TopologyEventListener implements FlowTopologyDiscoveryListener {
-        @Override
-        @Deprecated
-        @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
-        public void onLinkDiscovered(final LinkDiscovered notification) {
-            LOG.debug("-------------------------------------------");
-            LOG.debug("LinkDiscovered notification ........");
-            LOG.debug("-------------------------------------------");
-        }
-
-        @Override
-        @Deprecated
-        @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
-        public void onLinkOverutilized(final LinkOverutilized notification) {
-            LOG.debug("-------------------------------------------");
-            LOG.debug("LinkOverutilized notification ........");
-            LOG.debug("-------------------------------------------");
-        }
-
-        @Override
-        @Deprecated
-        @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
-        public void onLinkRemoved(final LinkRemoved notification) {
-            LOG.debug("-------------------------------------------");
-            LOG.debug("LinkRemoved notification   ........");
-            LOG.debug("-------------------------------------------");
-        }
-
-        @Override
-        @Deprecated
-        @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
-        public void onLinkUtilizationNormal(final LinkUtilizationNormal notification) {
-            LOG.debug("-------------------------------------------");
-            LOG.debug("LinkUtilizationNormal notification ........");
-            LOG.debug("-------------------------------------------");
-        }
-
+    @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
+    private void onNotification(Notification<?> notification) {
+        LOG.debug("-------------------------------------------");
+        LOG.debug("{} notification ........", notification.getClass().getSimpleName());
+        LOG.debug("-------------------------------------------");
     }
 }