Example usage for io.netty.buffer ByteBuf retainedSlice

List of usage examples for io.netty.buffer ByteBuf retainedSlice

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf retainedSlice.

Prototype

public abstract ByteBuf retainedSlice();

Source Link

Document

Returns a retained slice of this buffer's readable bytes.

Usage

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());
}