org.xnio.BufferAllocator Java Examples

The following examples show how to use org.xnio.BufferAllocator. 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: DirectBufferCache.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator, int maxAge) {
    this.sliceSize = sliceSize;
    this.pool = new LimitedBufferSlicePool(bufferAllocator, sliceSize, sliceSize * slicesPerPage, maxMemory / (sliceSize * slicesPerPage));
    this.cache = new ConcurrentHashMap<>(16);
    this.accessQueue = ConcurrentDirectDeque.newInstance();
    this.maxAge = maxAge;
}
 
Example #2
Source File: LimitedBufferSlicePool.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new instance.
 *
 * @param allocator the buffer allocator to use
 * @param bufferSize the size of each buffer
 * @param maxRegionSize the maximum region size for each backing buffer
 * @param maxRegions the maximum regions to create, zero for unlimited
 */
public LimitedBufferSlicePool(final BufferAllocator<ByteBuffer> allocator, final int bufferSize, final int maxRegionSize, final int maxRegions) {
    if (bufferSize <= 0) {
        throw new IllegalArgumentException("Buffer size must be greater than zero");
    }
    if (maxRegionSize < bufferSize) {
        throw new IllegalArgumentException("Maximum region size must be greater than or equal to the buffer size");
    }
    buffersPerRegion = maxRegionSize / bufferSize;
    this.bufferSize = bufferSize;
    this.allocator = allocator;
    this.maxRegions = maxRegions;
}
 
Example #3
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 #4
Source File: DirectBufferCache.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory) {
    this(sliceSize, slicesPerPage, maxMemory, BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR);
}
 
Example #5
Source File: DirectBufferCache.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator) {
    this(sliceSize, slicesPerPage, maxMemory, bufferAllocator, -1);
}
 
Example #6
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 #7
Source File: LimitedBufferSlicePool.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Construct a new instance.
 *
 * @param allocator the buffer allocator to use
 * @param bufferSize the size of each buffer
 * @param maxRegionSize the maximum region size for each backing buffer
 */
public LimitedBufferSlicePool(BufferAllocator<ByteBuffer> allocator, int bufferSize, int maxRegionSize) {
    this(allocator, bufferSize, maxRegionSize, 0);
}
 
Example #8
Source File: LimitedBufferSlicePool.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Construct a new instance, using a direct buffer allocator.
 *
 * @param bufferSize the size of each buffer
 * @param maxRegionSize the maximum region size for each backing buffer
 */
public LimitedBufferSlicePool(final int bufferSize, final int maxRegionSize) {
    this(BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR, bufferSize, maxRegionSize);
}