Search in sources :

Example 1 with DOMNotificationListener

use of org.opendaylight.mdsal.dom.api.DOMNotificationListener in project mdsal by opendaylight.

the class DOMNotificationRouter method registerNotificationListener.

@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<Absolute> types) {
    final AbstractListenerRegistration<T> reg = new AbstractListenerRegistration<>(listener) {

        @Override
        protected void removeRegistration() {
            synchronized (DOMNotificationRouter.this) {
                replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, input -> input != this)));
            }
        }
    };
    if (!types.isEmpty()) {
        final Builder<Absolute, AbstractListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
        b.putAll(listeners);
        for (final Absolute t : types) {
            b.put(t, reg);
        }
        replaceListeners(b.build());
    }
    return reg;
}
Also used : AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration) DOMNotificationListener(org.opendaylight.mdsal.dom.api.DOMNotificationListener) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)

Example 2 with DOMNotificationListener

use of org.opendaylight.mdsal.dom.api.DOMNotificationListener in project netconf by opendaylight.

the class BrokerFacade method registerToListenNotification.

public void registerToListenNotification(final NotificationListenerAdapter listener) {
    if (listener.isListening()) {
        return;
    }
    final SchemaPath path = listener.getSchemaPath();
    final ListenerRegistration<DOMNotificationListener> registration = this.domNotification.registerNotificationListener(listener, Absolute.of(ImmutableList.copyOf(path.getPathFromRoot())));
    listener.setRegistration(registration);
}
Also used : DOMNotificationListener(org.opendaylight.mdsal.dom.api.DOMNotificationListener) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath)

Example 3 with DOMNotificationListener

use of org.opendaylight.mdsal.dom.api.DOMNotificationListener in project mdsal by opendaylight.

the class ForwardingDOMNotificationServiceTest method basicTest.

@Test
public void basicTest() throws Exception {
    final DOMNotificationListener domNotificationListener = mock(DOMNotificationListener.class);
    doReturn(null).when(domNotificationService).registerNotificationListener(domNotificationListener);
    this.registerNotificationListener(domNotificationListener);
    verify(domNotificationService).registerNotificationListener(domNotificationListener);
    doReturn(null).when(domNotificationService).registerNotificationListener(domNotificationListener, Collections.emptySet());
    this.registerNotificationListener(domNotificationListener, Collections.emptySet());
    verify(domNotificationService).registerNotificationListener(domNotificationListener, Collections.emptySet());
}
Also used : DOMNotificationListener(org.opendaylight.mdsal.dom.api.DOMNotificationListener) Test(org.junit.Test)

Example 4 with DOMNotificationListener

use of org.opendaylight.mdsal.dom.api.DOMNotificationListener 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

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