From a80dddbb6eed5e87a4aa4917ce35c6ed94a53087 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 1 Jun 2022 18:31:43 +0200 Subject: [PATCH] Move PendingWriteRequest.pend() PendingWriteRequest should be a dumb DTO, move channel state checking away. Change-Id: I6b7a1d38ed4182a5c16373e1f6abc0386da9e2d8 Signed-off-by: Robert Varga --- .../ssh/client/AsyncSshHandlerWriter.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java index 3477b0b924..d13d45a238 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java @@ -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 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()); - } } } -- 2.36.6