updates from review

introduce default buffer size constant
This commit is contained in:
gregw 2024-07-17 10:50:55 +10:00 committed by Ludovic Orban
parent e699583c04
commit 2ba2250ac8
11 changed files with 29 additions and 19 deletions

View File

@ -20,13 +20,14 @@ import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.RetainableByteBuffer;
import org.eclipse.jetty.util.IO;
/**
* {@link ContentDecoder} for the "gzip" encoding.
*/
public class GZIPContentDecoder extends org.eclipse.jetty.http.GZIPContentDecoder implements ContentDecoder
{
public static final int DEFAULT_BUFFER_SIZE = 8192;
public static final int DEFAULT_BUFFER_SIZE = IO.DEFAULT_BUFFER_SIZE;
private long decodedLength;

View File

@ -23,6 +23,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
/**
@ -62,7 +63,7 @@ public class HttpTester
public Input()
{
this(BufferUtil.allocate(8192));
this(BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE));
}
Input(ByteBuffer buffer)
@ -477,7 +478,7 @@ public class HttpTester
switch (result)
{
case NEED_HEADER:
header = BufferUtil.allocate(8192);
header = BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE);
continue;
case HEADER_OVERFLOW:
@ -491,7 +492,7 @@ public class HttpTester
continue;
case NEED_CHUNK_TRAILER:
chunk = BufferUtil.allocate(8192);
chunk = BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE);
continue;
case NEED_INFO:

View File

@ -34,6 +34,7 @@ import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.Transport;
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ -102,7 +103,7 @@ import org.eclipse.jetty.util.thread.Scheduler;
public class HTTP2Client extends ContainerLifeCycle
{
private final ClientConnector connector;
private int inputBufferSize = 8192;
private int inputBufferSize = IO.DEFAULT_BUFFER_SIZE;
private List<String> protocols = List.of("h2");
private int initialSessionRecvWindow = 16 * 1024 * 1024;
private int initialStreamRecvWindow = 8 * 1024 * 1024;

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.http3;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ -186,7 +187,7 @@ public class HTTP3Configuration
/**
* <p>Sets max request headers size.</p>
* <p>The default value is {@code 8192} bytes.</p>
* <p>The default value is {@link IO#DEFAULT_BUFFER_SIZE} bytes.</p>
* <p>This value is configured in the server-side QPACK decoder, and
* then communicated to the client-side QPACK encoder via the SETTINGS
* frame.</p>
@ -208,7 +209,7 @@ public class HTTP3Configuration
/**
* <p>Sets max response headers size.</p>
* <p>The default value is {@code 8192} bytes.</p>
* <p>The default value is {@link IO#DEFAULT_BUFFER_SIZE} bytes.</p>
* <p>This value is configured in the client-side QPACK decoder, and
* then communicated to the server-side QPACK encoder via the SETTINGS
* frame.</p>

View File

@ -19,6 +19,7 @@ import java.util.List;
import java.util.Objects;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.IO;
/**
* <p>A pool for {@link RetainableByteBuffer} instances.</p>
@ -136,7 +137,7 @@ public interface ByteBufferPool
{
super(Objects.requireNonNullElse(wrapped, NON_POOLING));
_direct = direct;
_size = size >= 0 ? size : 8192;
_size = size >= 0 ? size : IO.DEFAULT_BUFFER_SIZE;
}
public boolean isDirect()

View File

@ -27,6 +27,7 @@ import java.util.Objects;
import org.eclipse.jetty.util.Blocker;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.IteratingNestedCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -1439,7 +1440,7 @@ public interface RetainableByteBuffer extends Retainable
*/
public DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize, int aggregationSize, int minRetainSize)
{
this(null, new ByteBufferPool.Sized(pool, direct, maxSize > 0 && maxSize < 8192L ? (int)maxSize : aggregationSize), maxSize, minRetainSize);
this(null, new ByteBufferPool.Sized(pool, direct, maxSize > 0 && maxSize < IO.DEFAULT_BUFFER_SIZE ? (int)maxSize : aggregationSize), maxSize, minRetainSize);
}
private DynamicCapacity(List<RetainableByteBuffer> buffers, ByteBufferPool.Sized pool, long maxSize, int minRetainSize)
@ -1500,7 +1501,7 @@ public interface RetainableByteBuffer extends Retainable
throw new BufferOverflowException();
int length = (int)size;
RetainableByteBuffer combined = _pool.acquire(length, _pool.isDirect());
RetainableByteBuffer combined = _pool.acquire(length);
ByteBuffer byteBuffer = combined.getByteBuffer();
BufferUtil.flipToFill(byteBuffer);
for (RetainableByteBuffer buffer : _buffers)
@ -2007,7 +2008,7 @@ public interface RetainableByteBuffer extends Retainable
aggregateSize = Math.max(length, aggregateSize);
if (aggregateSize > space)
aggregateSize = (int)space;
_aggregate = _pool.acquire(aggregateSize, _pool.isDirect()).asMutable();
_aggregate = _pool.acquire(aggregateSize, _pool.isDirect());
checkAggregateLimit(space);
_buffers.add(_aggregate);
}

