2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.io;
21 import java.nio.ByteBuffer;
24 * <p>A {@link ByteBuffer} pool.</p>
25 * <p>Acquired buffers may be {@link #release(ByteBuffer) released} but they do not need to;
26 * if they are released, they may be recycled and reused, otherwise they will be garbage
27 * collected as usual.</p>
29 public interface ByteBufferPool
32 * <p>Requests a {@link ByteBuffer} of the given size.</p>
33 * <p>The returned buffer may have a bigger capacity than the size being
34 * requested but it will have the limit set to the given size.</p>
36 * @param size the size of the buffer
37 * @param direct whether the buffer must be direct or not
38 * @return the requested buffer
39 * @see #release(ByteBuffer)
41 public ByteBuffer acquire(int size, boolean direct);
44 * <p>Returns a {@link ByteBuffer}, usually obtained with {@link #acquire(int, boolean)}
45 * (but not necessarily), making it available for recycling and reuse.</p>
47 * @param buffer the buffer to return
48 * @see #acquire(int, boolean)
50 public void release(ByteBuffer buffer);