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;
}
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);
}
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());
}
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));
}
Aggregations