List of usage examples for io.netty.buffer PooledByteBufAllocator DEFAULT
PooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer PooledByteBufAllocator DEFAULT.
Click Source Link
From source file:reactor.ipc.netty.options.NettyOptions.java
License:Open Source License
static void defaultNettyOptions(AbstractBootstrap<?, ?> bootstrap) { bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); }
From source file:reactor.ipc.netty.options.ServerOptions.java
License:Open Source License
static void defaultServerOptions(ServerBootstrap bootstrap) { bootstrap.localAddress(LOCALHOST_AUTO_PORT).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_BACKLOG, 1000) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.SO_RCVBUF, 1024 * 1024).childOption(ChannelOption.SO_SNDBUF, 1024 * 1024) .childOption(ChannelOption.AUTO_READ, false).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.SO_LINGER, 0).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000); }
From source file:ru.releng.shameonyou.core.graphite.GraphiteClient.java
License:Apache License
private Bootstrap configureBootstrap(Bootstrap bootstrap, EventLoopGroup eventLoopGroup) { return bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class) .remoteAddress(graphiteHost, graphitePort).option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1024 * 1024) .option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 128 * 1024) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(new ChannelInitializer<SocketChannel>() { @Override/*from w w w . ja v a 2 s. co m*/ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("decoder", decoder); ch.pipeline().addLast("encoder", encoder); ch.pipeline().addLast("writeTimeoutHandler", new WriteTimeoutHandler(1)); ch.pipeline().addLast("handler", handler); } }); }
From source file:rxweb.engine.server.netty.NettyServer.java
License:Apache License
private void init() { this.bootstrap.option(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).group(new NioEventLoopGroup()) .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() { @Override/*from w w w .j a v a 2 s. co m*/ protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler()).addLast(new HttpServerCodec()) .addLast(new NettyServerCodecHandlerAdapter()) .addLast(new ChannelInboundHandlerAdapter() { private CompletableFuture<Channel> headersSent; private final Logger logger = LoggerFactory.getLogger(getClass()); @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ServerRequest) { handleRequest(ctx, (ServerRequest) msg); } else { super.channelRead(ctx, msg); } } private void handleRequest(ChannelHandlerContext ctx, ServerRequest request) { List<ServerHandler> handlers = handlerResolver.resolve(request); if (handlers.isEmpty()) { this.logger.info("No handler found for request " + request.getUri()); } // In order to keep simple, we take the first handler ServerHandler handler = handlers.get(0); ServerResponse response = new NettyServerResponseAdapter(request); handler.handle(request, response); response.getContent().subscribe(new Subscriber<ByteBuffer>() { @Override public void onNext(ByteBuffer buffer) { if (headersSent != null) { ctx.writeAndFlush(buffer); } else { headersSent = CompletableFutureUtils .fromChannelFuture(ctx.write(response)); headersSent.handle((channel, t) -> { if (channel != null) { response.setStatusAndHeadersSent(true); ctx.write(buffer); } else { logger.error(t.toString()); } return channel; }); } } @Override public void onError(Throwable e) { logger.error("Error in response content observable: " + e); } @Override public void onCompleted() { if (response.isStatusAndHeadersSent()) { ctx.write(new DefaultLastHttpContent()); ctx.flush(); ctx.close(); } else if (headersSent != null) { headersSent.thenRun(() -> { ctx.write(new DefaultLastHttpContent()); ctx.flush(); ctx.close(); }); } else { CompletableFutureUtils.fromChannelFuture(ctx.write(response)) .thenRun(() -> { response.setStatusAndHeadersSent(true); ctx.write(new DefaultLastHttpContent()); ctx.flush(); ctx.close(); }); } } }); } }); } }); }
From source file:sailfish.remoting.channel.AbstractConfigurableExchangeChannelGroup.java
License:Apache License
private Bootstrap newBootstrap() { Bootstrap boot = new Bootstrap(); boot.channel(NettyPlatformIndependent.channelClass()); boot.option(ChannelOption.TCP_NODELAY, true); // replace by heart beat boot.option(ChannelOption.SO_KEEPALIVE, false); // default is pooled direct // ByteBuf(io.netty.util.internal.PlatformDependent.DIRECT_BUFFER_PREFERRED) boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // 32kb(for massive long connections, See // http://www.infoq.com/cn/articles/netty-million-level-push-service-design-points) // 64kb(RocketMq remoting default value) boot.option(ChannelOption.SO_SNDBUF, 32 * 1024); boot.option(ChannelOption.SO_RCVBUF, 32 * 1024); // temporary settings, need more tests boot.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)); //default is true, reduce thread context switching boot.option(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, true); return boot;//from w ww .j a va 2 s . com }
From source file:sailfish.remoting.DefaultServer.java
License:Apache License
private ServerBootstrap newServerBootstrap() { ServerBootstrap serverBoot = new ServerBootstrap(); serverBoot.channel(NettyPlatformIndependent.serverChannelClass()); // connections wait for accept serverBoot.option(ChannelOption.SO_BACKLOG, 1024); serverBoot.option(ChannelOption.SO_REUSEADDR, true); // replace by heart beat serverBoot.childOption(ChannelOption.SO_KEEPALIVE, false); serverBoot.childOption(ChannelOption.TCP_NODELAY, true); serverBoot.childOption(ChannelOption.SO_SNDBUF, 32 * 1024); serverBoot.childOption(ChannelOption.SO_RCVBUF, 32 * 1024); // temporary settings, need more tests serverBoot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)); serverBoot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); //default is true, reduce thread context switching serverBoot.childOption(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, true); return serverBoot; }
From source file:starbounddata.packets.Packet.java
License:Open Source License
/** * Recommended: For connections StarNub usage. * <p>/* w ww . j ava 2 s . c o m*/ * Uses: This method will write to a {@link io.netty.buffer.ByteBuf} using this packets fields * <p> * * @return ByteBuf representing the ByteBuf to write to socket */ protected ByteBuf packetToMessageEncoder() { ByteBuf msgOut = PooledByteBufAllocator.DEFAULT.directBuffer(); this.write(msgOut); int payloadLengthOut = msgOut.readableBytes(); byte[] dataOut; if (payloadLengthOut > 100) { dataOut = Zlib.compress(msgOut.readBytes(payloadLengthOut).array()); payloadLengthOut = -dataOut.length; } else { dataOut = msgOut.readBytes(payloadLengthOut).array(); } msgOut.clear(); msgOut.writeByte(PACKET_ID); writeSVLQPacketEncoder(msgOut, payloadLengthOut); msgOut.writeBytes(dataOut); return msgOut; }
From source file:tachyon.worker.netty.NettyDataServer.java
License:Apache License
private ServerBootstrap createBootstrap() { final ServerBootstrap boot = createBootstrapOfType( mTachyonConf.getEnum(Constants.WORKER_NETWORK_NETTY_CHANNEL, ChannelType.class)); // use pooled buffers boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); boot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // set write buffer // this is the default, but its recommended to set it in case of change in future netty. boot.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_WATERMARK_HIGH)); boot.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_WATERMARK_LOW)); // more buffer settings on Netty socket option, one can tune them by specifying // properties, e.g.: // tachyon.worker.network.netty.backlog=50 // tachyon.worker.network.netty.buffer.send=64KB // tachyon.worker.network.netty.buffer.receive=64KB if (mTachyonConf.containsKey(Constants.WORKER_NETTY_BACKLOG)) { boot.option(ChannelOption.SO_BACKLOG, mTachyonConf.getInt(Constants.WORKER_NETTY_BACKLOG)); }/*from www. java 2 s .c o m*/ if (mTachyonConf.containsKey(Constants.WORKER_NETTY_SEND_BUFFER)) { boot.option(ChannelOption.SO_SNDBUF, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_SEND_BUFFER)); } if (mTachyonConf.containsKey(Constants.WORKER_NETTY_RECEIVE_BUFFER)) { boot.option(ChannelOption.SO_RCVBUF, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_RECEIVE_BUFFER)); } return boot; }
From source file:tonivade.redis.RedisClient.java
License:Open Source License
public void start() { workerGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors()); initHandler = new RedisInitializerHandler(this); connectionHandler = new RedisConnectionHandler(this); bootstrap = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.SO_RCVBUF, BUFFER_SIZE).option(ChannelOption.SO_SNDBUF, BUFFER_SIZE) .option(ChannelOption.SO_KEEPALIVE, true).handler(initHandler); try {/*from w w w. j a va 2 s .c om*/ connect(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:tonivade.redis.RedisServer.java
License:Open Source License
public void start() { bossGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2); acceptHandler = new RedisInitializerHandler(this); connectionHandler = new RedisConnectionHandler(this); bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(acceptHandler) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.SO_RCVBUF, BUFFER_SIZE).option(ChannelOption.SO_SNDBUF, BUFFER_SIZE) .childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); future = bootstrap.bind(host, port); // Bind and start to accept incoming connections. future.syncUninterruptibly();/*from www.ja v a 2 s . com*/ LOGGER.info(() -> "server started: " + host + ":" + port); }