*/
package org.opendaylight.controller.sal.connect.netconf;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.util.LinkedList;
import java.util.List;
private final MessageTransformer<NetconfMessage> messageTransformer;
private final RemoteDeviceId id;
private boolean passNotifications = false;
+ private NotificationFilter filter;
NotificationHandler(final RemoteDeviceHandler<?> salFacade, final MessageTransformer<NetconfMessage> messageTransformer, final RemoteDeviceId id) {
this.salFacade = Preconditions.checkNotNull(salFacade);
passNotifications = true;
for (final NetconfMessage cachedNotification : queue) {
- passNotification(messageTransformer.toNotification(cachedNotification));
+ final CompositeNode parsedNotification = messageTransformer.toNotification(cachedNotification);
+ // TODO possible race condition here, because this exception is thrown occasionally
+ Preconditions.checkNotNull(parsedNotification, "Unable to parse received notification %s", cachedNotification);
+ passNotification(parsedNotification);
}
queue.clear();
queue.add(notification);
}
- private void passNotification(final CompositeNode parsedNotification) {
+ private synchronized void passNotification(final CompositeNode parsedNotification) {
logger.debug("{}: Forwarding notification {}", id, parsedNotification);
- Preconditions.checkNotNull(parsedNotification);
- salFacade.onNotification(parsedNotification);
+
+ if(filter == null || filter.filterNotification(parsedNotification).isPresent()) {
+ salFacade.onNotification(parsedNotification);
+ }
+ }
+
+ synchronized void addNotificationFilter(final NotificationFilter filter) {
+ this.filter = filter;
+ }
+
+ static interface NotificationFilter {
+
+ Optional<CompositeNode> filterNotification(CompositeNode notification);
}
}