List of usage examples for io.netty.channel ChannelOption SO_BACKLOG
ChannelOption SO_BACKLOG
To view the source code for io.netty.channel ChannelOption SO_BACKLOG.
Click Source Link
From source file:com.mastfrog.scamper.ChannelConfigurer.java
License:Open Source License
/** * Initialize a server sctp channel// w ww .j a va 2 s .co m * * @param b The bootstrap * @return The bootstrap */ protected ServerBootstrap init(ServerBootstrap b) { b = b.group(group, worker).channel(NioSctpServerChannel.class).option(ChannelOption.SO_BACKLOG, 1000) .option(ChannelOption.ALLOCATOR, alloc).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(init); return b; }
From source file:com.mc.netty.server.NettyServer.java
License:Open Source License
private ServerBootstrap getDefaultServerBootstrap() { ServerBootstrap bootStrap = new ServerBootstrap(); bootStrap.group(bossGroup, workerGroup).option(ChannelOption.SO_BACKLOG, 1000) // ??? .option(ChannelOption.SO_SNDBUF, 32 * 1024).option(ChannelOption.SO_RCVBUF, 32 * 1024) .option(ChannelOption.TCP_NODELAY, true) // ??? .option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT) .channel(NioServerSocketChannel.class).childOption(ChannelOption.SO_KEEPALIVE, true); return bootStrap; }
From source file:com.mnxfst.stream.server.StreamAnalyzerServer.java
License:Apache License
public void run(final String configurationFilename, final int port) throws Exception { ObjectMapper mapper = new ObjectMapper(); StreamAnalyzerConfiguration streamAnalyzerConfiguration = mapper.readValue(new File(configurationFilename), StreamAnalyzerConfiguration.class); // set up the actor runtime environment this.rootActorSystem = ActorSystem.create("streamanalyzer"); this.componentRegistryRef = componentRegistryInitialization(); pipelineInitialization(streamAnalyzerConfiguration.getPipelines()); dispatcherInitialization(streamAnalyzerConfiguration.getDispatchers(), componentRegistryRef); listenerInitialization(streamAnalyzerConfiguration.getListeners(), componentRegistryRef); EventLoopGroup bossGroup = new NioEventLoopGroup(); // (1) EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/* w ww . jav a2s . com*/ ServerBootstrap b = new ServerBootstrap(); // (2) b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) // (3) .childHandler(new ChannelInitializer<SocketChannel>() { // (4) @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new StreamAnalyzerStatsHandler()); } }).option(ChannelOption.SO_BACKLOG, 128) // (5) .childOption(ChannelOption.SO_KEEPALIVE, true); // (6) // Bind and start to accept incoming connections. ChannelFuture f = b.bind(port).sync(); // (7) // Wait until the server socket is closed. // In this example, this does not happen, but you can do that to gracefully // shut down your server. f.channel().closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
From source file:com.moshi.receptionist.remoting.netty.NettyRemotingServer.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyServerConfig.getServerWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override/*from w w w. jav a 2 s . c om*/ public Thread newThread(Runnable r) { return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroup, new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) // .option(ChannelOption.SO_BACKLOG, 1024) // .option(ChannelOption.SO_REUSEADDR, true) // .childOption(ChannelOption.TCP_NODELAY, true) // .childOption(ChannelOption.SO_SNDBUF, NettySystemConfig.SocketSndbufSize) // .childOption(ChannelOption.SO_RCVBUF, NettySystemConfig.SocketRcvbufSize) .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 NettyConnetManageHandler(), // new NettyServerHandler()); } }); if (NettySystemConfig.NettyPooledByteBufAllocatorEnable) { // ???? 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.nettyEventExecuter.start(); } // ?1?? this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRemotingServer.this.scanResponseTable(); } catch (Exception e) { log.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); }
From source file:com.mpush.core.server.ConnectionServer.java
License:Apache License
@Override protected void initOptions(ServerBootstrap b) { super.initOptions(b); b.option(ChannelOption.SO_BACKLOG, 1024); /**//from ww w . j av a 2s . c o m * TCP???? * NettyChannelOptionSO_SNDBUFSO_RCVBUF * ????????32K? */ if (snd_buf.connect_server > 0) b.childOption(ChannelOption.SO_SNDBUF, snd_buf.connect_server); if (rcv_buf.connect_server > 0) b.childOption(ChannelOption.SO_RCVBUF, rcv_buf.connect_server); /** * ?????????? * ??????????????? * ???????? * ???????? * ?????? * ???NettyChannelOutboundBuffer * buffernetty?channel write?buffer???????(?channelbuffer) * ??32(32?)32? * ?(?TCP??) * ??buffer???(?swap?linux killer) * ?channel?channel?active? * * ChannelOutboundBuffer???? * buffer??channelisWritable??false * buffer??isWritable??trueisWritablefalse???? * ???64K?32K??????? */ b.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(connect_server_low, connect_server_high)); }
From source file:com.mpush.core.server.WebSocketServer.java
License:Apache License
@Override protected void initOptions(ServerBootstrap b) { super.initOptions(b); b.option(ChannelOption.SO_BACKLOG, 1024); b.childOption(ChannelOption.SO_SNDBUF, 32 * 1024); b.childOption(ChannelOption.SO_RCVBUF, 32 * 1024); }
From source file:com.mycompany.nettyweb.HttpServer.java
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from w ww . j a v a2 s. c o m ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.option(ChannelOption.SO_BACKLOG, 1024); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new HttpServerInitializer()); Channel ch = bootstrap.bind(port).sync().channel(); System.out.println("Server started, port:" + port); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.nanxiaoqiang.test.netty.protocol.demo1.server.NettyServer.java
License:Apache License
public void bind() throws Exception { // ??NIO//from w ww .j a v a2s .c o m EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws IOException { ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4));// ? ch.pipeline().addLast(new NettyMessageEncoder());// ? ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50));// ?? ch.pipeline().addLast(new LoginAuthRespHandler());// ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler());// } }); // ??? ChannelFuture cf = b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT); cf.channel().closeFuture().sync(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.navercorp.pinpoint.grpc.server.ServerFactory.java
License:Apache License
private void setupServerOption(final NettyServerBuilder builder) { // TODO @see PinpointServerAcceptor builder.withChildOption(ChannelOption.TCP_NODELAY, true); builder.withChildOption(ChannelOption.SO_REUSEADDR, true); builder.withChildOption(ChannelOption.SO_RCVBUF, this.serverOption.getReceiveBufferSize()); builder.withChildOption(ChannelOption.SO_BACKLOG, this.serverOption.getBacklogQueueSize()); builder.withChildOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, this.serverOption.getConnectTimeout()); final WriteBufferWaterMark writeBufferWaterMark = new WriteBufferWaterMark( this.serverOption.getWriteBufferLowWaterMark(), this.serverOption.getWriteBufferHighWaterMark()); builder.withChildOption(ChannelOption.WRITE_BUFFER_WATER_MARK, writeBufferWaterMark); builder.handshakeTimeout(this.serverOption.getHandshakeTimeout(), TimeUnit.MILLISECONDS); builder.flowControlWindow(this.serverOption.getFlowControlWindow()); builder.maxInboundMessageSize(this.serverOption.getMaxInboundMessageSize()); builder.maxHeaderListSize(this.serverOption.getMaxHeaderListSize()); builder.keepAliveTime(this.serverOption.getKeepAliveTime(), TimeUnit.MILLISECONDS); builder.keepAliveTimeout(this.serverOption.getKeepAliveTimeout(), TimeUnit.MILLISECONDS); builder.permitKeepAliveTime(this.serverOption.getPermitKeepAliveTimeout(), TimeUnit.MILLISECONDS); builder.permitKeepAliveWithoutCalls(this.serverOption.isPermitKeepAliveWithoutCalls()); builder.maxConnectionIdle(this.serverOption.getMaxConnectionIdle(), TimeUnit.MILLISECONDS); builder.maxConnectionAge(this.serverOption.getMaxConnectionAge(), TimeUnit.MILLISECONDS); builder.maxConnectionAgeGrace(this.serverOption.getMaxConnectionAgeGrace(), TimeUnit.MILLISECONDS); builder.maxConcurrentCallsPerConnection(this.serverOption.getMaxConcurrentCallsPerConnection()); if (logger.isInfoEnabled()) { logger.info("Set serverOption {}. name={}, hostname={}, port={}", serverOption, name, hostname, port); }// ww w . j a v a 2s . c o m }
From source file:com.necla.simba.server.gateway.server.frontend.FrontendServer.java
License:Apache License
public FrontendServer(Properties props, BackendConnector backend, StatsCollector stats, SubscriptionManager subscriptionManager, ClientAuthenticationManager cam) throws Exception { this.backend = backend; this.stats = stats; assert this.stats != null : "stats must be there already"; this.subscriptionManager = subscriptionManager; this.cam = cam; ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()).channel(NioServerSocketChannel.class) .childHandler(new FrontendServerInitializer()).option(ChannelOption.SO_BACKLOG, 128); int port = Integer.parseInt(props.getProperty("port", "9000")); ChannelFuture f = bootstrap.bind(port).sync(); f.channel().closeFuture().sync();/*from ww w .j av a2 s .c om*/ }