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