org.xnio.ByteBufferSlicePool Java Examples

The following examples show how to use org.xnio.ByteBufferSlicePool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TokenAuthenticator.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
private ByteBufferPool createByteBufferPool() {
    long maxMemory = Runtime.getRuntime().maxMemory();
    boolean useDirectBuffers;
    int bufferSize, buffersPerRegion;
    if (maxMemory < 64 * 1024 * 1024) {
        //smaller than 64mb of ram we use 512b buffers
        useDirectBuffers = false;
        bufferSize = 512;
        buffersPerRegion = 10;
    } else if (maxMemory < 128 * 1024 * 1024) {
        //use 1k buffers
        useDirectBuffers = true;
        bufferSize = 1024;
        buffersPerRegion = 10;
    } else {
        //use 16k buffers for best performance
        //as 16k is generally the max amount of data that can be sent in a single write() call
        useDirectBuffers = true;
        bufferSize = 1024 * 16;
        buffersPerRegion = 20;
    }
    BufferAllocator<ByteBuffer> allocator;
    if (useDirectBuffers) {
        allocator = BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR;
    } else {
        allocator = BufferAllocator.BYTE_BUFFER_ALLOCATOR;
    }
    int maxRegionSize = buffersPerRegion * bufferSize;
    ByteBufferSlicePool pool = new ByteBufferSlicePool(allocator, bufferSize, maxRegionSize);
    return new XnioByteBufferPool(pool);
}
 
Example #2
Source File: XnioByteBufUtil.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
static Pooled<ByteBuffer> allocateDirect(ByteBufferSlicePool pool, int initialCapacity) {
    Pooled<ByteBuffer> pooled;
    if (initialCapacity <= pool.getBufferSize()) {
        pooled = pool.allocate();
    } else {
        pooled = new PooledByteBuf(ByteBuffer.allocateDirect(initialCapacity));
    }
    return pooled;
}
 
Example #3
Source File: BufferPoolService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void start(final StartContext context) {
    bufferPool = new ByteBufferSlicePool(directBuffers ? BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR : BufferAllocator.BYTE_BUFFER_ALLOCATOR, bufferSize, buffersPerSlice * bufferSize);
    byteBufferConsumer.accept(bufferPool);
}
 
Example #4
Source File: BufferPoolService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void stop(final StopContext context) {
    byteBufferConsumer.accept(null);
    ((ByteBufferSlicePool) bufferPool).clean();
    bufferPool = null;
}
 
Example #5
Source File: XnioByteBufAllocator.java    From netty-xnio-transport with Apache License 2.0 4 votes vote down vote up
public XnioByteBufAllocator(ByteBufferSlicePool pool) {
    if (pool == null) {
        throw new NullPointerException("pool");
    }
    this.pool = pool;
}
 
Example #6
Source File: XnioTestsuiteUtils.java    From netty-xnio-transport with Apache License 2.0 4 votes vote down vote up
static List<ByteBufAllocator> newAllocators(List<ByteBufAllocator> allocs) {
    List<ByteBufAllocator> allocators = new ArrayList<ByteBufAllocator>(allocs);
    allocators.add(new XnioByteBufAllocator(new ByteBufferSlicePool(1024 * 16, 1024 * 32)));
    return allocators;
}