Move PendingWriteRequest.pend() 13/101413/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Jun 2022 16:31:43 +0000 (18:31 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Jun 2022 16:31:43 +0000 (18:31 +0200)
PendingWriteRequest should be a dumb DTO, move channel state checking
away.

Change-Id: I6b7a1d38ed4182a5c16373e1f6abc0386da9e2d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java

index 3477b0b9249b035ee5a85883eb281d83172e67a2..d13d45a238fcf2f618069ea3ea945bee72e1faef 100644 (file)
@@ -16,7 +16,6 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.Deque;
 import java.util.LinkedList;
-import java.util.Queue;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.checkerframework.checker.lock.qual.GuardedBy;
@@ -171,12 +170,18 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
     }
 
     private void queueRequest(final ChannelHandlerContext ctx, final ByteBuf msg, final ChannelPromise promise) {
-//        try {
         LOG.debug("Write pending on channel: {}, queueing, current queue size: {}", ctx.channel(), pending.size());
         if (LOG.isTraceEnabled()) {
             LOG.trace("Queueing request due to pending: {}", byteBufToString(msg));
         }
-        new PendingWriteRequest(ctx, msg, promise).pend(pending);
+
+//      try {
+        final var req = new PendingWriteRequest(ctx, msg, promise);
+        // Preconditions.checkState(pending.size() < MAX_PENDING_WRITES,
+        // "Too much pending writes(%s) on channel: %s, remote window is not getting read or is too small",
+        // pending.size(), ctx.channel());
+        checkState(pending.offer(req), "Cannot pend another request write (pending count: %s) on channel: %s",
+                pending.size(), ctx.channel());
 //        } catch (final Exception ex) {
 //            LOG.warn("Unable to queue write request on channel: {}. Setting fail for the request: {}",
 //                    ctx.channel(), ex, byteBufToString(msg));
@@ -210,13 +215,5 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
             this.msg = msg;
             this.promise = promise;
         }
-
-        void pend(final Queue<PendingWriteRequest> pending) {
-            // Preconditions.checkState(pending.size() < MAX_PENDING_WRITES,
-            // "Too much pending writes(%s) on channel: %s, remote window is not getting read or is too small",
-            // pending.size(), ctx.channel());
-            checkState(pending.offer(this), "Cannot pend another request write (pending count: %s) on channel: %s",
-                pending.size(), ctx.channel());
-        }
     }
 }