Decouple config and netconf subsystems.
[controller.git] / opendaylight / netconf / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / listener / NetconfDeviceCommunicator.java
@@ -21,6 +21,8 @@ import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
@@ -30,8 +32,6 @@ import org.opendaylight.controller.netconf.client.NetconfClientSession;
 import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration;
-import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.controller.sal.connect.api.RemoteDevice;
 import org.opendaylight.controller.sal.connect.api.RemoteDeviceCommunicator;
 import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil;
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
 
 public class NetconfDeviceCommunicator implements NetconfClientSessionListener, RemoteDeviceCommunicator<NetconfMessage> {
 
-    private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceCommunicator.class);
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceCommunicator.class);
 
     private final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice;
     private final Optional<NetconfSessionPreferences> overrideNetconfCapabilities;
@@ -78,16 +78,19 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
     public void onSessionUp(final NetconfClientSession session) {
         sessionLock.lock();
         try {
-            logger.debug("{}: Session established", id);
+            LOG.debug("{}: Session established", id);
             this.session = session;
 
             NetconfSessionPreferences netconfSessionPreferences =
                                              NetconfSessionPreferences.fromNetconfSession(session);
-            logger.trace("{}: Session advertised capabilities: {}", id, netconfSessionPreferences);
+            LOG.trace("{}: Session advertised capabilities: {}", id,
+                    netconfSessionPreferences);
 
             if(overrideNetconfCapabilities.isPresent()) {
                 netconfSessionPreferences = netconfSessionPreferences.addModuleCaps(overrideNetconfCapabilities.get());
-                logger.debug("{}: Session capabilities overridden, capabilities that will be used: {}", id, netconfSessionPreferences);
+                LOG.debug(
+                        "{}: Session capabilities overridden, capabilities that will be used: {}",
+                        id, netconfSessionPreferences);
             }
 
             remoteDevice.onRemoteSessionUp(netconfSessionPreferences, this);
@@ -111,7 +114,7 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
             @Override
             public void operationComplete(Future<Object> future) throws Exception {
                 if (!future.isSuccess() && !future.isCancelled()) {
-                    logger.debug("{}: Connection failed", id, future.cause());
+                    LOG.debug("{}: Connection failed", id, future.cause());
                     NetconfDeviceCommunicator.this.remoteDevice.onRemoteSessionFailed(future.cause());
                 }
             }
@@ -178,13 +181,13 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
 
     @Override
     public void onSessionDown(final NetconfClientSession session, final Exception e) {
-        logger.warn("{}: Session went down", id, e);
+        LOG.warn("{}: Session went down", id, e);
         tearDown( null );
     }
 
     @Override
     public void onSessionTerminated(final NetconfClientSession session, final NetconfTerminationReason reason) {
-        logger.warn("{}: Session terminated {}", id, reason);
+        LOG.warn("{}: Session terminated {}", id, reason);
         tearDown( reason.getErrorMessage() );
     }
 
@@ -224,7 +227,8 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
                 requests.poll();
             } else {
                 request = null;
-                logger.warn("{}: Ignoring unsolicited message {}", id, msgToS(message));
+                LOG.warn("{}: Ignoring unsolicited message {}", id,
+                        msgToS(message));
             }
         }
         finally {
@@ -233,17 +237,18 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
 
         if( request != null ) {
 
-            logger.debug("{}: Message received {}", id, message);
+            LOG.debug("{}: Message received {}", id, message);
 
-            if(logger.isTraceEnabled()) {
-                logger.trace( "{}: Matched request: {} to response: {}", id, msgToS( request.request ), msgToS( message ) );
+            if(LOG.isTraceEnabled()) {
+                LOG.trace( "{}: Matched request: {} to response: {}", id, msgToS( request.request ), msgToS( message ) );
             }
 
             try {
                 NetconfMessageTransformUtil.checkValidReply( request.request, message );
             } catch (final NetconfDocumentedException e) {
-                logger.warn( "{}: Invalid request-reply match, reply message contains different message-id, request: {}, response: {}",
-                             id, msgToS( request.request ), msgToS( message ), e );
+                LOG.warn(
+                        "{}: Invalid request-reply match, reply message contains different message-id, request: {}, response: {}",
+                        id, msgToS(request.request), msgToS(message), e);
 
                 request.future.set( RpcResultBuilder.<NetconfMessage>failed()
                         .withRpcError( NetconfMessageTransformUtil.toRpcError( e ) ).build() );
@@ -257,8 +262,9 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
             try {
                 NetconfMessageTransformUtil.checkSuccessReply(message);
             } catch(final NetconfDocumentedException e) {
-                logger.warn( "{}: Error reply from remote device, request: {}, response: {}", id,
-                             msgToS( request.request ), msgToS( message ), e );
+                LOG.warn(
+                        "{}: Error reply from remote device, request: {}, response: {}",
+                        id, msgToS(request.request), msgToS(message), e);
 
                 request.future.set( RpcResultBuilder.<NetconfMessage>failed()
                         .withRpcError( NetconfMessageTransformUtil.toRpcError( e ) ).build() );
@@ -285,12 +291,13 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
 
     private ListenableFuture<RpcResult<NetconfMessage>> sendRequestWithLock(
                                                final NetconfMessage message, final QName rpc) {
-        if(logger.isTraceEnabled()) {
-            logger.trace("{}: Sending message {}", id, msgToS(message));
+        if(LOG.isTraceEnabled()) {
+            LOG.trace("{}: Sending message {}", id, msgToS(message));
         }
 
         if (session == null) {
-            logger.warn("{}: Session is disconnected, failing RPC request {}", id, message);
+            LOG.warn("{}: Session is disconnected, failing RPC request {}",
+                    id, message);
             return Futures.immediateFuture( createSessionDownRpcResult() );
         }
 
@@ -303,8 +310,9 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
             public void operationComplete(final Future<Void> future) throws Exception {
                 if( !future.isSuccess() ) {
                     // We expect that a session down will occur at this point
-                    logger.debug( "{}: Failed to send request {}", id,
-                                  XmlUtil.toString(req.request.getDocument()), future.cause() );
+                    LOG.debug("{}: Failed to send request {}", id,
+                            XmlUtil.toString(req.request.getDocument()),
+                            future.cause());
 
                     if( future.cause() != null ) {
                         req.future.set( createErrorRpcResult( RpcError.ErrorType.TRANSPORT,
@@ -315,7 +323,7 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
                     req.future.setException( future.cause() );
                 }
                 else {
-                    logger.trace( "Finished sending request {}", req.request );
+                    LOG.trace("Finished sending request {}", req.request);
                 }
             }
         });
@@ -324,8 +332,8 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener,
     }
 
     private void processNotification(final NetconfMessage notification) {
-        if(logger.isTraceEnabled()) {
-            logger.trace("{}: Notification received: {}", id, notification);
+        if(LOG.isTraceEnabled()) {
+            LOG.trace("{}: Notification received: {}", id, notification);
         }
 
         remoteDevice.onNotification(notification);