*/
package org.opendaylight.netconf.sal.connect.netconf;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import java.util.LinkedList;
import java.util.List;
-import java.util.Optional;
+import java.util.function.Predicate;
import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
+import org.opendaylight.netconf.sal.connect.api.NotificationTransformer;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.slf4j.Logger;
* Handles incoming notifications. Either caches them(until onRemoteSchemaUp is called) or passes to sal Facade.
*/
final class NotificationHandler {
-
private static final Logger LOG = LoggerFactory.getLogger(NotificationHandler.class);
- private final RemoteDeviceHandler<?> salFacade;
+ private final RemoteDeviceHandler salFacade;
+ // FIXME: better implementation?
private final List<NetconfMessage> queue = new LinkedList<>();
private final RemoteDeviceId id;
- private boolean passNotifications = false;
+ private boolean passNotifications = false;
private NotificationFilter filter;
- private MessageTransformer<NetconfMessage> messageTransformer;
+ private NotificationTransformer messageTransformer;
- NotificationHandler(final RemoteDeviceHandler<?> salFacade, final RemoteDeviceId id) {
- this.salFacade = Preconditions.checkNotNull(salFacade);
- this.id = Preconditions.checkNotNull(id);
+ NotificationHandler(final RemoteDeviceHandler salFacade, final RemoteDeviceId id) {
+ this.salFacade = requireNonNull(salFacade);
+ this.id = requireNonNull(id);
}
synchronized void handleNotification(final NetconfMessage notification) {
* Forward all cached notifications and pass all notifications from this point directly to sal facade.
* @param transformer Message transformer
*/
- synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> transformer) {
- this.messageTransformer = Preconditions.checkNotNull(transformer);
+ synchronized void onRemoteSchemaUp(final NotificationTransformer transformer) {
+ messageTransformer = requireNonNull(transformer);
passNotifications = true;
}
private DOMNotification transformNotification(final NetconfMessage cachedNotification) {
- final DOMNotification parsedNotification = messageTransformer.toNotification(cachedNotification);
- Preconditions.checkNotNull(
- parsedNotification, "%s: Unable to parse received notification: %s", id, cachedNotification);
- return parsedNotification;
+ return checkNotNull(messageTransformer.toNotification(cachedNotification),
+ "%s: Unable to parse received notification: %s", id, cachedNotification);
}
private void queueNotification(final NetconfMessage notification) {
- Preconditions.checkState(!passNotifications);
+ checkState(!passNotifications);
LOG.debug("{}: Caching notification {}, remote schema not yet fully built", id, notification);
if (LOG.isTraceEnabled()) {
private synchronized void passNotification(final DOMNotification parsedNotification) {
LOG.debug("{}: Forwarding notification {}", id, parsedNotification);
- if (filter == null || filter.filterNotification(parsedNotification).isPresent()) {
+ if (filter == null || filter.test(parsedNotification)) {
salFacade.onNotification(parsedNotification);
}
}
synchronized void addNotificationFilter(final NotificationFilter newFilter) {
- this.filter = newFilter;
+ filter = newFilter;
}
synchronized void onRemoteSchemaDown() {
messageTransformer = null;
}
- interface NotificationFilter {
+ @FunctionalInterface
+ interface NotificationFilter extends Predicate<DOMNotification> {
- Optional<DOMNotification> filterNotification(DOMNotification notification);
}
}