Search in sources :

Example 1 with DOMNotificationSubscriptionListener

use of org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener in project mdsal by opendaylight.

the class DOMNotificationRouter method notifyListenerTypesChanged.

@SuppressWarnings("checkstyle:IllegalCatch")
private void notifyListenerTypesChanged(final Set<Absolute> typesAfter) {
    final List<? extends DOMNotificationSubscriptionListener> listenersAfter = subscriptionListeners.streamListeners().collect(ImmutableList.toImmutableList());
    executor.execute(() -> {
        for (final DOMNotificationSubscriptionListener subListener : listenersAfter) {
            try {
                subListener.onSubscriptionChanged(typesAfter);
            } catch (final Exception e) {
                LOG.warn("Uncaught exception during invoking listener {}", subListener, e);
            }
        }
    });
}
Also used : DOMNotificationSubscriptionListener(org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener)

Example 2 with DOMNotificationSubscriptionListener

use of org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener in project mdsal by opendaylight.

the class DOMNotificationRouterTest method complexTest.

@SuppressWarnings("checkstyle:IllegalCatch")
@Test
public void complexTest() throws Exception {
    final DOMNotificationSubscriptionListener domNotificationSubscriptionListener = mock(DOMNotificationSubscriptionListener.class);
    doNothing().when(domNotificationSubscriptionListener).onSubscriptionChanged(any());
    final CountDownLatch latch = new CountDownLatch(1);
    final DOMNotificationListener domNotificationListener = new TestListener(latch);
    final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1024);
    Multimap<Absolute, ?> listeners = domNotificationRouter.listeners();
    assertTrue(listeners.isEmpty());
    assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener, Absolute.of(TestModel.TEST_QNAME)));
    assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener, Absolute.of(TestModel.TEST2_QNAME)));
    listeners = domNotificationRouter.listeners();
    assertFalse(listeners.isEmpty());
    ListenerRegistry<DOMNotificationSubscriptionListener> subscriptionListeners = domNotificationRouter.subscriptionListeners();
    assertEquals(0, subscriptionListeners.streamListeners().count());
    assertNotNull(domNotificationRouter.registerSubscriptionListener(domNotificationSubscriptionListener));
    subscriptionListeners = domNotificationRouter.subscriptionListeners();
    assertSame(domNotificationSubscriptionListener, subscriptionListeners.streamListeners().findAny().orElseThrow());
    final DOMNotification domNotification = mock(DOMNotification.class);
    doReturn("test").when(domNotification).toString();
    doReturn(Absolute.of(TestModel.TEST_QNAME)).when(domNotification).getType();
    doReturn(TEST_CHILD).when(domNotification).getBody();
    assertNotNull(domNotificationRouter.offerNotification(domNotification));
    try {
        assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
        assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
    } catch (Exception e) {
        // FIXME: what is the point here?!
        assertTrue(e instanceof UnsupportedOperationException);
    }
    assertNotNull(domNotificationRouter.putNotification(domNotification));
}
Also used : DOMNotificationListener(org.opendaylight.mdsal.dom.api.DOMNotificationListener) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) DOMNotificationSubscriptionListener(org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener) CountDownLatch(java.util.concurrent.CountDownLatch) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Test(org.junit.Test)

Aggregations

DOMNotificationSubscriptionListener (org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)1 DOMNotificationListener (org.opendaylight.mdsal.dom.api.DOMNotificationListener)1 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)1