Search in sources :

Example 1 with NotificationListener

use of org.opendaylight.yangtools.yang.binding.NotificationListener in project controller by opendaylight.

the class BindingDOMNotificationListenerAdapter method createInvokerMapFor.

public static Map<SchemaPath, NotificationListenerInvoker> createInvokerMapFor(final Class<? extends NotificationListener> implClz) {
    final Map<SchemaPath, NotificationListenerInvoker> builder = new HashMap<>();
    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;
            final NotificationListenerInvoker invoker = NotificationListenerInvoker.from(listenerType);
            for (final SchemaPath path : getNotificationTypes(listenerType)) {
                builder.put(path, invoker);
            }
        }
    }
    return ImmutableMap.copyOf(builder);
}
Also used : SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) HashMap(java.util.HashMap) NotificationListenerInvoker(org.opendaylight.yangtools.yang.binding.util.NotificationListenerInvoker) DOMNotificationListener(org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener) NotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener)

Example 2 with NotificationListener

use of org.opendaylight.yangtools.yang.binding.NotificationListener in project controller by opendaylight.

the class BackwardsCompatibleNotificationBrokerTest method testNotifSubscriptionForwarded.

@Test
public void testNotifSubscriptionForwarded() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final TwoLevelListChanged testData = createTestData();
    final NotifTestListenerChild testNotifListener = new NotifTestListenerChild(latch);
    final ListenerRegistration<NotificationListener> listenerRegistration = notificationProviderService.registerNotificationListener(testNotifListener);
    notificationProviderService.publish(testData);
    latch.await(500L, TimeUnit.MILLISECONDS);
    assertTrue(testNotifListener.getReceivedNotifications().size() == 1);
    assertEquals(testData, testNotifListener.getReceivedNotifications().get(0));
    listenerRegistration.close();
}
Also used : TwoLevelListChanged(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged) CountDownLatch(java.util.concurrent.CountDownLatch) NotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener) Test(org.junit.Test) AbstractNotificationBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest)

Aggregations

NotificationListener (org.opendaylight.yangtools.yang.binding.NotificationListener)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 AbstractNotificationBrokerTest (org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest)1 DOMNotificationListener (org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener)1 TwoLevelListChanged (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged)1 NotificationListenerInvoker (org.opendaylight.yangtools.yang.binding.util.NotificationListenerInvoker)1 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)1