View File

@ -32,6 +32,7 @@ import org.eclipse.jetty.io.content.AsyncContent;
import org.eclipse.jetty.io.content.BufferedContentSink;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -257,7 +258,7 @@ public class BufferedContentSinkTest
try (AsyncContent async = new AsyncContent(); )
{
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, false, 8192, 8192);
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, false, IO.DEFAULT_BUFFER_SIZE, IO.DEFAULT_BUFFER_SIZE);
Callback.Completable callback = new Callback.Completable();
buffered.write(false, BufferUtil.toBuffer("Hello "), callback);
@ -485,7 +486,7 @@ public class BufferedContentSinkTest
try (AsyncContent async = new AsyncContent())
{
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, true, 4096, 4096);
AtomicInteger count = new AtomicInteger(8192);
AtomicInteger count = new AtomicInteger(IO.DEFAULT_BUFFER_SIZE);
CountDownLatch complete = new CountDownLatch(1);
Callback callback = new Callback()
{
@ -571,7 +572,7 @@ public class BufferedContentSinkTest
try (AsyncContent async = new AsyncContent())
{
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, true, 1, 4096);
AtomicInteger count = new AtomicInteger(8192);
AtomicInteger count = new AtomicInteger(IO.DEFAULT_BUFFER_SIZE);
CountDownLatch complete = new CountDownLatch(1);
Callback callback = new Callback()
{

View File

@ -19,6 +19,7 @@ import java.util.List;
import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.ArrayUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
@ -32,7 +33,7 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
{
private final String _protocol;
private final List<String> _protocols;
private int _inputBufferSize = 8192;
private int _inputBufferSize = IO.DEFAULT_BUFFER_SIZE;
protected AbstractConnectionFactory(String protocol)
{

View File

@ -664,11 +664,11 @@ public class BufferUtil
public static void readFrom(InputStream is, int needed, ByteBuffer buffer) throws IOException
{
ByteBuffer tmp = allocate(8192);
ByteBuffer tmp = allocate(IO.DEFAULT_BUFFER_SIZE);
while (needed > 0 && buffer.hasRemaining())
{
int l = is.read(tmp.array(), 0, 8192);
int l = is.read(tmp.array(), 0, IO.DEFAULT_BUFFER_SIZE);
if (l < 0)
break;
tmp.position(0);
@ -688,7 +688,7 @@ public class BufferUtil
else
{
int totalRead = 0;
ByteBuffer tmp = allocate(8192);
ByteBuffer tmp = allocate(IO.DEFAULT_BUFFER_SIZE);
while (BufferUtil.space(tmp) > 0 && BufferUtil.space(buffer) > 0)
{
int read = is.read(tmp.array(), 0, Math.min(BufferUtil.space(tmp), BufferUtil.space(buffer)));

View File

@ -57,6 +57,8 @@ public class IO
{
private static final Logger LOG = LoggerFactory.getLogger(IO.class);
public static final int DEFAULT_BUFFER_SIZE = 8192;
public static final String
CRLF = "\r\n";

View File

@ -606,7 +606,7 @@ public class UrlEncoded
public static void decodeUtf16To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) throws IOException
{
InputStreamReader input = new InputStreamReader(in, StandardCharsets.UTF_16);
StringWriter buf = new StringWriter(8192);
StringWriter buf = new StringWriter(IO.DEFAULT_BUFFER_SIZE);
IO.copy(input, buf, maxLength);
decodeTo(buf.getBuffer().toString(), adder, StandardCharsets.UTF_16, maxKeys);