X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClientSession.java;h=004a22f6948c570e96fc880ea764b366c8cbfd94;hp=f0180cf78d74a8c47a9697f91480c474601a9759;hb=c7ec8db7f107b5e265f4e8b2fe3dd0f7b1163b64;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9 diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSession.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSession.java index f0180cf78d..004a22f694 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSession.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSession.java @@ -9,87 +9,48 @@ package org.opendaylight.controller.netconf.client; import io.netty.channel.Channel; -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.NetconfSession; -import org.opendaylight.controller.netconf.api.NetconfTerminationReason; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; -import org.opendaylight.protocol.framework.SessionListener; +import java.util.Collection; +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.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.Collection; - -public class NetconfClientSession extends NetconfSession { - - private final SessionListener sessionListener; - private final long sessionId; - private final Channel channel; +public class NetconfClientSession extends AbstractNetconfSession { private static final Logger logger = LoggerFactory.getLogger(NetconfClientSession.class); private final Collection capabilities; - private boolean up; - public NetconfClientSession(SessionListener sessionListener, Channel channel, long sessionId, + public NetconfClientSession(NetconfClientSessionListener sessionListener, Channel channel, long sessionId, Collection capabilities) { - this.sessionListener = sessionListener; - this.channel = channel; - this.sessionId = sessionId; + super(sessionListener, channel, sessionId); this.capabilities = capabilities; logger.debug("Client Session {} created", toString()); } - @Override - public void close() { - channel.close(); - sessionListener.onSessionTerminated(this, new NetconfTerminationReason("Client Session closed")); - } - - @Override - protected void handleMessage(NetconfMessage netconfMessage) { - logger.debug("Client Session {} received message {}", toString(), - XmlUtil.toString(netconfMessage.getDocument())); - sessionListener.onMessage(this, netconfMessage); - } - - @Override - public void sendMessage(NetconfMessage netconfMessage) { - channel.writeAndFlush(netconfMessage); + public Collection getServerCapabilities() { + return capabilities; } @Override - protected void endOfInput() { - logger.debug("Client 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.")); - } + protected NetconfClientSession thisInstance() { + return this; } @Override - protected void sessionUp() { - logger.debug("Client Session {} up", toString()); - sessionListener.onSessionUp(this); - this.up = true; + protected void addExiHandlers(NetconfEXICodec exiCodec) { + // TODO used only in negotiator, client supports only auto start-exi + replaceMessageDecoder(new NetconfEXIToMessageDecoder(exiCodec)); + replaceMessageEncoder(new NetconfMessageToEXIEncoder(exiCodec)); } @Override - public String toString() { - final StringBuffer sb = new StringBuffer("ClientNetconfSession{"); - sb.append("sessionId=").append(sessionId); - sb.append('}'); - return sb.toString(); - } - - public boolean isUp() { - return up; - } - - public long getSessionId() { - return sessionId; - } - - public Collection getServerCapabilities() { - return capabilities; + public void stopExiCommunication() { + // TODO never used, Netconf client does not support stop-exi + replaceMessageDecoder(new NetconfXMLToMessageDecoder()); + replaceMessageEncoder(new NetconfMessageToXMLEncoder()); } }