X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Fio%2FMappedByteBufferPool.java;h=bc9e8147360fb7c9ff752751d353f8a93e27d7ea;hp=b331904c4ef26180e216b09afe245cd92d5d9bcd;hb=ba4f228fa9f72d50991a2218cfd83987ef5d385e;hpb=73ef54a38e3930a1a789cdc6b5fa23cdd4c9d086 diff --git a/lib/jetty/org/eclipse/jetty/io/MappedByteBufferPool.java b/lib/jetty/org/eclipse/jetty/io/MappedByteBufferPool.java index b331904c..bc9e8147 100644 --- a/lib/jetty/org/eclipse/jetty/io/MappedByteBufferPool.java +++ b/lib/jetty/org/eclipse/jetty/io/MappedByteBufferPool.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 @@ -23,6 +23,7 @@ import java.util.Queue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jetty.util.BufferUtil; @@ -56,13 +57,19 @@ public class MappedByteBufferPool implements ByteBufferPool if (result == null) { int capacity = bucket * factor; - result = direct ? BufferUtil.allocateDirect(capacity) : BufferUtil.allocate(capacity); + result = newByteBuffer(capacity, direct); } BufferUtil.clear(result); return result; } + protected ByteBuffer newByteBuffer(int capacity, boolean direct) + { + return direct ? BufferUtil.allocateDirect(capacity) + : BufferUtil.allocate(capacity); + } + @Override public void release(ByteBuffer buffer) { @@ -108,4 +115,20 @@ public class MappedByteBufferPool implements ByteBufferPool { return direct ? directBuffers : heapBuffers; } + + public static class Tagged extends MappedByteBufferPool + { + private final AtomicInteger tag = new AtomicInteger(); + + @Override + protected ByteBuffer newByteBuffer(int capacity, boolean direct) + { + ByteBuffer buffer = super.newByteBuffer(capacity + 4, direct); + buffer.limit(buffer.capacity()); + buffer.putInt(tag.incrementAndGet()); + ByteBuffer slice = buffer.slice(); + BufferUtil.clear(slice); + return slice; + } + } }