List of usage examples for io.netty.bootstrap ServerBootstrap childOption
public <T> ServerBootstrap childOption(ChannelOption<T> childOption, T value)
From source file:io.hekate.network.netty.NettyServer.java
License:Apache License
private <O> void setChildUserOpt(ServerBootstrap boot, ChannelOption<O> opt, O value) { if (value != null) { if (DEBUG) { log.debug("Setting option {} = {} [address={}]", opt, value, address); }/* w w w. j a va2s . c o m*/ boot.childOption(opt, value); } }
From source file:io.jsync.net.impl.TCPSSLHelper.java
License:Open Source License
public void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay); if (tcpSendBufferSize != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, tcpSendBufferSize); }/*from ww w . j av a 2 s . co m*/ if (tcpReceiveBufferSize != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(tcpReceiveBufferSize)); } // TODO this may not be needed if (soLinger != -1) { bootstrap.option(ChannelOption.SO_LINGER, soLinger); } if (trafficClass != -1) { bootstrap.childOption(ChannelOption.IP_TOS, trafficClass); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, tcpKeepAlive); bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress); bootstrap.option(ChannelOption.SO_BACKLOG, acceptBackLog); }
From source file:io.mycat.netty.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(); final ProtocolHandler handshakeHandler = newHandshakeHandler(userExecutor); final ProtocolHandler protocolHandler = newProtocolHandler(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 va2 s .co 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(), */ handshakeHandler, protocolHandler); } }); return b; }
From source file:io.netlibs.bgp.netty.service.BGPv4Server.java
License:Apache License
public void startServer() { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()); bootstrap.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() { @Override/*w ww . j a v a 2s . c om*/ public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(BGPv4Reframer.HANDLER_NAME, BGPv4Server.this.reframer); pipeline.addLast(BGPv4Codec.HANDLER_NAME, BGPv4Server.this.codec); pipeline.addLast(InboundOpenCapabilitiesProcessor.HANDLER_NAME, BGPv4Server.this.inboundOpenCapProcessor); pipeline.addLast(ValidateServerIdentifier.HANDLER_NAME, BGPv4Server.this.validateServer); pipeline.addLast(BGPv4ServerEndpoint.HANDLER_NAME, BGPv4Server.this.serverEndpoint); } }); bootstrap.option(ChannelOption.SO_BACKLOG, 128); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); log.info("Starting local server"); this.serverChannel = bootstrap.bind(applicationConfiguration.getServerPort()).syncUninterruptibly() .channel(); }
From source file:io.tetrapod.core.flashpolicy.FlashPolicyServer.java
License:Apache License
@Override protected void setOptions(ServerBootstrap sb) { sb.childOption(ChannelOption.TCP_NODELAY, true); sb.childOption(ChannelOption.SO_KEEPALIVE, true); }
From source file:io.tilt.minka.broker.impl.SocketServer.java
License:Apache License
private boolean keepListening() { boolean disconnected; logger.info("{}: ({}:{}) Building server (using i: {}) with up to {} concurrent requests", getClass().getSimpleName(), serverAddress, serverPort, networkInterfase, this.connectionHandlerThreads); try {// w w w. ja v a2 s .c om final ServerBootstrap b = new ServerBootstrap(); b.group(serverWorkerGroup).channel(NioServerSocketChannel.class) //.channel(OioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)), serverHandler); } }); logger.info("{}: Listening for client connections..", getClass().getSimpleName()); b.childOption(ChannelOption.SO_KEEPALIVE, true); logger.info( "{}: ({}:{}) Listening to client connections (using i:{}) with up to {} concurrent requests", getClass().getSimpleName(), serverAddress, serverPort, networkInterfase, this.connectionHandlerThreads); b.bind(this.serverAddress, this.serverPort).sync().channel().closeFuture().sync(); disconnected = false; } catch (Exception e) { disconnected = true; logger.error("{}: ({}:{}) Unexpected interruption while listening incoming connections", getClass().getSimpleName(), serverAddress, serverPort, e); } finally { logger.info("{}: ({}:{}) Exiting server listening scope", getClass().getSimpleName(), serverAddress, serverPort); shutdown(); } return disconnected; }
From source file:io.vertx.core.net.impl.NetServerBase.java
License:Open Source License
/** * Apply the connection option to the server. * * @param bootstrap the Netty server bootstrap *///from w w w .j a v a 2s . c o m protected void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); } if (options.getReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.childOption(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getAcceptBacklog() != -1) { bootstrap.option(ChannelOption.SO_BACKLOG, options.getAcceptBacklog()); } }
From source file:io.vertx.core.net.impl.transport.EpollTransport.java
License:Open Source License
@Override public void configure(NetServerOptions options, ServerBootstrap bootstrap) { bootstrap.option(EpollChannelOption.SO_REUSEPORT, options.isReusePort()); if (options.isTcpFastOpen()) { bootstrap.option(EpollChannelOption.TCP_FASTOPEN, options.isTcpFastOpen() ? pendingFastOpenRequestsThreshold : 0); }// w w w . j a v a2 s .com bootstrap.childOption(EpollChannelOption.TCP_QUICKACK, options.isTcpQuickAck()); bootstrap.childOption(EpollChannelOption.TCP_CORK, options.isTcpCork()); super.configure(options, bootstrap); }
From source file:io.vertx.core.net.impl.transport.Transport.java
License:Open Source License
public void configure(NetServerOptions options, ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }// www .j av a 2s . co m if (options.getReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.childOption(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.childOption(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getAcceptBacklog() != -1) { bootstrap.option(ChannelOption.SO_BACKLOG, options.getAcceptBacklog()); } }
From source file:me.bigteddy98.mcproxy.Main.java
License:Open Source License
public void run() throws Exception { ProxyLogger.info("Starting " + NAME + " version " + VERSION + " developed by " + AUTHOR + "!"); ProxyLogger.info(/*from ww w .j av a 2s.c om*/ "Starting server process using commandline " + Arrays.asList(processBuilder).toString() + "..."); ProcessBuilder builder = new ProcessBuilder(processBuilder); builder.redirectErrorStream(true); this.serverProcess = builder.start(); this.processPrintWriter = new PrintWriter(this.serverProcess.getOutputStream()); ProxyLogger.info("Server process started."); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { serverProcess.destroy(); } })); new Thread(new Runnable() { @Override public void run() { try (InputStream r = serverProcess.getInputStream()) { StringBuilder tmp = new StringBuilder(); byte[] consoleOutput = new byte[1024]; int read; while ((read = r.read(consoleOutput)) != -1) { String consoleLog = new String(consoleOutput, 0, read); String[] c = consoleLog.split("\n", -1); if (c.length != 0) { if (c.length == 1) { tmp.append(c[0]); } else { for (int i = 0; i < c.length - 1; i++) { tmp.append(c[i]); ProxyLogger.info(tmp.toString()); tmp.setLength(0); } tmp.append(c[c.length - 1]); } } } } catch (IOException e) { e.printStackTrace(); } ProxyLogger.warn("Server thread ended!"); System.exit(0); } }, "Server Output Reader").start(); new Thread(new Runnable() { @Override public void run() { try (Scanner in = new Scanner(System.in)) { while (in.hasNextLine()) { String newLine = in.nextLine(); executeCommand(newLine); } } ProxyLogger.warn("COMMAND LOOP ENDED, this shouldn't happen!"); } }, "CommandReader").start(); final ThreadGroup nettyListeners = new ThreadGroup(Thread.currentThread().getThreadGroup(), "Netty Listeners"); new Thread(nettyListeners, new Runnable() { @Override public void run() { ProxyLogger.info("Started Netty Server at port " + fromPort + "..."); final ThreadGroup group = new ThreadGroup(nettyListeners, "Listener-" + toPort); EventLoopGroup bossGroup = new NioEventLoopGroup(MAX_NETTY_BOSS_THREADS, new ThreadFactory() { private int threadCount = 0; private String newName = group.getName() + "\\boss"; @Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r, newName + "\\" + threadCount++); t.setPriority(Thread.NORM_PRIORITY - 1); t.setDaemon(true); return t; } }); EventLoopGroup workerGroup = new NioEventLoopGroup(MAX_NETTY_WORKER_THREADS, new ThreadFactory() { private int threadCount = 0; private String newName = group.getName() + "\\worker"; @Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r, newName + "\\" + threadCount++); t.setPriority(Thread.NORM_PRIORITY - 1); t.setDaemon(true); return t; } }); try { ServerBootstrap bootstrab = new ServerBootstrap(); bootstrab.group(bossGroup, workerGroup); bootstrab.channel(NioServerSocketChannel.class); bootstrab.childHandler(new ClientboundConnectionInitializer("localhost", toPort)); bootstrab.childOption(ChannelOption.AUTO_READ, false); bootstrab.bind(fromPort).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } }).start(); }