Clean up listener activation
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / streams / listeners / NotificationListenerAdapter.java
index 60b3c333e61b2c6fdd6aa18b18872002e69b91e2..c7c0963d3ad62ec20bdf24e2539268dfc9941ee5 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Optional;
 import javax.xml.xpath.XPathExpressionException;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.restconf.common.formatters.JSONNotificationFormatter;
 import org.opendaylight.restconf.common.formatters.NotificationFormatter;
 import org.opendaylight.restconf.common.formatters.NotificationFormatterFactory;
@@ -139,6 +140,12 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem
         return this.path;
     }
 
+    public final synchronized void listen(final DOMNotificationService notificationService) {
+        if (!isListening()) {
+            setRegistration(notificationService.registerNotificationListener(this, getSchemaPath()));
+        }
+    }
+
     @Override
     public String toString() {
         return MoreObjects.toStringHelper(this)