Example usage for io.netty.buffer PooledByteBufAllocator DEFAULT

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

Introduction

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

Prototype

PooledByteBufAllocator DEFAULT

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

Click Source Link

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) {/*from   www . ja v 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.cloudfoundry.reactor._DefaultConnectionContext.java

License:Apache License

@PostConstruct
void monitorByteBufAllocator() {
    try {/*from w ww .  jav a2  s  .  c o m*/
        ObjectName name = getByteBufAllocatorObjectName();

        if (ManagementFactory.getPlatformMBeanServer().isRegistered(name)) {
            this.logger.warn(
                    "MBean '{}' is already registered and will be removed. You should only have a single DefaultConnectionContext per endpoint.",
                    name);
            ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
        }

        ManagementFactory.getPlatformMBeanServer()
                .registerMBean(new ByteBufAllocatorMetricProviderWrapper(PooledByteBufAllocator.DEFAULT), name);
    } catch (JMException e) {
        this.logger.error("Unable to register ByteBufAllocator MBean", e);
    }
}

From source file:org.curioswitch.curiostack.gcloud.core.auth.ServiceAccountAccessTokenProvider.java

License:Open Source License

@Override
ByteBuf refreshRequestContent(Type type) {
    long currentTimeMillis = clock().millis();
    String assertion = createAssertion(type, currentTimeMillis);
    QueryStringEncoder formEncoder = new QueryStringEncoder("");
    formEncoder.addParam("grant_type", GRANT_TYPE);
    formEncoder.addParam("assertion", assertion);
    String contentWithQuestionMark = formEncoder.toString();

    ByteBufAllocator alloc = RequestContext.mapCurrent(RequestContext::alloc,
            () -> PooledByteBufAllocator.DEFAULT);
    assert alloc != null;
    ByteBuf content = alloc.buffer(contentWithQuestionMark.length() - 1);
    ByteBufUtil.writeAscii(content, contentWithQuestionMark.substring(1));
    return content;
}

From source file:org.curioswitch.curiostack.gcloud.storage.StorageClient.java

License:Open Source License

public CompletableFuture<FileWriter> createFile(String filename, Map<String, String> metadata) {
    return createFile(filename, metadata, CommonPools.workerGroup().next(), PooledByteBufAllocator.DEFAULT);
}

From source file:org.curioswitch.curiostack.gcloud.storage.StorageClient.java

License:Open Source License

public CompletableFuture<FileWriter> createFile(FileRequest request) {
    return createFile(request, CommonPools.workerGroup().next(), PooledByteBufAllocator.DEFAULT);
}

From source file:org.curioswitch.curiostack.gcloud.storage.StorageClient.java

License:Open Source License

/**
 * Reads the contents of a file from cloud storage. Ownership of the returned {@link ByteBuf} is
 * transferred to the caller, which must release it. The future will complete with {@code null} if
 * the file is not found./*from  w  w w  . j  ava 2s . c  om*/
 */
public CompletableFuture<ByteBuf> readFile(String filename) {
    return readFile(filename, CommonPools.workerGroup().next(), PooledByteBufAllocator.DEFAULT);
}

From source file:org.curioswitch.curiostack.gcloud.storage.StorageClient.java

License:Open Source License

public CompletableFuture<Void> updateFileMetadata(String filename, Map<String, String> metadata) {
    return updateFileMetadata(filename, metadata, CommonPools.workerGroup().next(),
            PooledByteBufAllocator.DEFAULT);
}

From source file:org.curioswitch.curiostack.gcloud.storage.StorageClient.java

License:Open Source License

public CompletableFuture<Void> compose(ComposeRequest request) {
    return compose(request, CommonPools.workerGroup().next(), PooledByteBufAllocator.DEFAULT);
}

From source file:org.curioswitch.gradle.plugins.gcloud.buildcache.CloudStorageBuildCacheService.java

License:Open Source License

@Override
public void store(BuildCacheKey buildCacheKey, BuildCacheEntryWriter buildCacheEntryWriter) {
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer((int) buildCacheEntryWriter.getSize());

    try {//from   w w  w .  j  ava  2s .c o  m
        try (ByteBufOutputStream os = new ByteBufOutputStream(buf)) {
            buildCacheEntryWriter.writeTo(os);
        } catch (IOException e) {
            logger.warn("Couldn't write cache entry to buffer.", e);
            return;
        }

        FileWriter writer = cloudStorage.createFile(buildCacheKey.getHashCode(), ImmutableMap.of()).join();
        while (buf.readableBytes() > 0) {
            ByteBuf chunk = buf.readRetainedSlice(Math.min(buf.readableBytes(), 10 * 4 * 256 * 1000));
            if (buf.readableBytes() > 0) {
                getUnchecked(writer.write(chunk));
            } else {
                writer.writeAndClose(chunk).join();
            }
        }
    } catch (Throwable t) {
        logger.warn("Exception writing to cloud storage, ignoring.", t);
    } finally {
        buf.release();
    }
}

From source file:org.ddpush.im.v1.node.pushlistener.NettyPushListener.java

License:Apache License

public void initChannel() throws Exception {
    bossGroup = new EpollEventLoopGroup();
    workerGroup = new EpollEventLoopGroup(pushListenerWorkerNum,
            new ThreadFactoryWithName(NettyPushListener.class));
    serverBootstarp = new ServerBootstrap().group(bossGroup, workerGroup)
            .channel(EpollServerSocketChannel.class).option(ChannelOption.SO_TIMEOUT, sockTimout)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .option(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .childOption(ChannelOption.TCP_NODELAY, true).childHandler(pushListenerChannelInitializer);

    serverBootstarp.bind(port).sync();/*  ww  w.  ja v  a 2  s .c  o m*/

    logger.info("Netty TCP Push Listener nio provider: {} with {} workers",
            serverBootstarp.getClass().getCanonicalName(), pushListenerWorkerNum);
}