Bug 3063 - Notification brokers does not properly scans notification listeners for... 05/19105/1
authorMartin Bobak <mbobak@cisco.com>
Sun, 26 Apr 2015 14:00:33 +0000 (16:00 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Sun, 26 Apr 2015 14:37:43 +0000 (14:37 +0000)
Change-Id: Ie3b136bd40c443191d22bfbfd0ea532b65f717c2
Signed-off-by: Martin Bobak <mbobak@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotificationInvoker.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java

index 08a147721f71ccad7569a7e61fce07cdc0bad17e..cdc6315e4930c7433f11e3fe8de3e3c7efea100a 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.md.sal.binding.compat;
 
 import com.google.common.collect.ImmutableMap;
 package org.opendaylight.controller.md.sal.binding.compat;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.reflect.TypeToken;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -28,7 +29,8 @@ final class NotificationInvoker implements org.opendaylight.controller.sal.bindi
     private NotificationInvoker(final NotificationListener listener) {
         delegate = listener;
         final Map<Class<? extends Notification>, InvokerContext> builder = new HashMap<>();
     private NotificationInvoker(final NotificationListener listener) {
         delegate = listener;
         final Map<Class<? extends Notification>, InvokerContext> builder = new HashMap<>();
-        for(final Class<?> iface : listener.getClass().getInterfaces()) {
+        for(final TypeToken<?> ifaceToken : TypeToken.of(listener.getClass()).getTypes().interfaces()) {
+            Class<?> iface = ifaceToken.getRawType();
             if(NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
                 @SuppressWarnings("unchecked")
                 final Class<? extends NotificationListener> listenerType = (Class<? extends NotificationListener>) iface;
             if(NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
                 @SuppressWarnings("unchecked")
                 final Class<? extends NotificationListener> listenerType = (Class<? extends NotificationListener>) iface;
index 86822274efb2d6dfa9965e9e7b33863bec141164..cd3220e755306d2e379bfff647e38c2dcd34f042 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.md.sal.binding.impl;
 
 import com.google.common.collect.ImmutableMap;
 package org.opendaylight.controller.md.sal.binding.impl;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.reflect.TypeToken;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -60,7 +61,8 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener {
 
     public static Map<SchemaPath, NotificationListenerInvoker> createInvokerMapFor(final Class<? extends NotificationListener> implClz) {
         final Map<SchemaPath, NotificationListenerInvoker> builder = new HashMap<>();
 
     public static Map<SchemaPath, NotificationListenerInvoker> createInvokerMapFor(final Class<? extends NotificationListener> implClz) {
         final Map<SchemaPath, NotificationListenerInvoker> builder = new HashMap<>();
-        for(final Class<?> iface : implClz.getInterfaces()) {
+        for(final TypeToken<?> ifaceToken : TypeToken.of(implClz).getTypes().interfaces()) {
+            Class<?> iface = ifaceToken.getRawType();
             if(NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
                 @SuppressWarnings("unchecked")
                 final Class<? extends NotificationListener> listenerType = (Class<? extends NotificationListener>) iface;
             if(NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
                 @SuppressWarnings("unchecked")
                 final Class<? extends NotificationListener> listenerType = (Class<? extends NotificationListener>) iface;
index 6a8dc5fde960400ea07aa68e44b0a23375d6df30..f43352d1018e3345dbbd7188d5fb4947b7bb630a 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.md.sal.binding.impl.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
 
 import com.google.common.collect.ImmutableList;
 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
 
 import com.google.common.collect.ImmutableList;
@@ -52,17 +53,23 @@ public class BackwardsCompatibleNotificationBrokerTest extends AbstractNotificat
         final CountDownLatch latch = new CountDownLatch(1);
         final TwoLevelListChanged testData = createTestData();
 
         final CountDownLatch latch = new CountDownLatch(1);
         final TwoLevelListChanged testData = createTestData();
 
-        final NotifTestListener testNotifListener = new NotifTestListener(latch);
+        final NotifTestListenerChild testNotifListener = new NotifTestListenerChild(latch);
         final ListenerRegistration<NotificationListener> listenerRegistration =
                 notificationProviderService.registerNotificationListener(testNotifListener);
         notificationProviderService.publish(testData);
 
         final ListenerRegistration<NotificationListener> listenerRegistration =
                 notificationProviderService.registerNotificationListener(testNotifListener);
         notificationProviderService.publish(testData);
 
-        latch.await();
+        latch.await(500L, TimeUnit.MILLISECONDS);
         assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
         assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
         listenerRegistration.close();
     }
 
         assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
         assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
         listenerRegistration.close();
     }
 
+    private static class NotifTestListenerChild extends  NotifTestListener {
+
+        public NotifTestListenerChild(final CountDownLatch latch) {
+            super(latch);
+        }
+    }
     private static class NotifTestListener implements OpendaylightMdsalListTestListener {
         private List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
         private CountDownLatch latch;
     private static class NotifTestListener implements OpendaylightMdsalListTestListener {
         private List<TwoLevelListChanged> receivedNotifications = new ArrayList<>();
         private CountDownLatch latch;