Merge "Improve xml lookup in edit-config rpc for md-sal"
[controller.git] / opendaylight / netconf / netconf-client / src / main / java / org / opendaylight / controller / netconf / client / NetconfClientSession.java
index 11c7f3061f9e9b28f34926b482c60a8bbe51a26a..31a7661b2c17ccb8fdff3688f7111a26b4fe3f97 100644 (file)
@@ -9,28 +9,56 @@
 package org.opendaylight.controller.netconf.client;
 
 import io.netty.channel.Channel;
-
+import io.netty.handler.codec.ByteToMessageDecoder;
+import io.netty.handler.codec.MessageToByteEncoder;
 import java.util.Collection;
-
-import org.opendaylight.controller.netconf.api.NetconfSession;
-import org.opendaylight.protocol.framework.SessionListener;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.nettyutil.AbstractNetconfSession;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
+import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NetconfClientSession extends NetconfSession {
+public class NetconfClientSession extends AbstractNetconfSession<NetconfClientSession, NetconfClientSessionListener> {
 
-    private static final Logger logger = LoggerFactory.getLogger(NetconfClientSession.class);
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSession.class);
     private final Collection<String> capabilities;
 
-    public NetconfClientSession(SessionListener sessionListener, Channel channel, long sessionId,
-            Collection<String> capabilities) {
-        super(sessionListener,channel,sessionId);
+    /**
+     * Construct a new session.
+     *
+     * @param sessionListener
+     * @param channel
+     * @param sessionId
+     * @param capabilities set of advertised capabilities. Expected to be immutable.
+     */
+    public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel, final long sessionId,
+            final Collection<String> capabilities) {
+        super(sessionListener, channel, sessionId);
         this.capabilities = capabilities;
-        logger.debug("Client Session {} created", toString());
+        LOG.debug("Client Session {} created", this);
     }
 
     public Collection<String> getServerCapabilities() {
         return capabilities;
     }
 
+    @Override
+    protected NetconfClientSession thisInstance() {
+        return this;
+    }
+
+    @Override
+    protected void addExiHandlers(final ByteToMessageDecoder decoder, final MessageToByteEncoder<NetconfMessage> encoder) {
+        // TODO used only in negotiator, client supports only auto start-exi
+        replaceMessageDecoder(decoder);
+        replaceMessageEncoder(encoder);
+    }
+
+    @Override
+    public void stopExiCommunication() {
+        // TODO never used, Netconf client does not support stop-exi
+        replaceMessageDecoder(new NetconfXMLToMessageDecoder());
+        replaceMessageEncoder(new NetconfMessageToXMLEncoder());
+    }
 }