From a07faa892e0b0b471a271156845ed9b980fa2269 Mon Sep 17 00:00:00 2001 From: Martin Bobak Date: Sun, 26 Apr 2015 16:00:33 +0200 Subject: [PATCH] Bug 3063 - Notification brokers does not properly scans notification listeners for implemented interfaces Change-Id: Ie3b136bd40c443191d22bfbfd0ea532b65f717c2 Signed-off-by: Martin Bobak --- .../md/sal/binding/compat/NotificationInvoker.java | 4 +++- .../impl/BindingDOMNotificationListenerAdapter.java | 4 +++- .../BackwardsCompatibleNotificationBrokerTest.java | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotificationInvoker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotificationInvoker.java index 08a147721f..cdc6315e49 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotificationInvoker.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotificationInvoker.java @@ -8,6 +8,7 @@ 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; @@ -28,7 +29,8 @@ final class NotificationInvoker implements org.opendaylight.controller.sal.bindi private NotificationInvoker(final NotificationListener listener) { delegate = listener; final Map, 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 listenerType = (Class) iface; diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java index 86822274ef..cd3220e755 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java @@ -8,6 +8,7 @@ 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; @@ -60,7 +61,8 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { public static Map createInvokerMapFor(final Class implClz) { final Map 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 listenerType = (Class) iface; diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java index 6a8dc5fde9..f43352d101 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java @@ -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 java.util.concurrent.TimeUnit; 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 NotifTestListener testNotifListener = new NotifTestListener(latch); + final NotifTestListenerChild testNotifListener = new NotifTestListenerChild(latch); final ListenerRegistration 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(); } + private static class NotifTestListenerChild extends NotifTestListener { + + public NotifTestListenerChild(final CountDownLatch latch) { + super(latch); + } + } private static class NotifTestListener implements OpendaylightMdsalListTestListener { private List receivedNotifications = new ArrayList<>(); private CountDownLatch latch; -- 2.36.6