Split up MessageTransformer
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NotificationHandler.java
index 8c40dc4159c7cba2fe2425215a7f769c1d67992e..917729e7cba70b5d2060cd173d8bd4329ffb88ff 100644 (file)
@@ -13,11 +13,11 @@ 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;
@@ -29,16 +29,16 @@ import org.slf4j.LoggerFactory;
 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 NotificationFilter filter;
-    private MessageTransformer messageTransformer;
+    private NotificationTransformer messageTransformer;
 
-    NotificationHandler(final RemoteDeviceHandler<?> salFacade, final RemoteDeviceId id) {
+    NotificationHandler(final RemoteDeviceHandler salFacade, final RemoteDeviceId id) {
         this.salFacade = requireNonNull(salFacade);
         this.id = requireNonNull(id);
     }
@@ -55,7 +55,7 @@ final class NotificationHandler {
      * Forward all cached notifications and pass all notifications from this point directly to sal facade.
      * @param transformer Message transformer
      */
-    synchronized void onRemoteSchemaUp(final MessageTransformer transformer) {
+    synchronized void onRemoteSchemaUp(final NotificationTransformer transformer) {
         messageTransformer = requireNonNull(transformer);
 
         passNotifications = true;
@@ -86,7 +86,7 @@ final class NotificationHandler {
     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);
         }
     }
@@ -101,8 +101,8 @@ final class NotificationHandler {
         messageTransformer = null;
     }
 
-    interface NotificationFilter {
+    @FunctionalInterface
+    interface NotificationFilter extends Predicate<DOMNotification> {
 
-        Optional<DOMNotification> filterNotification(DOMNotification notification);
     }
 }