X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fnettyutil%2FAbstractNetconfSession.java;h=2c328df37e5b89bc37acf005e7a4ea3a70a0d354;hb=9110c5921ba8f05ceafefb784bf95b1b1655d6d2;hp=b1c1203c4f1dc5cb295e7ce9c4845c2ab422b90b;hpb=c8b97d445cc89c61fe0412241229b08324894e99;p=netconf.git diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java index b1c1203c4f..2c328df37e 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java @@ -10,31 +10,32 @@ package org.opendaylight.netconf.nettyutil; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; -import io.netty.channel.DefaultChannelPromise; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; +import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.FutureListener; -import java.io.IOException; -import org.opendaylight.controller.config.util.xml.XmlElement; +import java.io.EOFException; import org.opendaylight.netconf.api.NetconfExiSession; import org.opendaylight.netconf.api.NetconfMessage; import org.opendaylight.netconf.api.NetconfSession; import org.opendaylight.netconf.api.NetconfSessionListener; import org.opendaylight.netconf.api.NetconfTerminationReason; +import org.opendaylight.netconf.api.xml.XmlElement; import org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec; import org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder; import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder; import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters; -import org.opendaylight.protocol.framework.AbstractProtocolSession; -import org.openexi.proc.common.EXIOptionsException; -import org.openexi.sax.TransmogrifierException; +import org.opendaylight.netconf.shaded.exificient.core.exceptions.EXIException; +import org.opendaylight.netconf.shaded.exificient.core.exceptions.UnsupportedOption; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractNetconfSession> - extends AbstractProtocolSession implements NetconfSession, NetconfExiSession { +public abstract class AbstractNetconfSession> + extends SimpleChannelInboundHandler implements NetconfSession, NetconfExiSession { private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSession.class); + + private final L sessionListener; private final long sessionId; private boolean up = false; @@ -59,7 +60,6 @@ public abstract class AbstractNetconfSession() { - @Override - public void operationComplete(Future future) throws Exception { - if (future.isSuccess()) { - proxyFuture.setSuccess(); - } else { - proxyFuture.setFailure(future.cause()); - } - } - }); - if (delayedEncoder != null) { - replaceMessageEncoder(delayedEncoder); - delayedEncoder = null; - } + + final ChannelPromise promise = channel.newPromise(); + channel.eventLoop().execute(() -> { + channel.writeAndFlush(netconfMessage, promise); + if (delayedEncoder != null) { + replaceMessageEncoder(delayedEncoder); + delayedEncoder = null; } }); - return proxyFuture; + return promise; } - @Override protected void endOfInput() { - LOG.debug("Session {} end of input detected while session was in state {}", toString(), isUp() ? "up" - : "initialized"); - if (isUp()) { - this.sessionListener.onSessionDown(thisInstance(), - new IOException("End of input detected. Close the session.")); + LOG.debug("Session {} end of input detected while session was in state {}", this, up ? "up" : "initialized"); + if (up) { + this.sessionListener.onSessionDown(thisInstance(), new EOFException("End of input")); } } - @Override protected void sessionUp() { - LOG.debug("Session {} up", toString()); + LOG.debug("Session {} up", this); sessionListener.onSessionUp(thisInstance()); this.up = true; } @Override public String toString() { - final StringBuffer sb = new StringBuffer(getClass().getSimpleName() + "{"); + final StringBuilder sb = new StringBuilder(getClass().getSimpleName() + "{"); sb.append("sessionId=").append(sessionId); sb.append(", channel=").append(channel); sb.append('}'); @@ -147,24 +131,17 @@ public abstract class AbstractNetconfSession