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=6a55bdb9aa663c10545bb3cd5cbb4c1e1b83c1da;hb=7ab3450d00b4175d303e2d304dbafbd1175081d4;hp=3212754c26a435e8b6ffff2d005f5d6211d50264;hpb=1aaec97aa24f5dfe62fd3e6523e651db883ab51f;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 3212754c26..6a55bdb9aa 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,7 +5,6 @@ * 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; @@ -14,8 +13,6 @@ 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; @@ -64,9 +61,21 @@ public class NetconfClientSessionNegotiator extends super(sessionPreferences, promise, channel, timer, sessionListener, connectionTimeoutMillis); } + @SuppressWarnings("checkstyle:IllegalCatch") + @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", + justification = "SpotBugs does not understand generic cast of sessionPreferences") @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 on channel {}", channel, e); + negotiationFailed(e); + return; + } + } final NetconfClientSession session = getSessionForHelloMessage(netconfMessage); replaceHelloMessageInboundHandler(session); @@ -93,21 +102,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") + @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", + justification = "SpotBugs does not understand generic cast of sessionPreferences") private boolean shouldUseExi(final NetconfHelloMessage helloMsg) { return containsExi10Capability(helloMsg.getDocument()) && containsExi10Capability(sessionPreferences.getHelloMessage().getDocument()); @@ -143,7 +150,7 @@ public class NetconfClientSessionNegotiator extends @Override protected NetconfClientSession getSession(final NetconfClientSessionListener sessionListener, final Channel channel, - final NetconfHelloMessage message) throws NetconfDocumentedException { + final NetconfHelloMessage message) { final long sessionId = extractSessionId(message.getDocument()); // Copy here is important: it disconnects the strings from the document