Merge "Changed model versions to dependencies"
[controller.git] / opendaylight / netconf / netconf-api / src / main / java / org / opendaylight / controller / netconf / api / NetconfSession.java
index 8b761a85b23b423314a39f8718492a2f5d1f8de0..4770cb128fb7399f50759a2ffb599796001992b6 100644 (file)
@@ -8,72 +8,45 @@
 package org.opendaylight.controller.netconf.api;
 
 import io.netty.channel.Channel;
-import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelFuture;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.opendaylight.protocol.framework.AbstractProtocolSession;
-import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
-import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
 import org.opendaylight.protocol.framework.SessionListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class NetconfSession extends AbstractProtocolSession<NetconfMessage> {
-
-    private ChannelHandler exiEncoder;
-    private String exiEncoderName;
-    private String removeAfterMessageSentname;
-    private String pmeName,pmdName;
-    private final  Channel channel;
-    private final  SessionListener sessionListener;
+    private static final Logger logger = LoggerFactory.getLogger(NetconfSession.class);
+    private final SessionListener<NetconfMessage, NetconfSession, NetconfTerminationReason> sessionListener;
     private final long sessionId;
     private boolean up = false;
-    private static final Logger logger = LoggerFactory.getLogger(NetconfSession.class);
-    private static final int T = 0;
 
-    protected NetconfSession(SessionListener sessionListener, Channel channel, long sessionId) {
+    protected final Channel channel;
+
+    protected NetconfSession(SessionListener<NetconfMessage, NetconfSession, NetconfTerminationReason> sessionListener, Channel channel, long sessionId) {
         this.sessionListener = sessionListener;
         this.channel = channel;
         this.sessionId = sessionId;
         logger.debug("Session {} created", toString());
-
-        ChannelHandler pmd = channel.pipeline().get(ProtocolMessageDecoder.class);
-        ChannelHandler pme = channel.pipeline().get(ProtocolMessageEncoder.class);
-
-        for (Map.Entry<String, ChannelHandler> entry:channel.pipeline().toMap().entrySet()){
-            if (entry.getValue().equals(pmd)){
-                pmdName = entry.getKey();
-            }
-            if (entry.getValue().equals(pme)){
-                pmeName = entry.getKey();
-            }
-        }
     }
+
     @Override
     public void close() {
         channel.close();
+        up = false;
         sessionListener.onSessionTerminated(this, new NetconfTerminationReason("Session closed"));
     }
 
     @Override
     protected void handleMessage(NetconfMessage netconfMessage) {
-        logger.debug("handlign incomming message");
+        logger.debug("handling incoming message");
         sessionListener.onMessage(this, netconfMessage);
     }
 
-    public void sendMessage(NetconfMessage netconfMessage) {
-        channel.writeAndFlush(netconfMessage);
-        if (exiEncoder!=null){
-            if (channel.pipeline().get(exiEncoderName)== null){
-                channel.pipeline().addBefore(pmeName, exiEncoderName, exiEncoder);
-            }
-        }
-        if (removeAfterMessageSentname!=null){
-            channel.pipeline().remove(removeAfterMessageSentname);
-            removeAfterMessageSentname = null;
-        }
+    public ChannelFuture sendMessage(NetconfMessage netconfMessage) {
+        return channel.writeAndFlush(netconfMessage);
     }
 
     @Override
@@ -100,46 +73,12 @@ public abstract class NetconfSession extends AbstractProtocolSession<NetconfMess
         return sb.toString();
     }
 
-    public boolean isUp() {
+    public final boolean isUp() {
         return up;
     }
 
-    public long getSessionId() {
+    public final long getSessionId() {
         return sessionId;
     }
-
-    public <T extends ChannelHandler> T remove(Class<T> handlerType) {
-        return channel.pipeline().remove(handlerType);
-    }
-
-    public <T extends ChannelHandler> T getHandler(Class<T> handlerType) {
-        return channel.pipeline().get(handlerType);
-   }
-
-    public void addFirst(ChannelHandler handler, String name){
-        channel.pipeline().addFirst(name, handler);
-    }
-    public void addLast(ChannelHandler handler, String name){
-        channel.pipeline().addLast(name, handler);
-    }
-
-    public void addExiDecoder(String name,ChannelHandler handler){
-        if (channel.pipeline().get(name)== null){
-            channel.pipeline().addBefore(pmdName, name, handler);
-        }
-    }
-    public void addExiEncoderAfterMessageSent(String name, ChannelHandler handler){
-        this.exiEncoder = handler;
-        this.exiEncoderName = name;
-    }
-
-    public void addExiEncoder(String name, ChannelHandler handler){
-        channel.pipeline().addBefore(pmeName, name, handler);
-    }
-
-    public void removeAfterMessageSent(String handlerName){
-        this.removeAfterMessageSentname = handlerName;
-    }
-
 }