diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-02-17 17:29:51 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-02-17 17:39:12 +0100 |
commit | 6856c7448dcdae692f60aa65a79ec34c984b0586 (patch) | |
tree | 70305bdd01a82e8fcf6d3bd984ce2bb59cf50ea4 /container-core/src/main/java/com/yahoo/container/jdisc | |
parent | 1e4291ddeeb9072b49e64ef962f61a28dd256b9b (diff) |
Track sent and acked bytes to ensure a smooth flow of bytes not exceeding maxpending by more than
than a small byte buffer.
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/jdisc')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/jdisc/ContentChannelOutputStream.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/ContentChannelOutputStream.java b/container-core/src/main/java/com/yahoo/container/jdisc/ContentChannelOutputStream.java index 1d4c20efe5e..270da0c4ab0 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/ContentChannelOutputStream.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/ContentChannelOutputStream.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.Arrays; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -125,9 +124,13 @@ public class ContentChannelOutputStream extends OutputStream implements Writable @Override public void send(ByteBuffer src) throws IOException { // Don't do a buffer.flush() from here, this method is used by the buffer itself + send(src, null); + } + + protected void send(ByteBuffer src, CompletionHandler completionHandler) throws IOException { try { byteBufferData += src.remaining(); - endpoint.write(src, new LoggingCompletionHandler()); + endpoint.write(src, new LoggingCompletionHandler(completionHandler)); } catch (RuntimeException e) { throw new IOException(Exceptions.toMessageString(e), e); } @@ -138,10 +141,16 @@ public class ContentChannelOutputStream extends OutputStream implements Writable return buffer.appended() + byteBufferData; } - class LoggingCompletionHandler implements CompletionHandler { - + private class LoggingCompletionHandler implements CompletionHandler { + private final CompletionHandler nested; + LoggingCompletionHandler(CompletionHandler nested) { + this.nested = nested; + } @Override public void completed() { + if (nested != null) { + nested.completed(); + } } @Override @@ -158,6 +167,9 @@ public class ContentChannelOutputStream extends OutputStream implements Writable if (log.isLoggable(logLevel)) { log.log(logLevel, "Got exception when writing to client: " + Exceptions.toMessageString(t)); } + if (nested != null) { + nested.failed(t); + } } } |