package org.glassfish.grizzly.memory;
import java.nio.ByteBuffer;
import org.glassfish.grizzly.ThreadCache;
public final class ByteBufferArray extends AbstractBufferArray<ByteBuffer> {
private static final ThreadCache.CachedTypeIndex<ByteBufferArray> CACHE_IDX =
ThreadCache.obtainIndex(ByteBufferArray.class,
Integer.getInteger(ByteBufferArray.class.getName() + "bba-cache-size", 4));
public static ByteBufferArray create() {
final ByteBufferArray array = ThreadCache.takeFromCache(CACHE_IDX);
if (array != null) {
return array;
}
return new ByteBufferArray();
}
private ByteBufferArray() {
super(ByteBuffer.class);
}
@Override
public void recycle() {
super.recycle();
ThreadCache.putToCache(CACHE_IDX, this);
}
@Override
protected void setPositionLimit(final ByteBuffer buffer,
final int position, final int limit) {
Buffers.setPositionLimit(buffer, position, limit);
}
@Override
protected int getPosition(final ByteBuffer buffer) {
return buffer.position();
}
@Override
protected int getLimit(final ByteBuffer buffer) {
return buffer.limit();
}
}