List of usage examples for io.netty.buffer ByteBuf retainedSlice
public abstract ByteBuf retainedSlice();
From source file:org.apache.pulsar.client.impl.RawMessageImpl.java
License:Apache License
public RawMessageImpl(MessageIdData id, ByteBuf headersAndPayload) { this.id = id; this.headersAndPayload = headersAndPayload.retainedSlice(); }
From source file:org.elasticsearch.http.nio.PagedByteBufTests.java
License:Apache License
public void testReleasingPage() { AtomicInteger integer = new AtomicInteger(0); int pageCount = randomInt(10) + 1; ArrayList<InboundChannelBuffer.Page> pages = new ArrayList<>(); for (int i = 0; i < pageCount; ++i) { pages.add(new InboundChannelBuffer.Page(ByteBuffer.allocate(10), integer::incrementAndGet)); }/* w w w . j ava 2s .com*/ ByteBuf byteBuf = PagedByteBuf.byteBufFromPages(pages.toArray(new InboundChannelBuffer.Page[0])); assertEquals(0, integer.get()); byteBuf.retain(); byteBuf.release(); assertEquals(0, integer.get()); ByteBuf secondBuf = byteBuf.retainedSlice(); byteBuf.release(); assertEquals(0, integer.get()); secondBuf.release(); assertEquals(pageCount, integer.get()); }