Hide NetconfClientSessionNegotiator
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / NetconfClientSessionNegotiator.java
index 1816fee0e041f119c0b545e37e4bf21055b2c585..5ee52bd073ac1f125176282127bce30faec4c3d3 100644 (file)
@@ -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;
@@ -40,8 +37,9 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-public class NetconfClientSessionNegotiator extends
-        AbstractNetconfSessionNegotiator<NetconfClientSessionPreferences, NetconfClientSession,
+// Non-final for mocking
+class NetconfClientSessionNegotiator
+        extends AbstractNetconfSessionNegotiator<NetconfClientSessionPreferences, NetconfClientSession,
                 NetconfClientSessionListener> {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSessionNegotiator.class);
 
@@ -55,25 +53,23 @@ public class NetconfClientSessionNegotiator extends
 
     private static final Interner<Set<String>> INTERNER = Interners.newWeakInterner();
 
-    protected NetconfClientSessionNegotiator(final NetconfClientSessionPreferences sessionPreferences,
-                                             final Promise<NetconfClientSession> promise,
-                                             final Channel channel,
-                                             final Timer timer,
-                                             final NetconfClientSessionListener sessionListener,
-                                             final long connectionTimeoutMillis) {
+    NetconfClientSessionNegotiator(final NetconfClientSessionPreferences sessionPreferences,
+            final Promise<NetconfClientSession> promise, final Channel channel, final Timer timer,
+            final NetconfClientSessionListener sessionListener, final long connectionTimeoutMillis) {
         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", e);
+                LOG.warn("Unexpected negotiation failure on channel {}", channel, e);
                 negotiationFailed(e);
                 return;
             }
@@ -104,21 +100,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());