X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fnettyutil%2FAbstractNetconfSessionNegotiator.java;h=d9c15ae03578052a079bc157d44d2e7e9dcb6e1e;hb=ce8ad4e92f8128750f7ce7216f7e73ad238efaae;hp=1a548f41da16a221dd130458246803389127af8d;hpb=246887769bc45b7f5a33116e8636a70bd4776184;p=netconf.git diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java index 1a548f41da..d9c15ae035 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java @@ -19,7 +19,6 @@ import io.netty.handler.ssl.SslHandler; import io.netty.util.Timeout; import io.netty.util.Timer; import io.netty.util.TimerTask; -import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.Promise; import java.util.concurrent.TimeUnit; @@ -79,25 +78,30 @@ public abstract class AbstractNetconfSessionNegotiator

sslHandler = getSslHandler(channel); - if (sslHandler.isPresent()) { - Future future = sslHandler.get().handshakeFuture(); - future.addListener(new GenericFutureListener>() { - @Override - public void operationComplete(final Future future) { + if (ifNegotiatedAlready()) { + LOG.debug("Negotiation on channel {} already started", channel); + } else { + final Optional sslHandler = getSslHandler(channel); + if (sslHandler.isPresent()) { + sslHandler.get().handshakeFuture().addListener(future -> { Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); LOG.debug("Ssl handshake complete"); start(); - } - }); - } else { - start(); + }); + } else { + start(); + } } } + protected final synchronized boolean ifNegotiatedAlready() { + // Indicates whether negotiation already started + return this.state != State.IDLE; + } + private static Optional getSslHandler(final Channel channel) { final SslHandler sslHandler = channel.pipeline().get(SslHandler.class); - return sslHandler == null ? Optional.absent() : Optional.of(sslHandler); + return sslHandler == null ? Optional.absent() : Optional.of(sslHandler); } public P getSessionPreferences() { @@ -117,6 +121,7 @@ public abstract class AbstractNetconfSessionNegotiator

() { - @Override - public void operationComplete(final ChannelFuture future) throws Exception { - if (future.isSuccess()) { - LOG.debug("Channel {} closed: success", future.channel()); - } else { - LOG.warn("Channel {} closed: fail", future.channel()); - } + channel.close().addListener((GenericFutureListener) future -> { + if (future.isSuccess()) { + LOG.debug("Channel {} closed: success", future.channel()); + } else { + LOG.warn("Channel {} closed: fail", future.channel()); } }); } @@ -226,6 +228,7 @@ public abstract class AbstractNetconfSessionNegotiator