]> WPIA git - gigi.git/blobdiff - lib/jetty/org/eclipse/jetty/io/MappedByteBufferPool.java
updating jetty to jetty-9.2.16.v2016040
[gigi.git] / lib / jetty / org / eclipse / jetty / io / MappedByteBufferPool.java
index b331904c4ef26180e216b09afe245cd92d5d9bcd..bc9e8147360fb7c9ff752751d353f8a93e27d7ea 100644 (file)
@@ -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;
+        }
+    }
 }