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=f8f486b2a0f63770b984e66a532ec332c7c9e7d0;hb=4e39e49ef541d25099afc4c2ff80d89b04b24103;hp=b3d35dc3c0d05bd8811505b4c450948052c9f0ff;hpb=f0821760fcf5054e0e0e8cfd3453e7cf10252757;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 b3d35dc3c0..f8f486b2a0 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 @@ -41,7 +41,8 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; -public abstract class AbstractNetconfSessionNegotiator

, L extends NetconfSessionListener> +public abstract class AbstractNetconfSessionNegotiator

, L extends NetconfSessionListener> extends AbstractSessionNegotiator { private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSessionNegotiator.class); @@ -54,7 +55,7 @@ public abstract class AbstractNetconfSessionNegotiator

promise, final Channel channel, final Timer timer, - final L sessionListener, final long connectionTimeoutMillis) { + protected AbstractNetconfSessionNegotiator(final P sessionPreferences, final Promise promise, + final Channel channel, final Timer timer, + final L sessionListener, final long connectionTimeoutMillis) { super(promise, channel); this.sessionPreferences = sessionPreferences; this.promise = promise; @@ -77,25 +79,34 @@ 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) { - Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); - LOG.debug("Ssl handshake complete"); - start(); - } - }); + if (ifNegotiatedAlready()) { + LOG.debug("Negotiation on channel {} already started", channel); } else { - start(); + final Optional sslHandler = getSslHandler(channel); + if (sslHandler.isPresent()) { + Future future = sslHandler.get().handshakeFuture(); + future.addListener(new GenericFutureListener>() { + @Override + public void operationComplete(final Future future) { + Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); + LOG.debug("Ssl handshake complete"); + start(); + } + }); + } else { + start(); + } } } + protected final 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() { @@ -115,6 +126,7 @@ public abstract class AbstractNetconfSessionNegotiator

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

* Inbound hello message handler should be kept until negotiation is successful * It caches any non-hello messages while negotiation is still in progress */ protected final void replaceHelloMessageInboundHandler(final S session) { - ChannelHandler helloMessageHandler = replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToMessageDecoder()); + ChannelHandler helloMessageHandler = replaceChannelHandler(channel, + AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToMessageDecoder()); Preconditions.checkState(helloMessageHandler instanceof NetconfXMLToHelloMessageDecoder, "Pipeline handlers misplaced on session: %s, pipeline: %s", session, channel.pipeline()); @@ -200,7 +215,8 @@ public abstract class AbstractNetconfSessionNegotiator