List of usage examples for io.netty.buffer ByteBufAllocator directBuffer
ByteBuf directBuffer();
From source file:am.ik.sendgrid.util.JsonCodec.java
License:Apache License
static <T> ByteBuf encode(ByteBufAllocator allocator, ObjectMapper objectMapper, T source) { try {// w w w. j a v a 2 s . co m return allocator.directBuffer().writeBytes(objectMapper.writeValueAsBytes(source)); } catch (JsonProcessingException e) { throw Exceptions.propagate(e); } }
From source file:org.apache.bookkeeper.common.allocator.impl.ByteBufAllocatorBuilderTest.java
License:Apache License
@Test public void testUnpooled() { ByteBufAllocator alloc = ByteBufAllocatorBuilder.create().poolingPolicy(PoolingPolicy.UnpooledHeap).build(); ByteBuf buf = alloc.buffer();//ww w. j a va 2s . c o m assertEquals(UnpooledByteBufAllocator.DEFAULT, buf.alloc()); assertTrue(buf.hasArray()); ByteBuf buf2 = alloc.directBuffer(); assertEquals(UnpooledByteBufAllocator.DEFAULT, buf2.alloc()); assertFalse(buf2.hasArray()); }
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 ww . ja v a 2 s . 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 www .j a va 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(); }
From source file:org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutput.java
License:Apache License
FanOutOneBlockAsyncDFSOutput(Configuration conf, FSUtils fsUtils, DistributedFileSystem dfs, DFSClient client,
ClientProtocol namenode, String clientName, String src, long fileId, LocatedBlock locatedBlock,
CryptoCodec cryptoCodec, EventLoop eventLoop, List<Channel> datanodeList, DataChecksum summer,
ByteBufAllocator alloc) {
this.conf = conf;
this.fsUtils = fsUtils;
this.dfs = dfs;
this.client = client;
this.namenode = namenode;
this.fileId = fileId;
this.clientName = clientName;
this.src = src;
this.locatedBlock = locatedBlock;
this.cryptoCodec = cryptoCodec;
this.eventLoop = eventLoop;
this.datanodeList = datanodeList;
this.summer = summer;
this.alloc = alloc;
this.buf = alloc.directBuffer();
this.state = State.STREAMING;
setupReceiver(conf.getInt(DFS_CLIENT_SOCKET_TIMEOUT_KEY, READ_TIMEOUT));
}
From source file:org.apache.hadoop.hbase.util.FanOutOneBlockAsyncDFSOutput.java
License:Apache License
FanOutOneBlockAsyncDFSOutput(Configuration conf, FSUtils fsUtils, DistributedFileSystem dfs, DFSClient client,
ClientProtocol namenode, String clientName, String src, long fileId, LocatedBlock locatedBlock,
EventLoop eventLoop, List<Channel> datanodeList, DataChecksum summer, ByteBufAllocator alloc) {
this.conf = conf;
this.fsUtils = fsUtils;
this.dfs = dfs;
this.client = client;
this.namenode = namenode;
this.fileId = fileId;
this.clientName = clientName;
this.src = src;
this.locatedBlock = locatedBlock;
this.eventLoop = eventLoop;
this.datanodeList = datanodeList;
this.summer = summer;
this.alloc = alloc;
this.buf = alloc.directBuffer();
this.state = State.STREAMING;
setupReceiver(conf.getInt(DFS_CLIENT_SOCKET_TIMEOUT_KEY, HdfsServerConstants.READ_TIMEOUT));
}