Use Future.cause() for completion checking 48/102748/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 18:45:14 +0000 (20:45 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 18:45:14 +0000 (20:45 +0200)
We know the future has completed, hence nullability of Future.cause()
is a quicker check for success.

Change-Id: Ie7baadb7fd744a8b7cfd58b01097997e71045ccd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java

index 89c0be106837c21a907587dedca8dcb491b20a39..59f3e450b9c35b5d137bc391531a9c7a6ee28bf7 100644 (file)
@@ -336,11 +336,12 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
      *
      * @param msg Message which should be sent.
      */
-    protected final void sendMessage(final NetconfMessage msg) {
-        this.channel.writeAndFlush(msg).addListener(f -> {
-            if (!f.isSuccess()) {
-                LOG.info("Failed to send message {} on channel {}", msg, channel, f.cause());
-                negotiationFailed(f.cause());
+    protected void sendMessage(final NetconfMessage msg) {
+        channel.writeAndFlush(msg).addListener(f -> {
+            final var cause = f.cause();
+            if (cause != null) {
+                LOG.info("Failed to send message {} on channel {}", msg, channel, cause);
+                negotiationFailed(cause);
             } else {
                 LOG.trace("Message {} sent to socket on channel {}", msg, channel);
             }