List of usage examples for io.netty.channel ChannelOption SO_SNDBUF
ChannelOption SO_SNDBUF
To view the source code for io.netty.channel ChannelOption SO_SNDBUF.
Click Source Link
From source file:com.navercorp.nbasearc.gcp.PhysicalConnection.java
License:Apache License
static PhysicalConnection create(String ip, int port, SingleThreadEventLoop eventLoop, Gateway gw, int reconnectInterval) { final PhysicalConnection pc = new PhysicalConnection(ip, port, eventLoop, gw, reconnectInterval); pc.b.group(eventLoop.getEventLoopGroup()).channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.SO_LINGER, 0) .option(ChannelOption.SO_SNDBUF, SOCKET_BUFFER).option(ChannelOption.SO_RCVBUF, SOCKET_BUFFER) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT) .handler(new ChannelInitializer<SocketChannel>() { @Override/*from www . j av a 2 s. c o m*/ protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(pc.new PhysicalConnectionHandler()); } }); return pc; }
From source file:com.newlandframework.avatarmq.broker.server.AvatarMQBrokerServer.java
License:Apache License
public void init() { try {/*from w w w . j a va 2 s . 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 {// ww w. ja va2 s. com 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); }//w w w .j a v a2s . 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.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 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 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 ww .ja va 2 s . c o m*/ 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 w w . j a v a2 s . c om 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 ww. ja v a 2s . 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); } }
From source file:com.tongbanjie.tarzan.rpc.netty.NettyRpcClient.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyClientConfig.getClientWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override/* w w w . j ava2 s. co m*/ public Thread newThread(Runnable r) { return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet()); } }); this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class)// // .option(ChannelOption.TCP_NODELAY, true) // .option(ChannelOption.SO_KEEPALIVE, false) // .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()) // .option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()) // .option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()) // .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(// defaultEventExecutorGroup, // new NettyEncoder(), // new NettyDecoder(), // new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()), // new NettyConnectManageHandler(), // new NettyClientHandler()); } }); this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRpcClient.this.scanResponseTable(); } catch (Exception e) { LOGGER.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); if (this.channelEventListener != null) { this.nettyEventExecutor.start(); } }
From source file:com.tongbanjie.tarzan.rpc.netty.NettyRpcServer.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyServerConfig.getServerWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override//from ww w . java2s . c o m public Thread newThread(Runnable r) { return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector) .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, nettyServerConfig.getServerSocketSndBufSize()) // .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) // .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( // defaultEventExecutorGroup, // new NettyEncoder(), // new NettyDecoder(), // new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), // new NettyConnectManageHandler(), // new NettyServerHandler()); } }); if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) { childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); } try { ChannelFuture sync = this.serverBootstrap.bind().sync(); InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress(); this.port = addr.getPort(); } catch (InterruptedException e1) { throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1); } if (this.channelEventListener != null) { this.nettyEventExecutor.start(); } this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRpcServer.this.scanResponseTable(); } catch (Exception e) { LOGGER.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); LOGGER.info("Rpc server [port:{}] start success", port); }