X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fapi%2FNetconfSession.java;h=ca91589d74eaf92f4ba1ed4bbb72d4955b6109e5;hp=1e14bfdba285ec0e8f68f3b0b363abe2e370c66b;hb=b2e81149739c87f0ecc2ce7f06448d7a5d3162b8;hpb=0a23c5e6383fe72e6c5f59aa727ae2b27bb966f5 diff --git a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfSession.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfSession.java index 1e14bfdba2..ca91589d74 100644 --- a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfSession.java +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfSession.java @@ -7,138 +7,11 @@ */ package org.opendaylight.controller.netconf.api; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -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; +import io.netty.channel.ChannelFuture; +import org.opendaylight.protocol.framework.ProtocolSession; -import java.io.IOException; -import java.util.Map; +public interface NetconfSession extends ProtocolSession { -public abstract class NetconfSession extends AbstractProtocolSession { - - private ChannelHandler exiEncoder; - private String exiEncoderName; - private String removeAfterMessageSentname; - private String pmeName,pmdName; - protected final Channel channel; - private final SessionListener sessionListener; - private final long sessionId; - private boolean up = false; - private static final Logger logger = LoggerFactory.getLogger(NetconfSession.class); - - protected NetconfSession(SessionListener 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 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"); - 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; - } - } - - @Override - protected void endOfInput() { - logger.debug("Session {} end of input detected while session was in state {}", toString(), isUp() ? "up" - : "initialized"); - if (isUp()) { - this.sessionListener.onSessionDown(this, new IOException("End of input detected. Close the session.")); - } - } - - @Override - protected void sessionUp() { - logger.debug("Session {} up", toString()); - sessionListener.onSessionUp(this); - this.up = true; - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("ServerNetconfSession{"); - sb.append("sessionId=").append(sessionId); - sb.append('}'); - return sb.toString(); - } - - public boolean isUp() { - return up; - } - - public long getSessionId() { - return sessionId; - } - - public T remove(Class handlerType) { - return channel.pipeline().remove(handlerType); - } - - public T getHandler(Class 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; - } + ChannelFuture sendMessage(NetconfMessage message); } -