Merge "Netconf-cli compilable and included in project"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerSession.java
index 9ddc64f1a16934b95c6a3bd69410eef554e4313b..ca604a4f6531c4f03d878825ac5fde5cfd360aeb 100644 (file)
@@ -8,15 +8,19 @@
 
 package org.opendaylight.controller.netconf.impl;
 
+import com.google.common.base.Preconditions;
 import io.netty.channel.Channel;
-
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
-import org.opendaylight.controller.netconf.api.AbstractNetconfSession;
 import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession;
+import org.opendaylight.controller.netconf.nettyutil.AbstractNetconfSession;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXICodec;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXIToMessageDecoder;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfMessageToEXIEncoder;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.DomainName;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Host;
@@ -33,11 +37,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 public final class NetconfServerSession extends AbstractNetconfSession<NetconfServerSession, NetconfServerSessionListener> implements NetconfManagementSession {
 
-    private static final Logger logger = LoggerFactory.getLogger(NetconfServerSession.class);
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfServerSession.class);
 
     private final NetconfHelloMessageAdditionalHeader header;
 
@@ -48,7 +50,7 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
             NetconfHelloMessageAdditionalHeader header) {
         super(sessionListener, channel, sessionId);
         this.header = header;
-        logger.debug("Session {} created", toString());
+        LOG.debug("Session {} created", toString());
     }
 
     @Override
@@ -109,9 +111,12 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
 
     private Class<? extends Transport> getTransportForString(String transport) {
         switch(transport) {
-        case "ssh" : return NetconfSsh.class;
-        case "tcp" : return NetconfTcp.class;
-        default: throw new IllegalArgumentException("Unknown transport type " + transport);
+        case "ssh" :
+            return NetconfSsh.class;
+        case "tcp" :
+            return NetconfTcp.class;
+        default:
+            throw new IllegalArgumentException("Unknown transport type " + transport);
         }
     }
 
@@ -124,4 +129,16 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
     protected NetconfServerSession thisInstance() {
         return this;
     }
+
+    @Override
+    protected void addExiHandlers(NetconfEXICodec exiCodec) {
+        replaceMessageDecoder(new NetconfEXIToMessageDecoder(exiCodec));
+        replaceMessageEncoderAfterNextMessage(new NetconfMessageToEXIEncoder(exiCodec));
+    }
+
+    @Override
+    public void stopExiCommunication() {
+        replaceMessageDecoder(new NetconfXMLToMessageDecoder());
+        replaceMessageEncoderAfterNextMessage(new NetconfMessageToXMLEncoder());
+    }
 }