X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fapi%2FNetconfSession.java;h=0bd54979f8cab1c86a080b8bd9a2689625a122c0;hb=refs%2Fchanges%2F78%2F5678%2F15;hp=4770cb128fb7399f50759a2ffb599796001992b6;hpb=2b6f7622ea95596c1b512ca8d0bb343edca42098;p=controller.git 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 4770cb128f..0bd54979f8 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,78 +7,12 @@ */ package org.opendaylight.controller.netconf.api; -import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; -import java.io.IOException; +import org.opendaylight.protocol.framework.ProtocolSession; -import org.opendaylight.protocol.framework.AbstractProtocolSession; -import org.opendaylight.protocol.framework.SessionListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +public interface NetconfSession extends ProtocolSession { -public abstract class NetconfSession extends AbstractProtocolSession { - private static final Logger logger = LoggerFactory.getLogger(NetconfSession.class); - private final SessionListener sessionListener; - private final long sessionId; - private boolean up = false; + ChannelFuture sendMessage(NetconfMessage message); - protected final Channel channel; - - protected NetconfSession(SessionListener sessionListener, Channel channel, long sessionId) { - this.sessionListener = sessionListener; - this.channel = channel; - this.sessionId = sessionId; - logger.debug("Session {} created", toString()); - } - - @Override - public void close() { - channel.close(); - up = false; - sessionListener.onSessionTerminated(this, new NetconfTerminationReason("Session closed")); - } - - @Override - protected void handleMessage(NetconfMessage netconfMessage) { - logger.debug("handling incoming message"); - sessionListener.onMessage(this, netconfMessage); - } - - public ChannelFuture sendMessage(NetconfMessage netconfMessage) { - return channel.writeAndFlush(netconfMessage); - } - - @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 final boolean isUp() { - return up; - } - - public final long getSessionId() { - return sessionId; - } } -