Extend Websocket streams for data-less notifications
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / streams / listeners / AbstractQueryParams.java
index 618bf4de91ac475bf676456655a54b39a23ae1d2..469764628cfe452c39b4a6afd8959a9df3eea232 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.netconf.sal.streams.listeners;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import java.io.StringReader;
 import java.time.Instant;
 import java.util.Optional;
@@ -53,6 +54,7 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
     private Instant stop = null;
     private String filter = null;
     private boolean leafNodesOnly = false;
+    private boolean skipNotificationData = false;
 
     @VisibleForTesting
     public final Instant getStart() {
@@ -70,14 +72,17 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
      *            indicate which subset of all possible events are of interest
      * @param leafNodesOnly
      *            if true, notifications will contain changes to leaf nodes only
+     * @param skipNotificationData
+     *            if true, notification will not contain changed data
      */
     @SuppressWarnings("checkstyle:hiddenField")
     public void setQueryParams(final Instant start, final Optional<Instant> stop, final Optional<String> filter,
-                               final boolean leafNodesOnly) {
-        this.start = Preconditions.checkNotNull(start);
+                               final boolean leafNodesOnly, final boolean skipNotificationData) {
+        this.start = requireNonNull(start);
         this.stop = stop.orElse(null);
         this.filter = filter.orElse(null);
         this.leafNodesOnly = leafNodesOnly;
+        this.skipNotificationData = skipNotificationData;
     }
 
     /**
@@ -90,19 +95,19 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
     }
 
     /**
-     * Checking query parameters on specific notification.
+     * Check whether this query should notify changes without data.
      *
-     * @param xml       data of notification
-     * @param listener  listener of notification
-     * @return true if notification meets the requirements of query parameters,
-     *         false otherwise
+     * @return true if this query should notify about changes with  data
      */
+    public boolean isSkipNotificationData() {
+        return skipNotificationData;
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
-    protected <T extends BaseListenerInterface> boolean checkQueryParams(final String xml, final T listener) {
-        final Instant now = Instant.now();
+    <T extends BaseListenerInterface> boolean checkStartStop(final Instant now, final T listener) {
         if (this.stop != null) {
-            if ((this.start.compareTo(now) < 0) && (this.stop.compareTo(now) > 0)) {
-                return checkFilter(xml);
+            if (this.start.compareTo(now) < 0 && this.stop.compareTo(now) > 0) {
+                return true;
             }
             if (this.stop.compareTo(now) < 0) {
                 try {
@@ -114,10 +119,10 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
         } else if (this.start != null) {
             if (this.start.compareTo(now) < 0) {
                 this.start = null;
-                return checkFilter(xml);
+                return true;
             }
         } else {
-            return checkFilter(xml);
+            return true;
         }
         return false;
     }
@@ -128,7 +133,7 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
      * @param xml   data of notification
      */
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private boolean checkFilter(final String xml) {
+    boolean checkFilter(final String xml) {
         if (this.filter == null) {
             return true;
         }