Hide NetconfDevice.LOG
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NotificationHandler.java
index 232c7c7569730965fe24debe23aa548d9bd5bac9..ce63849affb1a01b101d0386ee0d68880301b233 100644 (file)
@@ -7,13 +7,16 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf;
 
-import com.google.common.base.Optional;
-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 org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+import java.util.Optional;
+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.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
@@ -36,12 +39,12 @@ final class NotificationHandler {
     private MessageTransformer<NetconfMessage> messageTransformer;
 
     NotificationHandler(final RemoteDeviceHandler<?> salFacade, final RemoteDeviceId id) {
-        this.salFacade = Preconditions.checkNotNull(salFacade);
-        this.id = Preconditions.checkNotNull(id);
+        this.salFacade = requireNonNull(salFacade);
+        this.id = requireNonNull(id);
     }
 
     synchronized void handleNotification(final NetconfMessage notification) {
-        if(passNotifications) {
+        if (passNotifications) {
             passNotification(transformNotification(notification));
         } else {
             queueNotification(notification);
@@ -50,10 +53,10 @@ final class NotificationHandler {
 
     /**
      * Forward all cached notifications and pass all notifications from this point directly to sal facade.
-     * @param messageTransformer
+     * @param transformer Message transformer
      */
-    synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> messageTransformer) {
-        this.messageTransformer = Preconditions.checkNotNull(messageTransformer);
+    synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> transformer) {
+        this.messageTransformer = requireNonNull(transformer);
 
         passNotifications = true;
 
@@ -65,16 +68,15 @@ final class NotificationHandler {
     }
 
     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 == false);
+        checkState(!passNotifications);
 
         LOG.debug("{}: Caching notification {}, remote schema not yet fully built", id, notification);
-        if(LOG.isTraceEnabled()) {
+        if (LOG.isTraceEnabled()) {
             LOG.trace("{}: Caching notification {}", id, XmlUtil.toString(notification.getDocument()));
         }
 
@@ -84,13 +86,13 @@ 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.filterNotification(parsedNotification).isPresent()) {
             salFacade.onNotification(parsedNotification);
         }
     }
 
-    synchronized void addNotificationFilter(final NotificationFilter filter) {
-        this.filter = filter;
+    synchronized void addNotificationFilter(final NotificationFilter newFilter) {
+        this.filter = newFilter;
     }
 
     synchronized void onRemoteSchemaDown() {
@@ -99,7 +101,7 @@ final class NotificationHandler {
         messageTransformer = null;
     }
 
-    static interface NotificationFilter {
+    interface NotificationFilter {
 
         Optional<DOMNotification> filterNotification(DOMNotification notification);
     }