Search in sources :

Example 1 with AbstractListenerRegistration

use of org.opendaylight.yangtools.concepts.AbstractListenerRegistration in project controller by opendaylight.

the class HeliumNotificationProviderServiceWithInterestListeners method registerNotificationListener.

@Override
public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(final Class<T> type, final NotificationListener<T> listener) {
    final FunctionalNotificationListenerAdapter<T> adapter = new FunctionalNotificationListenerAdapter<>(codec, type, listener);
    final SchemaPath domType = SchemaPath.create(true, BindingReflections.findQName(type));
    final ListenerRegistration<?> domReg = domService.registerNotificationListener(adapter, domType);
    return new AbstractListenerRegistration<NotificationListener<T>>(listener) {

        @Override
        protected void removeRegistration() {
            domReg.close();
        }
    };
}
Also used : AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath)

Example 2 with AbstractListenerRegistration

use of org.opendaylight.yangtools.concepts.AbstractListenerRegistration in project controller by opendaylight.

the class DOMNotificationRouter method registerNotificationListener.

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

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

Aggregations

AbstractListenerRegistration (org.opendaylight.yangtools.concepts.AbstractListenerRegistration)2 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)2 DOMNotificationListener (org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener)1 ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)1