* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.sal.connect.netconf.sal;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import java.util.Collection;
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class NetconfDeviceNotificationService implements DOMNotificationService {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceNotificationService.class);
+
private final Multimap<SchemaPath, DOMNotificationListener> listeners = HashMultimap.create();
// Notification publish is very simple and hijacks the thread of the caller
// TODO shouldnt we reuse the implementation for notification router from sal-broker-impl ?
+ @SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void publishNotification(final DOMNotification notification) {
for (final DOMNotificationListener domNotificationListener : listeners.get(notification.getType())) {
- domNotificationListener.onNotification(notification);
+ try {
+ domNotificationListener.onNotification(notification);
+ } catch (final Exception e) {
+ LOG.warn("Listener {} threw an uncaught exception during processing notification {}",
+ domNotificationListener, notification, e);
+ }
}
}
@Override
- public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(@Nonnull final T listener, @Nonnull final Collection<SchemaPath> types) {
+ public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
+ @Nonnull final T listener, @Nonnull final Collection<SchemaPath> types) {
for (final SchemaPath type : types) {
listeners.put(type, listener);
}
- return new ListenerRegistration<T>() {
+ return new AbstractListenerRegistration<T>(listener) {
@Override
- public void close() {
+ protected void removeRegistration() {
for (final SchemaPath type : types) {
listeners.remove(type, listener);
}
}
-
- @Override
- public T getInstance() {
- return listener;
- }
};
}
@Override
- public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(@Nonnull final T listener, final SchemaPath... types) {
+ public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
+ @Nonnull final T listener, final SchemaPath... types) {
return registerNotificationListener(listener, Lists.newArrayList(types));
}
}