From: Robert Varga Date: Wed, 1 Jun 2022 16:31:43 +0000 (+0200) Subject: Move PendingWriteRequest.pend() X-Git-Tag: v4.0.0~59 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=a80dddbb6eed5e87a4aa4917ce35c6ed94a53087 Move PendingWriteRequest.pend() PendingWriteRequest should be a dumb DTO, move channel state checking away. Change-Id: I6b7a1d38ed4182a5c16373e1f6abc0386da9e2d8 Signed-off-by: Robert Varga --- 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()); - } } }