//
// ========================================================================
-// 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
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;
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)
{
{
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;
+ }
+ }
}