From a089fbf3ea41320a7906c0759f7d72e0db97c20f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 29 May 2024 10:13:25 +0200 Subject: [PATCH] Fixes #9778 - Jetty 12 - Remove WriteFlusher.Listener. (#11839) * Fixes #9778 - Jetty 12 - Remove WriteFlusher.Listener. This listener is not necessary anymore, as the min data rate checks have been moved to a StatisticsHandler.MinimumDataRateHandler. Signed-off-by: Simone Bordet --- .../eclipse/jetty/http2/HTTP2Connection.java | 9 +---- .../org/eclipse/jetty/http2/HTTP2Session.java | 36 ------------------- .../jetty/http2/internal/HTTP2Flusher.java | 9 ----- .../org/eclipse/jetty/io/WriteFlusher.java | 7 ++-- .../jetty/server/internal/HttpConnection.java | 10 +----- 5 files changed, 7 insertions(+), 64 deletions(-) diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java index d3425e341dcd..9098dc3522b8 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java @@ -38,7 +38,6 @@ import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.Retainable; import org.eclipse.jetty.io.RetainableByteBuffer; -import org.eclipse.jetty.io.WriteFlusher; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.component.LifeCycle; @@ -48,7 +47,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class HTTP2Connection extends AbstractConnection implements Parser.Listener, WriteFlusher.Listener, Connection.UpgradeTo +public class HTTP2Connection extends AbstractConnection implements Parser.Listener, Connection.UpgradeTo { private static final Logger LOG = LoggerFactory.getLogger(HTTP2Connection.class); @@ -302,12 +301,6 @@ public void onConnectionFailure(int error, String reason) session.onConnectionFailure(error, reason); } - @Override - public void onFlushed(long bytes) throws IOException - { - session.onFlushed(bytes); - } - protected class HTTP2Producer implements ExecutionStrategy.Producer { private final Callback fillableCallback = new FillableCallback(); diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index 43e24fea1183..981036e64a0c 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -60,7 +60,6 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.CyclicTimeouts; import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.io.WriteFlusher; import org.eclipse.jetty.util.AtomicBiInteger; import org.eclipse.jetty.util.Atomics; import org.eclipse.jetty.util.Callback; @@ -1084,11 +1083,6 @@ private void onStreamDestroyed(int streamId) streamsState.onStreamDestroyed(); } - public void onFlushed(long bytes) throws IOException - { - flusher.onFlushed(bytes); - } - private void terminate(Throwable cause) { flusher.terminate(cause); @@ -1263,8 +1257,6 @@ public int getDataBytesRemaining() public abstract boolean generate(ByteBufferPool.Accumulator accumulator) throws HpackException; - public abstract long onFlushed(long bytes) throws IOException; - boolean hasHighPriority() { return false; @@ -1355,16 +1347,6 @@ public boolean generate(ByteBufferPool.Accumulator accumulator) throws HpackExce return true; } - @Override - public long onFlushed(long bytes) - { - long flushed = Math.min(frameBytes, bytes); - if (LOG.isDebugEnabled()) - LOG.debug("Flushed {}/{} frame bytes for {}", flushed, bytes, this); - frameBytes -= flushed; - return bytes - flushed; - } - /** *

Performs actions just before writing the frame to the network.

*

Some frame, when sent over the network, causes the receiver @@ -1433,7 +1415,6 @@ public void succeeded() private class DataEntry extends Entry { private int frameBytes; - private int frameRemaining; private int dataBytes; private int dataRemaining; @@ -1477,7 +1458,6 @@ public boolean generate(ByteBufferPool.Accumulator accumulator) DataFrame dataFrame = (DataFrame)frame; int frameBytes = generator.data(accumulator, dataFrame, length); this.frameBytes += frameBytes; - this.frameRemaining += frameBytes; int dataBytes = frameBytes - Frame.HEADER_LENGTH; this.dataBytes += dataBytes; @@ -1492,27 +1472,11 @@ public boolean generate(ByteBufferPool.Accumulator accumulator) return true; } - @Override - public long onFlushed(long bytes) throws IOException - { - long flushed = Math.min(frameRemaining, bytes); - if (LOG.isDebugEnabled()) - LOG.debug("Flushed {}/{} frame bytes for {}", flushed, bytes, this); - frameRemaining -= flushed; - // We should only forward data (not frame) bytes, - // but we trade precision for simplicity. - Object channel = stream.getAttachment(); - if (channel instanceof WriteFlusher.Listener) - ((WriteFlusher.Listener)channel).onFlushed(flushed); - return bytes - flushed; - } - @Override public void succeeded() { bytesWritten.addAndGet(frameBytes); frameBytes = 0; - frameRemaining = 0; flowControl.onDataSent(stream, dataBytes); dataBytes = 0; diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/internal/HTTP2Flusher.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/internal/HTTP2Flusher.java index df7df77c9f7a..fd0f7c8b8372 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/internal/HTTP2Flusher.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/internal/HTTP2Flusher.java @@ -293,15 +293,6 @@ protected Action process() throws Throwable return Action.SCHEDULED; } - public void onFlushed(long bytes) throws IOException - { - // A single EndPoint write may be flushed multiple times (for example with SSL). - for (HTTP2Session.Entry entry : processedEntries) - { - bytes = entry.onFlushed(bytes); - } - } - @Override public void succeeded() { diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java index 2ebba0cd95d3..24943165b430 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java @@ -429,8 +429,8 @@ protected ByteBuffer[] flush(SocketAddress address, ByteBuffer[] buffers) throws if (written > 0) { Connection connection = _endPoint.getConnection(); - if (connection instanceof Listener) - ((Listener)connection).onFlushed(written); + if (connection instanceof Listener listener) + listener.onFlushed(written); } if (flushed) @@ -581,7 +581,10 @@ public String toString() /** *

A listener of {@link WriteFlusher} events. * If implemented by a Connection class, the {@link #onFlushed(long)} event will be delivered to it.

+ * + * @deprecated functionality removed, no replacement */ + @Deprecated(since = "12.0.10", forRemoval = true) public interface Listener { /** diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java index 0ac7056cb8f5..3d479670005f 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java @@ -52,7 +52,6 @@ import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.RetainableByteBuffer; import org.eclipse.jetty.io.RuntimeIOException; -import org.eclipse.jetty.io.WriteFlusher; import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.server.AbstractMetaDataConnection; import org.eclipse.jetty.server.ConnectionFactory; @@ -81,7 +80,7 @@ /** *

A {@link Connection} that handles the HTTP protocol.

*/ -public class HttpConnection extends AbstractMetaDataConnection implements Runnable, WriteFlusher.Listener, Connection.UpgradeFrom, Connection.UpgradeTo, ConnectionMetaData +public class HttpConnection extends AbstractMetaDataConnection implements Runnable, Connection.UpgradeFrom, Connection.UpgradeTo, ConnectionMetaData { private static final Logger LOG = LoggerFactory.getLogger(HttpConnection.class); private static final HttpField PREAMBLE_UPGRADE_H2C = new HttpField(HttpHeader.UPGRADE, "h2c"); @@ -336,13 +335,6 @@ public void onUpgradeTo(ByteBuffer buffer) BufferUtil.append(getRequestBuffer(), buffer); } - @Override - public void onFlushed(long bytes) throws IOException - { - // TODO is this callback still needed? Couldn't we wrap send callback instead? - // Either way, the dat rate calculations from HttpOutput.onFlushed should be moved to Channel. - } - void releaseRequestBuffer() { if (_retainableByteBuffer != null && !_retainableByteBuffer.hasRemaining())