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.jupiter.transport.netty.NettyUdtAcceptor.java
License:Apache License
@Override protected void setOptions() { super.setOptions(); ServerBootstrap boot = bootstrap();/*from w w w.ja v a 2 s .c o m*/ // parent options NettyUdtConfigGroup.ParentConfig parent = configGroup.parent(); boot.option(ChannelOption.SO_BACKLOG, parent.getBacklog()); // child options NettyUdtConfigGroup.ChildConfig child = configGroup.child(); boot.childOption(ChannelOption.SO_REUSEADDR, child.isReuseAddress()); if (child.getRcvBuf() > 0) { boot.childOption(ChannelOption.SO_RCVBUF, child.getRcvBuf()); } if (child.getSndBuf() > 0) { boot.childOption(ChannelOption.SO_SNDBUF, child.getSndBuf()); } if (child.getLinger() > 0) { boot.childOption(ChannelOption.SO_LINGER, child.getLinger()); } int bufLowWaterMark = child.getWriteBufferLowWaterMark(); int bufHighWaterMark = child.getWriteBufferHighWaterMark(); if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) { WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark); boot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark); } }
From source file:org.kaazing.messaging.driver.transport.netty.tcp.NettyTransportContext.java
License:Apache License
public NettyTransportContext() { super();//from w ww.j a v a 2 s . c o m if (USE_SSL) { SelfSignedCertificate ssc = null; try { ssc = new SelfSignedCertificate(); serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); clientSslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE) .build(); } catch (CertificateException e) { LOGGER.error("CertificateException", e); throw new IllegalArgumentException("Error creating transport context", e); } catch (SSLException e) { LOGGER.error("SSLException", e); throw new IllegalArgumentException("Error creating transport context", e); } } else { serverSslCtx = null; clientSslCtx = null; } // Configure the server. serverBossGroup = new NioEventLoopGroup(1); serverWorkerGroup = new NioEventLoopGroup(); serverBootstrap = new ServerBootstrap(); serverBootstrap.group(serverBossGroup, serverWorkerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); if (serverSslCtx != null) { p.addLast(serverSslCtx.newHandler(ch.alloc())); } p.addLast(new LengthFieldBasedFrameDecoder(1000000, 0, 4, 0, 4)); serverReceivingTransportsLock.readLock().lock(); try { serverReceivingTransports.forEach((nettyReceivingTransport) -> { if (ch.localAddress().equals(nettyReceivingTransport.getInetSocketAddress()) || nettyReceivingTransport.isInAddrAny() && ch.localAddress().getPort() == nettyReceivingTransport .getInetSocketAddress().getPort()) { p.addLast(nettyReceivingTransport.getNettyChannelHandler()); } }); } finally { serverReceivingTransportsLock.readLock().unlock(); } } }); bootstrap = new Bootstrap(); group = new NioEventLoopGroup(); bootstrap.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (clientSslCtx != null) { p.addLast(clientSslCtx.newHandler(ch.alloc())); } } }); }
From source file:org.kayla.Server.java
License:Open Source License
public static void main(String[] agrs) { try {/* ww w. j a v a 2s . c o m*/ cache = new Cache(FileStore.open(Constants.CACHE_REPOSITORY)); table = cache.createChecksumTable().encode(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new GameChannelHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true); try { future = bootstrap.bind(43594).sync(); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("Bound " + Constants.FRAME_NAME + " on: " + future.channel().localAddress().toString()); } catch (IOException e) { logger.error("Error starting " + Constants.FRAME_NAME + "!", e); } }
From source file:org.kualigan.maven.plugins.AbstractStartRedisMojo.java
License:Apache License
/** * Start the redis server/*from w w w. j av a2s .c o m*/ * * @param isForked is a {@link Boolean} determing whether to fork the redis server or not. */ public void start(final Boolean isForked) throws InterruptedException { // Only execute the command handler in a single thread final RedisCommandHandler commandHandler = new RedisCommandHandler(new SimpleRedisServer()); // Configure the server. final ServerBootstrap b = new ServerBootstrap(); final DefaultEventExecutorGroup group = new DefaultEventExecutorGroup(1); getPluginContext().put(REDIS_GROUP_CONTEXT_PROPERTY_NAME, group); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).localAddress(getPort()) .childOption(ChannelOption.TCP_NODELAY, true) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); p.addLast(new RedisCommandDecoder()); p.addLast(new RedisReplyEncoder()); p.addLast(group, commandHandler); } }); final StringBuffer message = new StringBuffer(); // Start the server. if (isForked) { message.append("Forking Redis"); } else { message.append("Starting Redis"); } message.append("(port=").append(getPort()).append(") server..."); getLog().info(message.toString()); final ChannelFuture f = b.bind(); // Wait until the server socket is closed. if (!isForked) { f.sync(); f.channel().closeFuture().sync(); } } finally { // Shut down all event loops to terminate all threads. group.shutdownGracefully(); } }
From source file:org.legacy.network.Network.java
License:Open Source License
public void bindNetwork() { bootstrap = new ServerBootstrap(); bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()); bootstrap.channel(NioServerSocketChannel.class); bootstrap.option(ChannelOption.SO_BACKLOG, 100); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childHandler(new Pipeline()); try {//w ww. j ava 2s. c om bootstrap.localAddress(43594).bind().sync(); } catch (InterruptedException exception) { LegacyLogger.fireErrorMessage(this, "Error in binding the network", exception); } }
From source file:org.lightmare.remote.rpc.RpcListener.java
License:Open Source License
/** * Starts RPC server//www . jav a2 s .c om * */ public static void startServer(Configuration config) { setNettyPools(config); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(boss, worker).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializerImpl()); bootstrap.option(ChannelOption.SO_BACKLOG, 500); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); bootstrap.childOption(ChannelOption.SO_TIMEOUT, config.getIntValue(ConfigKeys.CONNECTION_TIMEOUT.key)); InetSocketAddress address = new InetSocketAddress( Inet4Address.getByName(config.getStringValue("listening_ip")), config.getIntValue("listening_port")); ChannelFuture future = bootstrap.bind(address).sync(); LOG.info(future); } catch (UnknownHostException ex) { LOG.error(ex.getMessage(), ex); } catch (InterruptedException ex) { LOG.error(ex.getMessage(), ex); } }
From source file:org.midonet.util.netty.ServerFrontEnd.java
License:Apache License
@Override protected void doStart() { try {// w w w . jav a 2s.c o m if (datagram) { log.info("Starting Netty UDP server on port {}", port); Bootstrap boot = new Bootstrap(); boot.group(wrkr).channel(NioDatagramChannel.class).handler(adapter); if (rcvbufSize != null) boot.option(ChannelOption.SO_RCVBUF, rcvbufSize).option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(rcvbufSize)); sock = boot.bind(port).sync(); } else { log.info("Starting Netty TCP server on port {}", port); ServerBootstrap boot = new ServerBootstrap(); boot.group(boss, wrkr).channel(NioServerSocketChannel.class).childHandler(adapter) .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_KEEPALIVE, true); sock = boot.bind(port).sync(); } log.info("Netty server started"); notifyStarted(); } catch (InterruptedException e) { log.warn("Netty server start interrupted"); Thread.currentThread().interrupt(); notifyFailed(e); } }
From source file:org.mitre.svmp.webrtc.http.TranslatorHttpServer.java
License:Open Source License
public void run() { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from www . jav a 2s . c om*/ ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new TranslatorHttpServerInitializer(sendQueue, receiveQueue)); Channel ch = b.bind(listenPort).sync().channel(); // read from the receive queue, translate into JSON, send to the "wait" connection // could make that driven through the handler probably ch.closeFuture().sync(); } catch (Exception e) { e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:org.mobicents.protocols.sctp.netty.NettyServerImpl.java
License:Open Source License
private void initSocket() throws Exception { ServerBootstrap b = new ServerBootstrap(); b.group(this.management.getBossGroup(), this.management.getWorkerGroup()); if (this.ipChannelType == IpChannelType.SCTP) { b.channel(NioSctpServerChannel.class); b.option(ChannelOption.SO_BACKLOG, 100); b.childHandler(new NettySctpServerChannelInitializer(this, this.management)); this.applySctpOptions(b); } else {/*ww w . j a v a 2s.c o m*/ b.channel(NioServerSocketChannel.class); b.option(ChannelOption.SO_BACKLOG, 100); b.childHandler(new NettyTcpServerChannelInitializer(this, this.management)); } b.handler(new LoggingHandler(LogLevel.INFO)); InetSocketAddress localAddress = new InetSocketAddress(this.hostAddress, this.hostport); // Bind the server to primary address. ChannelFuture channelFuture = b.bind(localAddress).sync(); // Get the underlying sctp channel if (this.ipChannelType == IpChannelType.SCTP) { this.serverChannelSctp = (SctpServerChannel) channelFuture.channel(); // Bind the secondary address. // Please note that, bindAddress in the client channel should be done before connecting if you have not // enable Dynamic Address Configuration. See net.sctp.addip_enable kernel param if (this.extraHostAddresses != null) { for (int count = 0; count < this.extraHostAddresses.length; count++) { String localSecondaryAddress = this.extraHostAddresses[count]; InetAddress localSecondaryInetAddress = InetAddress.getByName(localSecondaryAddress); channelFuture = this.serverChannelSctp.bindAddress(localSecondaryInetAddress).sync(); } } if (logger.isInfoEnabled()) { logger.info(String.format("SctpServerChannel bound to=%s ", this.serverChannelSctp.allLocalAddresses())); } } else { this.serverChannelTcp = (NioServerSocketChannel) channelFuture.channel(); if (logger.isInfoEnabled()) { logger.info( String.format("ServerSocketChannel bound to=%s ", this.serverChannelTcp.localAddress())); } } }
From source file:org.msgpack.rpc.impl.netty.NettyTcpServerTransport.java
License:Apache License
NettyTcpServerTransport(final TcpServerConfig config, final Server server, final NettyEventLoop loop) throws InterruptedException { if (server == null) { throw new IllegalArgumentException("Server must not be null"); }/*w w w . jav a 2 s. c o m*/ final Address address = config.getListenAddress(); final RpcMessageHandler handler = new RpcMessageHandler(server); handler.useThread(true); final EventLoopGroup bossGroup = new NioEventLoopGroup(/*1*/); // (1) final EventLoopGroup workerGroup = new NioEventLoopGroup(/*4*/); final ServerBootstrap b = new ServerBootstrap().group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) // (3) .childHandler(new ChannelInitializer<SocketChannel>() { // (4) @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new MessagePackDecoder(loop.getObjectMapper()), new MessageHandler(handler), new MessagePackEncoder(loop.getObjectMapper())); } }).option(ChannelOption.SO_BACKLOG, 128) // (5) .childOption(ChannelOption.TCP_NODELAY, !Boolean.FALSE.equals(config.getOption(ChannelOption.TCP_NODELAY.name()))) .childOption(ChannelOption.SO_KEEPALIVE, !Boolean.FALSE.equals(config.getOption(ChannelOption.SO_KEEPALIVE.name()))); // Bind and start to accept incoming connections. channelFuture = b.bind(address.getSocketAddress()).sync(); // (7) }