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:com.newlandframework.avatarmq.broker.server.AvatarMQBrokerServer.java
License:Apache License
public void init() { try {//from w w w.ja v a2s.com handler = new MessageBrokerHandler().buildConsumerHook(new ConsumerMessageHook()) .buildProducerHook(new ProducerMessageHook()); boss = new NioEventLoopGroup(1, threadBossFactory); workers = new NioEventLoopGroup(parallel, threadWorkerFactory, NettyUtil.getNioSelectorProvider()); KryoCodecUtil util = new KryoCodecUtil(KryoPoolFactory.getKryoPoolInstance()); bootstrap = new ServerBootstrap(); bootstrap.group(boss, workers).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 1024).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_SNDBUF, nettyClustersConfig.getClientSocketSndBufSize()) .option(ChannelOption.SO_RCVBUF, nettyClustersConfig.getClientSocketRcvBufSize()) .handler(new LoggingHandler(LogLevel.INFO)).localAddress(serverIpAddr) .childHandler(new ChannelInitializer<SocketChannel>() { public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(defaultEventExecutorGroup, new MessageObjectEncoder(util), new MessageObjectDecoder(util), handler); } }); super.init(); } catch (IOException ex) { Logger.getLogger(AvatarMQBrokerServer.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.newlandframework.avatarmq.netty.MessageConnectFactory.java
License:Apache License
public void init() { try {//from ww w .j av a 2 s . c o m defaultEventExecutorGroup = new DefaultEventExecutorGroup(NettyClustersConfig.getWorkerThreads(), threadFactory); eventLoopGroup = new NioEventLoopGroup(); bootstrap = new Bootstrap(); bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { public void initChannel(SocketChannel channel) throws Exception { channel.pipeline().addLast(defaultEventExecutorGroup); channel.pipeline().addLast(new MessageObjectEncoder(util)); channel.pipeline().addLast(new MessageObjectDecoder(util)); channel.pipeline().addLast(messageHandler); } }).option(ChannelOption.SO_SNDBUF, nettyClustersConfig.getClientSocketSndBufSize()) .option(ChannelOption.SO_RCVBUF, nettyClustersConfig.getClientSocketRcvBufSize()) .option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, false); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.openddal.server.NettyServer.java
License:Apache License
private ServerBootstrap configServer() { bossGroup = new NioEventLoopGroup(args.bossThreads, new DefaultThreadFactory("NettyBossGroup", true)); workerGroup = new NioEventLoopGroup(args.workerThreads, new DefaultThreadFactory("NettyWorkerGroup", true)); userExecutor = createUserThreadExecutor(); Authenticator authenticator = createAuthenticator(); ProcessorFactory processorFactory = createProcessorFactory(); RequestFactory requestFactory = createRequestFactory(); ResponseFactory responseFactory = createResponseFactory(); final ProtocolHandler protocolHandler = new ProtocolHandler(authenticator, processorFactory, requestFactory, responseFactory, userExecutor); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childOption(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.TCP_NODELAY, true); if (args.socketTimeoutMills > 0) { b.childOption(ChannelOption.SO_TIMEOUT, args.socketTimeoutMills); }//from w w w .j a v a2 s.c o m if (args.recvBuff > 0) { b.childOption(ChannelOption.SO_RCVBUF, args.recvBuff); } if (args.sendBuff > 0) { b.childOption(ChannelOption.SO_SNDBUF, args.sendBuff); } b.childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(createProtocolDecoder(), /* createProtocolEncoder(), */ protocolHandler); } }); return b; }
From source file:com.spotify.ffwd.protocol.ProtocolServersImpl.java
License:Apache License
private AsyncFuture<ProtocolConnection> bindTCP(final Logger log, final Protocol protocol, ProtocolServer server, RetryPolicy policy) { final ServerBootstrap b = new ServerBootstrap(); b.group(boss, worker);/*from ww w .j a v a 2 s .c o m*/ b.channel(NioServerSocketChannel.class); b.childHandler(server.initializer()); b.option(ChannelOption.SO_BACKLOG, 128); if (protocol.getReceiveBufferSize() != null) { b.childOption(ChannelOption.SO_RCVBUF, protocol.getReceiveBufferSize()); } b.childOption(ChannelOption.SO_KEEPALIVE, true); final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort(); final RetryingProtocolConnection connection = new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return b.bind(host, port); } @Override public String toString() { return String.format("bind tcp://%s:%d", host, port); } }); return connection.getInitialFuture(); }
From source file:com.spotify.ffwd.protocol.ProtocolServersImpl.java
License:Apache License
private AsyncFuture<ProtocolConnection> bindUDP(final Logger log, final Protocol protocol, ProtocolServer server, RetryPolicy policy) { final Bootstrap b = new Bootstrap(); b.group(worker);//from w ww . ja va2 s . co m b.channel(NioDatagramChannel.class); b.handler(server.initializer()); if (protocol.getReceiveBufferSize() != null) { b.option(ChannelOption.SO_RCVBUF, protocol.getReceiveBufferSize()); } final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort(); final RetryingProtocolConnection connection = new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return b.bind(host, port); } @Override public String toString() { return String.format("bind tcp://%s:%d", host, port); } }); return connection.getInitialFuture(); }
From source file:com.srotya.linea.network.InternalUDPTransportServer.java
License:Apache License
public void start() throws Exception { NetworkInterface iface = NetworkUtils.selectDefaultIPAddress(false); Inet4Address address = NetworkUtils.getIPv4Address(iface); EventLoopGroup workerGroup = new NioEventLoopGroup(4); Bootstrap b = new Bootstrap(); channel = b.group(workerGroup).channel(NioDatagramChannel.class).option(ChannelOption.SO_RCVBUF, 1024 * 10) .handler(new ChannelInitializer<Channel>() { @Override//from w ww . j av a 2s .co m protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast(new KryoDatagramDecoderWrapper()).addLast(new IWCHandler(router)); } }).bind(address, port).sync().channel(); }
From source file:com.srotya.sidewinder.core.ingress.binary.NettyBinaryIngestionServer.java
License:Apache License
public void start() throws InterruptedException { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(4); ServerBootstrap bs = new ServerBootstrap(); channel = bs.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_RCVBUF, 10485760).option(ChannelOption.SO_SNDBUF, 10485760) .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new ChannelInitializer<SocketChannel>() { @Override/*from ww w . ja v a2s . c o m*/ protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new LengthFieldBasedFrameDecoder(3000, 0, 4, 0, 4)); p.addLast(new SeriesDataPointDecoder()); p.addLast(new SeriesDataPointWriter(storageEngine)); } }).bind("localhost", 9927).sync().channel(); }
From source file:com.srotya.sidewinder.core.ingress.binary.NettyIngestionClient.java
License:Apache License
public static void main(String[] args) throws InterruptedException { EventLoopGroup group = new NioEventLoopGroup(1); try {/*w w w . j a va 2 s . c om*/ Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.SO_RCVBUF, 10485760) .option(ChannelOption.SO_SNDBUF, 10485760).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new LengthFieldPrepender(4)); p.addLast(new SeriesDataPointEncoder()); } }); // Start the client. ChannelFuture f = b.connect("localhost", 9927).sync(); Channel channel = f.channel(); for (int k = 0; k < TOTAL; k++) { List<DataPoint> data = new ArrayList<>(); for (int i = 0; i < 100; i++) { DataPoint dp = new DataPoint("test", "cpu" + i, "value", Arrays.asList("2"), System.currentTimeMillis() + i * k, System.currentTimeMillis() + i * k); dp.setFp(false); data.add(dp); } // Thread.sleep(1); channel.writeAndFlush(data); } System.out.println("Data points:" + TOTAL); channel.flush(); channel.closeFuture().sync(); System.exit(0); } finally { // Shut down the event loop to terminate all threads. } }
From source file:com.srotya.sidewinder.core.ingress.http.NettyHTTPIngestionServer.java
License:Apache License
public void start() throws InterruptedException { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(4); ServerBootstrap bs = new ServerBootstrap(); channel = bs.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_RCVBUF, 10485760).option(ChannelOption.SO_SNDBUF, 10485760) .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new ChannelInitializer<SocketChannel>() { @Override//from w ww.j a v a 2 s. c o m protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new HttpRequestDecoder()); p.addLast(new HttpResponseEncoder()); p.addLast(new HTTPDataPointDecoder(storageEngine)); } }).bind("localhost", 9928).sync().channel(); }
From source file:com.tc.websocket.server.DominoWebSocketServer.java
License:Apache License
@Override public synchronized void start() { if (this.isOn()) return;/*from w w w . j a va2 s .c o m*/ try { try { ServerBootstrap boot = new ServerBootstrap(); if (cfg.isNativeTransport()) { boot.channel(EpollServerSocketChannel.class); } else { boot.channel(NioServerSocketChannel.class); } boot.group(bossGroup, workerGroup).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)) .childOption(ChannelOption.SO_SNDBUF, cfg.getSendBuffer()) .childOption(ChannelOption.SO_RCVBUF, cfg.getReceiveBuffer()) .childOption(ChannelOption.TCP_NODELAY, true).childHandler(init); //bind to the main port boot.bind(cfg.getPort()).sync(); //bind to the redirect port (e.g. 80 will redirect to 443) for (Integer port : cfg.getRedirectPorts()) { ChannelFuture f = boot.bind(port); f.sync(); } this.on.set(true); String version = BundleUtils.getVersion(Activator.bundle); String name = BundleUtils.getName(Activator.bundle); cfg.print(name + " ready and listening on " + cfg.getPort() + " running version " + version); } finally { } } catch (Exception e) { LOG.log(Level.SEVERE, null, e); } }