Skip to content

Commit

Permalink
Revert "Revert NON_POOLING change" (#11649)
Browse files Browse the repository at this point in the history
This reverts commit 2bf7d6c.
  • Loading branch information
gregw authored Apr 18, 2024
1 parent 940c744 commit 33feac3
Show file tree
Hide file tree
Showing 28 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public GZIPContentDecoder(InflaterPool inflaterPool, ByteBufferPool byteBufferPo
_inflaterEntry = inflaterPool.acquire();
_inflater = _inflaterEntry.get();
_bufferSize = bufferSize;
_pool = byteBufferPool != null ? byteBufferPool : new ByteBufferPool.NonPooling();
_pool = byteBufferPool != null ? byteBufferPool : ByteBufferPool.NON_POOLING;
reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public Part(HttpFields headers, Resource resource, ByteRange byteRange, ByteBuff
super(null, null, headers);
this.resource = resource;
this.byteRange = byteRange;
this.bufferPool = bufferPool == null ? new ByteBufferPool.NonPooling() : bufferPool;
this.bufferPool = bufferPool == null ? ByteBufferPool.NON_POOLING : bufferPool;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class CachingHttpContentFactory implements HttpContent.Factory
public CachingHttpContentFactory(HttpContent.Factory authority, ByteBufferPool bufferPool)
{
_authority = authority;
_bufferPool = bufferPool != null ? bufferPool : new ByteBufferPool.NonPooling();
_bufferPool = bufferPool != null ? bufferPool : ByteBufferPool.NON_POOLING;
}

protected ConcurrentMap<String, CachingHttpContent> getCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void testGenerateParse(ByteBuffer byteBuffer)
byteBuffer.get(inputBytes);
DataFrame input = new DataFrame(ByteBuffer.wrap(inputBytes), true);

ByteBufferPool.NonPooling bufferPool = new ByteBufferPool.NonPooling();
ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
new MessageGenerator(bufferPool, null, true).generate(accumulator, 0, input, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testGenerateParse()
{
GoAwayFrame input = GoAwayFrame.CLIENT_GRACEFUL;

ByteBufferPool.NonPooling bufferPool = new ByteBufferPool.NonPooling();
ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
new ControlGenerator(bufferPool, true).generate(accumulator, 0, input, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testGenerateParse()

QpackEncoder encoder = new QpackEncoder(instructions -> {});
encoder.setMaxHeadersSize(4 * 1024);
ByteBufferPool.NonPooling bufferPool = new ByteBufferPool.NonPooling();
ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
new MessageGenerator(bufferPool, encoder, true).generate(accumulator, 0, input, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void testGenerateParse(Map<Long, Long> settings)
{
SettingsFrame input = new SettingsFrame(settings);

ByteBufferPool.NonPooling bufferPool = new ByteBufferPool.NonPooling();
ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
new ControlGenerator(bufferPool, true).generate(accumulator, 0, input, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class DecoderInstructionParserTest
{
private final ByteBufferPool bufferPool = new ByteBufferPool.NonPooling();
private final ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
private DecoderInstructionParser _instructionParser;
private DecoderParserDebugHandler _handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class InstructionGeneratorTest
{
private final ByteBufferPool _bufferPool = new ByteBufferPool.NonPooling();
private final ByteBufferPool _bufferPool = ByteBufferPool.NON_POOLING;

private String toHexString(Instruction instruction)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class QpackTestUtil
{
public static ByteBuffer toBuffer(Instruction... instructions)
{
ByteBufferPool.NonPooling bufferPool = new ByteBufferPool.NonPooling();
ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
for (Instruction instruction : instructions)
{
Expand All @@ -57,7 +57,7 @@ public static Matcher<String> equalsHex(String expectedString)

public static ByteBuffer toBuffer(List<Instruction> instructions)
{
ByteBufferPool bufferPool = new ByteBufferPool.NonPooling();
ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
instructions.forEach(i -> i.encode(bufferPool, accumulator));
assertThat(accumulator.getSize(), is(instructions.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ByteBufferAccumulator()

public ByteBufferAccumulator(ByteBufferPool bufferPool, boolean direct)
{
_bufferPool = (bufferPool == null) ? new ByteBufferPool.NonPooling() : bufferPool;
_bufferPool = (bufferPool == null) ? ByteBufferPool.NON_POOLING : bufferPool;
_direct = direct;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ByteBufferAggregator(ByteBufferPool bufferPool, boolean direct, int start
throw new IllegalArgumentException("startSize must be > 0, was: " + startSize);
if (startSize > maxSize)
throw new IllegalArgumentException("maxSize (" + maxSize + ") must be >= startSize (" + startSize + ")");
_bufferPool = (bufferPool == null) ? new ByteBufferPool.NonPooling() : bufferPool;
_bufferPool = (bufferPool == null) ? ByteBufferPool.NON_POOLING : bufferPool;
_direct = direct;
_maxSize = maxSize;
_currentSize = startSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ByteBufferOutputStream2()

public ByteBufferOutputStream2(ByteBufferPool bufferPool, boolean direct)
{
_accumulator = new ByteBufferAccumulator(bufferPool == null ? new ByteBufferPool.NonPooling() : bufferPool, direct);
_accumulator = new ByteBufferAccumulator(bufferPool == null ? ByteBufferPool.NON_POOLING : bufferPool, direct);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*/
public interface ByteBufferPool
{
ByteBufferPool NON_POOLING = new NonPooling();

/**
* <p>Acquires a {@link RetainableByteBuffer} from this pool.</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static RetainableByteBuffer toRetainableByteBuffer(Resource resource, Byt
throw new IllegalArgumentException("Resource length exceeds 2 GiB: " + resource);
int length = (int)longLength;

bufferPool = bufferPool == null ? new ByteBufferPool.NonPooling() : bufferPool;
bufferPool = bufferPool == null ? ByteBufferPool.NON_POOLING : bufferPool;

// Optimize for PathResource.
Path path = resource.getPath();
Expand Down Expand Up @@ -371,7 +371,7 @@ public PathToSinkCopier(Path path, Content.Sink sink, ByteBufferPool pool, int b
if (first > -1)
channel.position(first);
this.sink = sink;
this.pool = pool == null ? new ByteBufferPool.NonPooling() : pool;
this.pool = pool == null ? ByteBufferPool.NON_POOLING : pool;
this.bufferSize = bufferSize <= 0 ? 4096 : bufferSize;
this.direct = direct;
this.remainingLength = length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BufferedContentSink(Content.Sink delegate, ByteBufferPool bufferPool, boo
if (maxBufferSize < maxAggregationSize)
throw new IllegalArgumentException("maxBufferSize (" + maxBufferSize + ") must be >= maxAggregationSize (" + maxAggregationSize + ")");
_delegate = delegate;
_bufferPool = (bufferPool == null) ? new ByteBufferPool.NonPooling() : bufferPool;
_bufferPool = (bufferPool == null) ? ByteBufferPool.NON_POOLING : bufferPool;
_direct = direct;
_maxBufferSize = maxBufferSize;
_maxAggregationSize = maxAggregationSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public InputStreamContentSource(InputStream inputStream)
public InputStreamContentSource(InputStream inputStream, ByteBufferPool bufferPool)
{
this.inputStream = Objects.requireNonNull(inputStream);
this.bufferPool = bufferPool != null ? bufferPool : new ByteBufferPool.NonPooling();
this.bufferPool = bufferPool != null ? bufferPool : ByteBufferPool.NON_POOLING;
}

public int getBufferSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public PathContentSource(Path path, ByteBufferPool byteBufferPool)
throw new AccessDeniedException(path.toString());
this.path = path;
this.length = Files.size(path);
this.byteBufferPool = byteBufferPool != null ? byteBufferPool : new ByteBufferPool.NonPooling();
this.byteBufferPool = byteBufferPool != null ? byteBufferPool : ByteBufferPool.NON_POOLING;
}
catch (IOException x)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ else if (_baseResource.isAlias())
private ByteBufferPool getByteBufferPool(Context context)
{
if (context == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
Server server = getServer();
if (server == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
return server.getByteBufferPool();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MockConnector extends AbstractConnector
{
public MockConnector(Server server)
{
super(server, server.getThreadPool(), server.getScheduler(), new ByteBufferPool.NonPooling(), 0);
super(server, server.getThreadPool(), server.getScheduler(), ByteBufferPool.NON_POOLING, 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected HttpContent.Factory newHttpContentFactory()
{
return path -> new ResourceHttpContent(memResource, "text/plain")
{
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), new ByteBufferPool.NonPooling(), false).getByteBuffer();
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), ByteBufferPool.NON_POOLING, false).getByteBuffer();

@Override
public ByteBuffer getByteBuffer()
Expand Down Expand Up @@ -215,7 +215,7 @@ protected HttpContent.Factory newHttpContentFactory()
{
return path -> new ResourceHttpContent(memResource, "text/plain")
{
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), new ByteBufferPool.NonPooling(), false).getByteBuffer();
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), ByteBufferPool.NON_POOLING, false).getByteBuffer();

@Override
public ByteBuffer getByteBuffer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void testLargeFrame()
expected.put(toBuffer(Integer.MAX_VALUE));
expected.flip();

Parser parser = new Parser(new ByteBufferPool.NonPooling());
Parser parser = new Parser(ByteBufferPool.NON_POOLING);
assertNull(parser.parse(expected));
assertThat(parser.getPayloadLength(), equalTo(Integer.MAX_VALUE));
}
Expand All @@ -265,7 +265,7 @@ public void testFrameTooLarge()
expected.put(toBuffer(Integer.MAX_VALUE + 1L));
expected.flip();

Parser parser = new Parser(new ByteBufferPool.NonPooling());
Parser parser = new Parser(ByteBufferPool.NON_POOLING);
assertThrows(MessageTooLargeException.class, () -> parser.parse(expected));
}

Expand All @@ -280,7 +280,7 @@ public void testLargestFrame()
expected.put(new byte[]{(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
expected.flip();

Parser parser = new Parser(new ByteBufferPool.NonPooling());
Parser parser = new Parser(ByteBufferPool.NON_POOLING);
assertThrows(MessageTooLargeException.class, () -> parser.parse(expected));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class OutgoingMessageCapture extends CoreSession.Empty implements CoreSes
public BlockingQueue<ByteBuffer> binaryMessages = new LinkedBlockingDeque<>();
public BlockingQueue<String> events = new LinkedBlockingDeque<>();

private final ByteBufferPool bufferPool = new ByteBufferPool.NonPooling();
private final ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
private final MethodHandle wholeTextHandle;
private final MethodHandle wholeBinaryHandle;
private MessageSink messageSink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ public void init() throws ServletException
private static ByteBufferPool getByteBufferPool(ContextHandler contextHandler)
{
if (contextHandler == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
Server server = contextHandler.getServer();
if (server == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
return server.getByteBufferPool();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3516,7 +3516,7 @@ public void testMemoryResourceRangeUsingBufferedHttpContent() throws Exception
context.addServlet(new ServletHolder(defaultServlet), "/");
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain")
{
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), new ByteBufferPool.NonPooling(), false).getByteBuffer();
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), ByteBufferPool.NON_POOLING, false).getByteBuffer();

@Override
public ByteBuffer getByteBuffer()
Expand Down Expand Up @@ -3570,7 +3570,7 @@ public void testMemoryResourceMultipleRangesUsingBufferedHttpContent() throws Ex
context.addServlet(new ServletHolder(defaultServlet), "/");
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain")
{
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), new ByteBufferPool.NonPooling(), false).getByteBuffer();
final ByteBuffer buffer = IOResources.toRetainableByteBuffer(getResource(), ByteBufferPool.NON_POOLING, false).getByteBuffer();

@Override
public ByteBuffer getByteBuffer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public void doStart() throws Exception
private static ByteBufferPool getByteBufferPool(ContextHandler contextHandler)
{
if (contextHandler == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
Server server = contextHandler.getServer();
if (server == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
return server.getByteBufferPool();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ protected Resource resolve(String pathInContext)
private static ByteBufferPool getByteBufferPool(ContextHandler contextHandler)
{
if (contextHandler == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
Server server = contextHandler.getServer();
if (server == null)
return new ByteBufferPool.NonPooling();
return ByteBufferPool.NON_POOLING;
return server.getByteBufferPool();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class OutgoingMessageCapture extends CoreSession.Empty implements CoreSes
public BlockingQueue<ByteBuffer> binaryMessages = new LinkedBlockingDeque<>();
public BlockingQueue<String> events = new LinkedBlockingDeque<>();

private final ByteBufferPool bufferPool = new ByteBufferPool.NonPooling();
private final ByteBufferPool bufferPool = ByteBufferPool.NON_POOLING;
private final MethodHandle wholeTextHandle;
private final MethodHandle wholeBinaryHandle;
private MessageSink messageSink;
Expand Down

0 comments on commit 33feac3

Please sign in to comment.