List of usage examples for io.netty.channel ChannelOption SO_RCVBUF
ChannelOption SO_RCVBUF
To view the source code for io.netty.channel ChannelOption SO_RCVBUF.
Click Source Link
From source file:reactor.io.net.impl.netty.udp.NettyDatagramServer.java
License:Apache License
public NettyDatagramServer(@Nonnull Environment env, @Nonnull Dispatcher dispatcher, @Nullable InetSocketAddress listenAddress, @Nullable final NetworkInterface multicastInterface, @Nonnull final ServerSocketOptions options, @Nullable Codec<Buffer, IN, OUT> codec) { super(env, dispatcher, listenAddress, multicastInterface, options, codec); if (options instanceof NettyServerSocketOptions) { this.nettyOptions = (NettyServerSocketOptions) options; } else {/*from w w w .ja va 2 s .co m*/ this.nettyOptions = null; } if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { int ioThreadCount = getDefaultEnvironment().getIntProperty("reactor.udp.ioThreadCount", Environment.PROCESSORS); this.ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-udp-io")); } final InternetProtocolFamily family = toNettyFamily(options.protocolFamily()); this.bootstrap = new Bootstrap().group(ioGroup).option(ChannelOption.SO_RCVBUF, options.rcvbuf()) .option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_REUSEADDR, options.reuseAddr()).option(ChannelOption.AUTO_READ, false) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.timeout()) .channelFactory(new ChannelFactory<Channel>() { @Override public Channel newChannel() { return new NioDatagramChannel(family); } }); if (null != listenAddress) { bootstrap.localAddress(listenAddress); } else { bootstrap.localAddress(NetUtil.LOCALHOST, 3000); } if (null != multicastInterface) { bootstrap.option(ChannelOption.IP_MULTICAST_IF, multicastInterface); } }
From source file:reactor.io.net.netty.tcp.NettyTcpClient.java
License:Apache License
/** * Creates a new NettyTcpClient that will use the given {@code env} for configuration and the given {@code * reactor} to//from w w w . jav a 2 s . c o m * send events. The number of IO threads used by the client is configured by the environment's {@code * reactor.tcp.ioThreadCount} property. In its absence the number of IO threads will be equal to the {@link * Environment#PROCESSORS number of available processors}. </p> The client will connect to the given {@code * connectAddress}, configuring its socket using the given {@code opts}. The given {@code codec} will be used for * encoding and decoding of data. * * @param env The configuration environment * @param reactor The reactor used to send events * @param connectAddress The address the client will connect to * @param options The configuration options for the client's socket * @param sslOptions The SSL configuration options for the client's socket * @param codec The codec used to encode and decode data * @param consumers The consumers that will interact with the connection */ public NettyTcpClient(@Nonnull Environment env, @Nonnull EventBus reactor, @Nonnull InetSocketAddress connectAddress, @Nonnull final ClientSocketOptions options, @Nullable final SslOptions sslOptions, @Nullable Codec<Buffer, IN, OUT> codec, @Nonnull Collection<Consumer<NetChannel<IN, OUT>>> consumers) { super(env, reactor, connectAddress, options, sslOptions, codec, consumers); this.connectAddress = connectAddress; if (options instanceof NettyClientSocketOptions) { this.nettyOptions = (NettyClientSocketOptions) options; } else { this.nettyOptions = null; } if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { int ioThreadCount = env.getProperty("reactor.tcp.ioThreadCount", Integer.class, Environment.PROCESSORS); this.ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-tcp-io")); } this.bootstrap = new Bootstrap().group(ioGroup).channel(NioSocketChannel.class) .option(ChannelOption.SO_RCVBUF, options.rcvbuf()).option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_KEEPALIVE, options.keepAlive()) .option(ChannelOption.SO_LINGER, options.linger()) .option(ChannelOption.TCP_NODELAY, options.tcpNoDelay()).remoteAddress(this.connectAddress) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(options.timeout()); if (null != sslOptions) { SSLEngine ssl = new SSLEngineSupplier(sslOptions, true).get(); if (log.isDebugEnabled()) { log.debug("SSL enabled using keystore {}", (null != sslOptions.keystoreFile() ? sslOptions.keystoreFile() : "<DEFAULT>")); } ch.pipeline().addLast(new SslHandler(ssl)); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); } }); this.connectionSupplier = new Supplier<ChannelFuture>() { @Override public ChannelFuture get() { if (!closing) { return bootstrap.connect(getConnectAddress()); } else { return null; } } }; }
From source file:reactor.io.net.netty.tcp.NettyTcpServer.java
License:Apache License
protected NettyTcpServer(@Nonnull Environment env, @Nonnull EventBus reactor, @Nullable InetSocketAddress listenAddress, final ServerSocketOptions options, final SslOptions sslOptions, @Nullable Codec<Buffer, IN, OUT> codec, @Nonnull Collection<Consumer<NetChannel<IN, OUT>>> consumers) { super(env, reactor, listenAddress, options, sslOptions, codec, consumers); if (options instanceof NettyServerSocketOptions) { this.nettyOptions = (NettyServerSocketOptions) options; } else {/* w w w . j a va 2 s .c o m*/ this.nettyOptions = null; } int selectThreadCount = env.getProperty("reactor.tcp.selectThreadCount", Integer.class, Environment.PROCESSORS / 2); int ioThreadCount = env.getProperty("reactor.tcp.ioThreadCount", Integer.class, Environment.PROCESSORS); this.selectorGroup = new NioEventLoopGroup(selectThreadCount, new NamedDaemonThreadFactory("reactor-tcp-select")); if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { this.ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-tcp-io")); } this.bootstrap = new ServerBootstrap().group(selectorGroup, ioGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, options.backlog()) .option(ChannelOption.SO_RCVBUF, options.rcvbuf()).option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_REUSEADDR, options.reuseAddr()) .localAddress((null == listenAddress ? new InetSocketAddress(3000) : listenAddress)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel ch) throws Exception { SocketChannelConfig config = ch.config(); config.setReceiveBufferSize(options.rcvbuf()); config.setSendBufferSize(options.sndbuf()); config.setKeepAlive(options.keepAlive()); config.setReuseAddress(options.reuseAddr()); config.setSoLinger(options.linger()); config.setTcpNoDelay(options.tcpNoDelay()); if (log.isDebugEnabled()) { log.debug("CONNECT {}", ch); } if (null != sslOptions) { SSLEngine ssl = new SSLEngineSupplier(sslOptions, false).get(); if (log.isDebugEnabled()) { log.debug("SSL enabled using keystore {}", (null != sslOptions.keystoreFile() ? sslOptions.keystoreFile() : "<DEFAULT>")); } ch.pipeline().addLast(new SslHandler(ssl)); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (log.isDebugEnabled()) { log.debug("CLOSE {}", ch); } close(ch); } }); } }); }
From source file:reactor.io.net.netty.udp.NettyDatagramServer.java
License:Apache License
public NettyDatagramServer(@Nonnull Environment env, @Nonnull EventBus reactor, @Nullable InetSocketAddress listenAddress, @Nullable final NetworkInterface multicastInterface, @Nonnull final ServerSocketOptions options, @Nullable Codec<Buffer, IN, OUT> codec, Collection<Consumer<NetChannel<IN, OUT>>> consumers) { super(env, reactor, listenAddress, multicastInterface, options, codec, consumers); if (options instanceof NettyServerSocketOptions) { this.nettyOptions = (NettyServerSocketOptions) options; } else {// www. j av a2 s. com this.nettyOptions = null; } if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { int ioThreadCount = env.getProperty("reactor.udp.ioThreadCount", Integer.class, Environment.PROCESSORS); this.ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-udp-io")); } final NettyNetChannelInboundHandler inboundHandler = new NettyNetChannelInboundHandler() { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { super.channelRead(ctx, ((DatagramPacket) msg).content()); } }; this.bootstrap = new Bootstrap().group(ioGroup).option(ChannelOption.SO_RCVBUF, options.rcvbuf()) .option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_REUSEADDR, options.reuseAddr()) .channelFactory(new ChannelFactory<Channel>() { @Override public Channel newChannel() { final NioDatagramChannel ch = new NioDatagramChannel(); DatagramChannelConfig config = ch.config(); config.setReceiveBufferSize(options.rcvbuf()); config.setSendBufferSize(options.sndbuf()); config.setReuseAddress(options.reuseAddr()); if (null != multicastInterface) { config.setNetworkInterface(multicastInterface); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (log.isInfoEnabled()) { log.info("CLOSE {}", ch); } close(ch); } }); netChannel = (NettyNetChannel<IN, OUT>) select(ch); inboundHandler.setNetChannel(netChannel); ch.pipeline().addLast(new ChannelOutboundHandlerAdapter() { @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { super.write(ctx, msg, promise); } }); return ch; } }).handler(inboundHandler); if (null != listenAddress) { bootstrap.localAddress(listenAddress); } else { bootstrap.localAddress(NetUtil.LOCALHOST, 3000); } if (null != multicastInterface) { bootstrap.option(ChannelOption.IP_MULTICAST_IF, multicastInterface); } }
From source file:reactor.ipc.netty.options.ClientOptions.java
License:Open Source License
static void defaultClientOptions(Bootstrap bootstrap) { bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000).option(ChannelOption.AUTO_READ, false) .option(ChannelOption.SO_RCVBUF, 1024 * 1024).option(ChannelOption.SO_SNDBUF, 1024 * 1024); }
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:reactor.tcp.netty.NettyTcpClient.java
License:Open Source License
/** * Creates a new NettyTcpClient that will use the given {@code env} for configuration and the given * {@code reactor} to send events. The number of IO threads used by the client is configured by * the environment's {@code reactor.tcp.ioThreadCount} property. In its absence the number of * IO threads will be equal to the {@link Environment#PROCESSORS number of available processors}. * </p>//from ww w.j av a 2 s.c o m * The client will connect to the given {@code connectAddress}, configuring its socket using the * given {@code opts}. The given {@code codec} will be used for encoding and decoding of data. * * @param env The configuration environment * @param reactor The reactor used to send events * @param connectAddress The address the client will connect to * @param opts The configuration options for the client's socket * @param codec The codec used to encode and decode data */ public NettyTcpClient(@Nonnull Environment env, @Nonnull Reactor reactor, @Nonnull InetSocketAddress connectAddress, ClientSocketOptions opts, @Nullable Codec<Buffer, IN, OUT> codec) { super(env, reactor, connectAddress, codec); this.eventsReactor = reactor; this.options = opts; int ioThreadCount = env.getProperty("reactor.tcp.ioThreadCount", Integer.class, Environment.PROCESSORS); ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-tcp-io")); this.bootstrap = new Bootstrap().group(ioGroup).channel(NioSocketChannel.class) .option(ChannelOption.SO_RCVBUF, options.rcvbuf()).option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_KEEPALIVE, options.keepAlive()) .option(ChannelOption.SO_LINGER, options.linger()) .option(ChannelOption.TCP_NODELAY, options.tcpNoDelay()).remoteAddress(connectAddress) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(options.timeout()); ch.pipeline().addLast(createChannelHandlers(ch)); ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { close(ch); } }); } }); }
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;// w w w . jav a 2 s.co m }
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:sas.systems.imflux.session.rtp.AbstractRtpSession.java
License:Apache License
/** * {@inheritDoc}/*from w w w . j a v a2 s . c om*/ */ @Override public synchronized boolean init() { if (this.running.get()) { return true; } Class<? extends Channel> channelType; if (useNio) { // create data channel bootstrap // EventLoopGroup bossGroup = new NioEventLoopGroup(5, Executors.defaultThreadFactory()); // if we want to use others than the defaults this.workerGroup = new NioEventLoopGroup(); channelType = NioDatagramChannel.class; } else { this.workerGroup = new OioEventLoopGroup(); channelType = OioDatagramChannel.class; } Bootstrap dataBootstrap = new Bootstrap(); dataBootstrap.group(this.workerGroup).option(ChannelOption.SO_SNDBUF, this.sendBufferSize) .option(ChannelOption.SO_RCVBUF, this.receiveBufferSize) // option not set: "receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(this.receiveBufferSize) .channel(channelType) // use an UDP channel implementation => forces us to use AddressedEnvelope .handler(new ChannelInitializer<Channel>() { // is used to initialize the ChannelPipeline @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", UdpDataPacketDecoder.getInstance()); pipeline.addLast("encoder", UdpDataPacketEncoder.getInstance()); pipeline.addLast("handler", new UdpDataHandler(AbstractRtpSession.this)); } }); // create control channel bootstrap Bootstrap controlBootstrap = new Bootstrap(); controlBootstrap.group(this.workerGroup).option(ChannelOption.SO_SNDBUF, this.sendBufferSize) .option(ChannelOption.SO_RCVBUF, this.receiveBufferSize) // option not set: "receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(this.receiveBufferSize) .channel(channelType) // use an UDP channel implementation => forces us to use AddressedEnvelope .handler(new ChannelInitializer<Channel>() { // is used to initialize the ChannelPipeline @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", UdpControlPacketDecoder.getInstance()); pipeline.addLast("encoder", UdpControlPacketEncoder.getInstance()); pipeline.addLast("handler", new UdpControlHandler(AbstractRtpSession.this)); } }); // create data channel SocketAddress dataAddress = this.localParticipant.getDataDestination(); try { ChannelFuture future = dataBootstrap.bind(dataAddress); this.dataChannel = future.sync().channel(); // wait for future to complete and retrieve channel } catch (Exception e) { LOG.error("Failed to bind data channel for session with id " + this.id, e); shutdownEventLoopGroup(); return false; } // create control channel SocketAddress controlAddress = this.localParticipant.getControlDestination(); try { ChannelFuture future = controlBootstrap.bind(controlAddress); this.controlChannel = future.sync().channel(); // wait for future to complete and retrieve channel } catch (Exception e) { LOG.error("Failed to bind control channel for session with id " + this.id, e); this.dataChannel.close(); shutdownEventLoopGroup(); return false; } LOG.debug("Data & Control channels bound for RtpSession with id {}.", this.id); // Send first RTCP packet. this.joinSession(this.localParticipant.getSsrc()); this.running.set(true); // Add the participant database cleaner. this.timer.newTimeout(new TimerTask() { @Override public void run(Timeout timeout) throws Exception { if (!running.get()) { return; } participantDatabase.cleanup(); timer.newTimeout(this, participantDatabaseCleanup, TimeUnit.SECONDS); } }, this.participantDatabaseCleanup, TimeUnit.SECONDS); // Add the periodic RTCP report generator. if (this.automatedRtcpHandling) { this.timer.newTimeout(this, this.updatePeriodicRtcpSendInterval(), TimeUnit.SECONDS); } if (this.internalTimer) { this.timer.start(); } return true; }