Replace replaceHelloMessageOutboundHandler() 57/102757/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 21:07:52 +0000 (23:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 19 Oct 2022 07:28:38 +0000 (09:28 +0200)
This is a utility method to manipulate pipeline, with a single caller.
Inline the method so the manipulations are clearly visible.

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

index ef71afc3cdf8ee07570778223627f780d5620197..082d4247cc4dc2fdd6d6fef5e4da26a2e7001eb8 100644 (file)
@@ -161,9 +161,24 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
             return;
         }
 
+        // Catch any exceptions from this point on. Use a named class to ease debugging.
+        final class ExceptionHandlingInboundChannelHandler extends ChannelInboundHandlerAdapter {
+            @Override
+            public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
+                LOG.warn("An exception occurred during negotiation with {} on channel {}",
+                        channel.remoteAddress(), channel, cause);
+                // FIXME: this is quite suspect as it is competing with timeoutExpired() without synchronization
+                cancelTimeout();
+                negotiationFailed(cause);
+                changeState(State.FAILED);
+            }
+        }
+
         channel.pipeline().addLast(NAME_OF_EXCEPTION_HANDLER, new ExceptionHandlingInboundChannelHandler());
 
-        replaceHelloMessageOutboundHandler();
+        // Remove special outbound handler for hello message. Insert regular netconf xml message (en|de)coders.
+        replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
+            new NetconfMessageToXMLEncoder());
 
         synchronized (this) {
             lockedChangeState(State.OPEN_WAIT);
@@ -287,14 +302,6 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
         }
     }
 
-    /**
-     * Remove special outbound handler for hello message. Insert regular netconf xml message (en|de)coders.
-     */
-    private void replaceHelloMessageOutboundHandler() {
-        replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
-                new NetconfMessageToXMLEncoder());
-    }
-
     private static ChannelHandler replaceChannelHandler(final Channel channel, final String handlerKey,
                                                         final ChannelHandler decoder) {
         return channel.pipeline().replace(handlerKey, handlerKey, decoder);
@@ -335,21 +342,6 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
         return false;
     }
 
-    /**
-     * Handler to catch exceptions in pipeline during negotiation.
-     */
-    private final class ExceptionHandlingInboundChannelHandler extends ChannelInboundHandlerAdapter {
-        @Override
-        public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
-            LOG.warn("An exception occurred during negotiation with {} on channel {}",
-                    channel.remoteAddress(), channel, cause);
-            // FIXME: this is quite suspect as it is competing with timeoutExpired() without synchronization
-            cancelTimeout();
-            negotiationFailed(cause);
-            changeState(State.FAILED);
-        }
-    }
-
     protected final void negotiationSuccessful(final S session) {
         LOG.debug("Negotiation on channel {} successful with session {}", channel, session);
         channel.pipeline().replace(this, "session", session);