X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fclient%2FNetconfClientSessionNegotiator.java;h=0c98fa3f42edf08fbc86c90e7b515c514fe9ce6e;hb=7bf7d3fd39c6966a2414d4ca6fd77d195021c1f8;hp=1816fee0e041f119c0b545e37e4bf21055b2c585;hpb=df1a4dbb37e0fb187c6d50d3bab1f9d88b888928;p=netconf.git diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java index 1816fee0e0..0c98fa3f42 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java @@ -5,17 +5,13 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.client; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Interner; import com.google.common.collect.Interners; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.Timer; @@ -23,7 +19,7 @@ import io.netty.util.concurrent.Promise; import java.util.Set; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; -import org.opendaylight.netconf.api.NetconfClientSessionPreferences; +import org.checkerframework.checker.index.qual.NonNegative; import org.opendaylight.netconf.api.NetconfDocumentedException; import org.opendaylight.netconf.api.NetconfMessage; import org.opendaylight.netconf.api.messages.NetconfHelloMessage; @@ -40,9 +36,9 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -public class NetconfClientSessionNegotiator extends - AbstractNetconfSessionNegotiator { +// Non-final for mocking +class NetconfClientSessionNegotiator + extends AbstractNetconfSessionNegotiator { private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSessionNegotiator.class); private static final XPathExpression SESSION_ID_X_PATH = XMLNetconfUtil @@ -55,25 +51,25 @@ public class NetconfClientSessionNegotiator extends private static final Interner> INTERNER = Interners.newWeakInterner(); - protected NetconfClientSessionNegotiator(final NetconfClientSessionPreferences sessionPreferences, - final Promise promise, - final Channel channel, - final Timer timer, - final NetconfClientSessionListener sessionListener, - final long connectionTimeoutMillis) { - super(sessionPreferences, promise, channel, timer, sessionListener, connectionTimeoutMillis); + private final NetconfStartExiMessage startExi; + + NetconfClientSessionNegotiator(final NetconfHelloMessage hello, final NetconfStartExiMessage startExi, + final Promise promise, final Channel channel, final Timer timer, + final NetconfClientSessionListener sessionListener, final long connectionTimeoutMillis, + final @NonNegative int maximumIncomingChunkSize) { + super(hello, promise, channel, timer, sessionListener, connectionTimeoutMillis, maximumIncomingChunkSize); + this.startExi = startExi; } @SuppressWarnings("checkstyle:IllegalCatch") @Override - @SuppressFBWarnings("BC_UNCONFIRMED_CAST") protected void handleMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException { if (!ifNegotiatedAlready()) { LOG.debug("Server hello message received, starting negotiation on channel {}", channel); try { startNegotiation(); } catch (final Exception e) { - LOG.warn("Unexpected negotiation failure", e); + LOG.warn("Unexpected negotiation failure on channel {}", channel, e); negotiationFailed(e); return; } @@ -83,10 +79,9 @@ public class NetconfClientSessionNegotiator extends // If exi should be used, try to initiate exi communication // Call negotiationSuccessFul after exi negotiation is finished successfully or not - final NetconfMessage startExiMessage = sessionPreferences.getStartExiMessage(); - if (shouldUseExi(netconfMessage) && startExiMessage instanceof NetconfStartExiMessage) { + if (startExi != null && shouldUseExi(netconfMessage)) { LOG.debug("Netconf session {} should use exi.", session); - tryToInitiateExi(session, (NetconfStartExiMessage) startExiMessage); + tryToInitiateExi(session, startExi); } else { // Exi is not supported, release session immediately LOG.debug("Netconf session {} isn't capable of using exi.", session); @@ -104,24 +99,19 @@ public class NetconfClientSessionNegotiator extends ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER, new ExiConfirmationInboundHandler(session, startExiMessage)); - session.sendMessage(startExiMessage).addListener(new ChannelFutureListener() { - @Override - public void operationComplete(final ChannelFuture channelFuture) { - if (!channelFuture.isSuccess()) { - LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, this, - channelFuture.cause()); - channel.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER); - } else { - LOG.trace("Start-exi message {} sent to socket on session {}", startExiMessage, this); - } + session.sendMessage(startExiMessage).addListener(channelFuture -> { + if (!channelFuture.isSuccess()) { + LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, session, + channelFuture.cause()); + channel.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER); + } else { + LOG.trace("Start-exi message {} sent to socket on session {}", startExiMessage, session); } }); } - @SuppressFBWarnings("BC_UNCONFIRMED_CAST") private boolean shouldUseExi(final NetconfHelloMessage helloMsg) { - return containsExi10Capability(helloMsg.getDocument()) - && containsExi10Capability(sessionPreferences.getHelloMessage().getDocument()); + return containsExi10Capability(helloMsg.getDocument()) && containsExi10Capability(localHello().getDocument()); } private static boolean containsExi10Capability(final Document doc) {