Example usage for io.netty.buffer ByteBufAllocator heapBuffer

List of usage examples for io.netty.buffer ByteBufAllocator heapBuffer

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufAllocator heapBuffer.

Prototype

ByteBuf heapBuffer();

Source Link

Document

Allocate a heap ByteBuf .

Usage

From source file:com.corundumstudio.socketio.parser.Encoder.java

License:Apache License

public ByteBuf allocateBuffer(ByteBufAllocator allocator) {
    if (configuration.isPreferDirectBuffer()) {
        return allocator.ioBuffer();
    }/*from w w w .j  a  v  a 2 s. c o m*/

    return allocator.heapBuffer();
}

From source file:org.apache.bookkeeper.common.allocator.impl.ByteBufAllocatorBuilderTest.java

License:Apache License

@Test
public void testPooled() {
    PooledByteBufAllocator pooledAlloc = new PooledByteBufAllocator(true);

    ByteBufAllocator alloc = ByteBufAllocatorBuilder.create().poolingPolicy(PoolingPolicy.PooledDirect)
            .pooledAllocator(pooledAlloc).build();

    assertTrue(alloc.isDirectBufferPooled());

    ByteBuf buf1 = alloc.buffer();// w  w w  .j a  v a2s.  c  o  m
    assertEquals(pooledAlloc, buf1.alloc());
    assertFalse(buf1.hasArray());
    buf1.release();

    ByteBuf buf2 = alloc.directBuffer();
    assertEquals(pooledAlloc, buf2.alloc());
    assertFalse(buf2.hasArray());
    buf2.release();

    ByteBuf buf3 = alloc.heapBuffer();
    assertEquals(pooledAlloc, buf3.alloc());
    assertTrue(buf3.hasArray());
    buf3.release();
}

From source file:org.apache.bookkeeper.common.allocator.impl.ByteBufAllocatorBuilderTest.java

License:Apache License

@Test
public void testPooledWithDefaultAllocator() {
    ByteBufAllocator alloc = ByteBufAllocatorBuilder.create().poolingPolicy(PoolingPolicy.PooledDirect)
            .poolingConcurrency(3).build();

    assertTrue(alloc.isDirectBufferPooled());

    ByteBuf buf1 = alloc.buffer();//from ww  w  .  j av a  2 s  . c  o m
    assertEquals(PooledByteBufAllocator.class, buf1.alloc().getClass());
    assertEquals(3, ((PooledByteBufAllocator) buf1.alloc()).metric().numDirectArenas());
    assertFalse(buf1.hasArray());
    buf1.release();

    ByteBuf buf2 = alloc.directBuffer();
    assertFalse(buf2.hasArray());
    buf2.release();

    ByteBuf buf3 = alloc.heapBuffer();
    assertTrue(buf3.hasArray());
    buf3.release();
}