Example usage for io.netty.buffer UnpooledByteBufAllocator DEFAULT

List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT

Introduction

In this page you can find the example usage for io.netty.buffer UnpooledByteBufAllocator DEFAULT.

Prototype

UnpooledByteBufAllocator DEFAULT

To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.

Click Source Link

Document

Default instance which uses leak-detection for direct buffers.

Usage

From source file:org.asynchttpclient.netty.channel.ChannelManager.java

License:Open Source License

private Bootstrap newBootstrap(ChannelFactory<? extends Channel> channelFactory, EventLoopGroup eventLoopGroup,
        AsyncHttpClientConfig config) {//w  w w  . j  av  a 2s .  c  om
    @SuppressWarnings("deprecation")
    Bootstrap bootstrap = new Bootstrap().channelFactory(channelFactory).group(eventLoopGroup)//
            // default to PooledByteBufAllocator
            .option(ChannelOption.ALLOCATOR,
                    config.isUsePooledMemory() ? PooledByteBufAllocator.DEFAULT
                            : UnpooledByteBufAllocator.DEFAULT)//
            .option(ChannelOption.TCP_NODELAY, config.isTcpNoDelay())//
            .option(ChannelOption.SO_REUSEADDR, config.isSoReuseAddress())//
            .option(ChannelOption.AUTO_CLOSE, false);

    if (config.getConnectTimeout() > 0) {
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
    }

    if (config.getSoLinger() >= 0) {
        bootstrap.option(ChannelOption.SO_LINGER, config.getSoLinger());
    }

    if (config.getSoSndBuf() >= 0) {
        bootstrap.option(ChannelOption.SO_SNDBUF, config.getSoSndBuf());
    }

    if (config.getSoRcvBuf() >= 0) {
        bootstrap.option(ChannelOption.SO_RCVBUF, config.getSoRcvBuf());
    }

    for (Entry<ChannelOption<Object>, Object> entry : config.getChannelOptions().entrySet()) {
        bootstrap.option(entry.getKey(), entry.getValue());
    }

    return bootstrap;
}

From source file:org.ballerinalang.broker.BallerinaBrokerByteBuf.java

License:Open Source License

public BallerinaBrokerByteBuf(BValue value) {
    super(UnpooledByteBufAllocator.DEFAULT, 0, 0);
    this.value = value;
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test
public void shouldReturnSingleResponseIfAllowedByMaxFrameSize() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(10000);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(100).forLength(200);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(300).forLength(100);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);
    ReadVResponse response1 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response2 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);

    assertThat(response1.getSegmentLengths(), hasItems(200, 100));
    assertThat(response2, is(nullValue()));
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test(expected = IllegalStateException.class)
public void shouldFailReadsBiggerThanMaxFrameSize() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(10000);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(100).forLength(2000);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);
    response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test
public void shouldRespectMaxFrameSize() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(10000);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(100).forLength(100);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(300).forLength(1000);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);
    ReadVResponse response1 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response2 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response3 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);

    assertThat(response1.getSegmentLengths(), hasItems(100, 100));
    assertThat(response2.getSegmentLengths(), hasItems(1000));
    assertThat(response3, is(nullValue()));
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test
public void shouldRespectEndOfFile() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(10000);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(9700).forLength(500);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);
    ReadVResponse response1 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response2 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);

    assertThat(response1.getSegmentLengths(), hasItems(300));
    assertThat(response2, is(nullValue()));
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test
public void shouldUsePositionIndependentRead() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(10000);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(100).forLength(100);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(200).forLength(100);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(400).forLength(1000);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(9700).forLength(1000);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);
    ReadVResponse response1 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response2 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response3 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);

    verify(channel(SOME_FH)).read(any(ByteBuffer.class), eq(100L));
    verify(channel(SOME_FH)).read(any(ByteBuffer.class), eq(200L));
    verify(channel(SOME_FH)).read(any(ByteBuffer.class), eq(400L));
    verify(channel(SOME_FH)).read(any(ByteBuffer.class), eq(9700L));
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test
public void shouldPackTruncatedReadsInSingleFrameIfPossible() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(400);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(100).forLength(200);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(300).forLength(1000);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);

    ReadVResponse response1 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
    ReadVResponse response2 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);

    assertThat(response1.getSegmentLengths(), hasItems(200, 100));
    assertThat(response2, is(nullValue()));
}

From source file:org.dcache.xrootd.stream.ChunkedFileChannelReadvResponseTest.java

License:Open Source License

@Test(expected = IllegalStateException.class)
public void shouldNotOverflowWithLargeRequests() throws Exception {
    givenFileDescriptor().withFileHandle(SOME_FH).withSize(Integer.MAX_VALUE);
    givenReadRequest().forFileHandle(SOME_FH).atOffset(0).forLength(Integer.MAX_VALUE);

    AbstractChunkedReadvResponse response = aResponseWithMaxFrameSizeOf(1024);

    ReadVResponse response1 = response.nextChunk(UnpooledByteBufAllocator.DEFAULT);
}

From source file:org.ebayopensource.scc.cache.NettyResponseDeserializer.java

License:Apache License

@Override
public FullHttpResponse deserialize(CacheResponse cacheResp) {
    CompositeByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.compositeBuffer();
    if (cacheResp.getContent() != null) {
        byteBuf.capacity(cacheResp.getContent().length);
        byteBuf.setBytes(0, cacheResp.getContent());
        byteBuf.writerIndex(cacheResp.getContent().length);
    }/*  w  w  w  .j  a va 2  s  .  c om*/
    DefaultFullHttpResponse response = new DefaultFullHttpResponse(
            HttpVersion.valueOf(cacheResp.getProtocalVersion()),
            new HttpResponseStatus(cacheResp.getCode(), cacheResp.getReasonPhrase()), byteBuf, true);
    HttpHeaders headers = response.headers();
    List<CacheEntry<String, String>> cacheHeaders = cacheResp.getHeaders();
    for (Entry<String, String> entry : cacheHeaders) {
        headers.add(entry.getKey(), entry.getValue());
    }

    HttpHeaders trailingHeaders = response.trailingHeaders();
    List<CacheEntry<String, String>> cacheTrailingHeaders = cacheResp.getTrailingHeaders();
    for (Entry<String, String> entry : cacheTrailingHeaders) {
        trailingHeaders.add(entry.getKey(), entry.getValue());
    }

    return response;
}