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:org.eclipse.neoscada.protocol.iec60870.server.Server.java
License:Open Source License
public Server(final SocketAddress address, final ProtocolOptions options, final List<ServerModule> modules) { this.options = options; this.manager = new MessageManager(this.options); this.bossGroup = new NioEventLoopGroup(); this.workerGroup = new NioEventLoopGroup(); this.bootstrap = new ServerBootstrap(); this.bootstrap.group(this.bossGroup, this.workerGroup); this.bootstrap.channel(NioServerSocketChannel.class); this.bootstrap.option(ChannelOption.SO_BACKLOG, 5); this.bootstrap.option(ChannelOption.SO_REUSEADDR, true); this.bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override//from ww w . ja v a 2 s . c om protected void initChannel(final SocketChannel ch) throws Exception { handleInitChannel(ch); } }); this.modules = modules.toArray(new ServerModule[modules.size()]); for (final ServerModule module : modules) { module.initializeServer(this, this.manager); } this.channel = this.bootstrap.bind(address).channel(); }
From source file:org.eclipse.scada.protocol.iec60870.server.Server.java
License:Open Source License
public Server(final short port, final ProtocolOptions options, final List<ServerModule> modules) { this.options = options; this.manager = new MessageManager(this.options); this.bossGroup = new NioEventLoopGroup(); this.workerGroup = new NioEventLoopGroup(); this.bootstrap = new ServerBootstrap(); this.bootstrap.group(this.bossGroup, this.workerGroup); this.bootstrap.channel(NioServerSocketChannel.class); this.bootstrap.option(ChannelOption.SO_BACKLOG, 5); this.bootstrap.option(ChannelOption.SO_REUSEADDR, true); this.bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override/*from ww w . java 2 s . co m*/ protected void initChannel(final SocketChannel ch) throws Exception { handleInitChannel(ch); } }); this.modules = modules.toArray(new ServerModule[modules.size()]); for (final ServerModule module : modules) { module.initializeServer(this, this.manager); } this.channel = this.bootstrap.bind(port).channel(); }
From source file:org.eclipse.scada.protocol.relp.service.Receiver.java
License:Open Source License
public Receiver(final ReceiverHandlerFactory factory, final SocketAddress addr) { this.factory = factory; this.bossGroup = new NioEventLoopGroup(); this.workerGroup = new NioEventLoopGroup(); this.bootstrap = new ServerBootstrap(); this.bootstrap.group(this.bossGroup, this.workerGroup); this.bootstrap.channel(NioServerSocketChannel.class); this.bootstrap.option(ChannelOption.SO_BACKLOG, 5); this.bootstrap.option(ChannelOption.SO_REUSEADDR, true); this.bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override/*www. jav a 2s . c om*/ protected void initChannel(final SocketChannel ch) throws Exception { handleInitChannel(ch); } }); this.channel = this.bootstrap.bind(addr).channel(); logger.info("Receiver running ..."); }
From source file:org.elasticsearch.hadoop.integration.rest.ssl.BasicSSLServer.java
License:Apache License
public void start() throws Exception { File cert = Paths.get(getClass().getResource("/ssl/server.pem").toURI()).toFile(); File keyStore = Paths.get(getClass().getResource("/ssl/server.key").toURI()).toFile(); SslContext sslCtx = SslContext.newServerContext(cert, keyStore); bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); server = new ServerBootstrap(); server.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new BasicSSLServerInitializer(sslCtx)); server.bind(port).sync().channel().closeFuture(); }
From source file:org.ensembl.gti.seqstore.server.MetaDataServer.java
License:Apache License
public void run() throws Exception { log.info("Starting server"); EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w w w.j a va 2 s . com*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4), getHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); // Bind and start to accept incoming connections. log.info("Binding to port " + port); ChannelFuture f = b.bind(port).sync(); // 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. log.info("Syncing future"); f.channel().closeFuture().sync(); } finally { log.info("Shutting server server"); workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
From source file:org.evilco.network.rcon.server.AbstractRconServer.java
License:Apache License
/** * Constructs a new AbstractRconServer instance. * @param eventBus The event bus.// w w w .ja va 2 s. c o m * @param registry The command registry. * @param password The server password. */ public AbstractRconServer(@NonNull EventBus eventBus, @NonNull ICommandRegistry registry, @NonNull String password) { // store arguments this.eventBus = eventBus; this.commandRegistry = registry; this.password = password; // create groups this.groupBoss = this.createEventLoopGroup(); this.groupWorker = this.createEventLoopGroup(); // create bootstrap this.bootstrap = new ServerBootstrap(); // set groups this.bootstrap.group(this.groupBoss, this.groupWorker); // set properties this.bootstrap.channel(this.getChannelType()); this.bootstrap.childHandler(this.createChannelInitializer()); this.bootstrap.option(ChannelOption.SO_BACKLOG, 128); this.bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); }
From source file:org.fengbaoxp.netty.official.AbstractServer.java
License:Apache License
protected void run(ChannelHandler channelHandler, int port) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//w w w. ja v a 2 s. com ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(channelHandler); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); ChannelFuture f = b.bind(port).sync(); f.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:org.ftccommunity.ftcxtensible.networking.http.HttpHelloWorldServer.java
License:Apache License
public void run() { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from w ww . ja va2s .com try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) //.childHandler(new HttpHelloWorldServerInitializer(sslCtx, main)); .childHandler(new ChannelInitializer<SocketChannel>() { /** * This method will be called once the {@link Channel} was registered. After the method returns this instance * will be removed from the {@link ChannelPipeline} of the {@link Channel}. * * @param ch the {@link Channel} which was registered. * @throws Exception is thrown if an error occurs. In that case the {@link Channel} will be closed. */ @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new HttpServerCodec(), new HttpHelloWorldServerHandler(context)); } }); Channel ch = b.bind(PORT).sync().channel(); System.err.println( "Open your web browser and navigate to " + ("http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } Log.i("NET_OP_MODE::", "Op Mode Server is shuting down."); }
From source file:org.ftccommunity.ftcxtensible.networking.http.RobotHttpServer.java
License:Open Source License
/** * The server thread implementation. This loads the Netty server and runs as the Netty server. *///from w w w .j a v a2 s . c o m public void run() { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) //.childHandler(new HttpHelloWorldServerInitializer(sslCtx, main)); .childHandler(new ChannelInitializer<SocketChannel>() { /** * This method will be called once the {@link Channel} was registered. After the method returns this instance * will be removed from the {@link ChannelPipeline} of the {@link Channel}. * * @param ch the {@link Channel} which was registered. * @throws Exception is thrown if an error occurs. In that case the {@link Channel} will be closed. */ @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new HttpServerCodec(), new org.ftccommunity.ftcxtensible.networking.http.RobotHttpServerHandler( context)); } }); Channel ch = b.bind(PORT).sync().channel(); System.err.println( "Open your web browser and navigate to " + ("http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } Log.i("NET_OP_MODE::", "OpMode Server is shutting down."); }
From source file:org.fusesource.hawtdispatch.netty.example.EchoServer.java
License:Apache License
public void run() throws Exception { // Configure the server. ServerBootstrap b = new ServerBootstrap(); try {/* w w w . j a v a2 s .c o m*/ b.group(new HawtEventLoopGroup(Dispatch.getGlobalQueue()), new HawtEventLoopGroup(Dispatch.getGlobalQueue())).channel(HawtServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new EchoServerHandler()); } }); // Start the server. ChannelFuture f = b.bind().sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. b.shutdown(); } }