Example usage for io.netty.channel ChannelOption SO_BACKLOG

List of usage examples for io.netty.channel ChannelOption SO_BACKLOG

Introduction

In this page you can find the example usage for io.netty.channel ChannelOption SO_BACKLOG.

Prototype

ChannelOption SO_BACKLOG

To view the source code for io.netty.channel ChannelOption SO_BACKLOG.

Click Source Link

Usage

From source file:org.hummer.server.NettyServer.java

License:Apache License

public void init() {
    if (!inited.compareAndSet(false, true)) {
        return;//from  w  w  w.j a v  a  2 s .  c  o  m
    }
    inited.set(true);
    bootstrap = new ServerBootstrap();
    EventLoopGroup boss = new NioEventLoopGroup(
            GolbalConfigurationFactory.getInstance().configure().getServerBossThreads());
    EventLoopGroup worker = new NioEventLoopGroup(
            GolbalConfigurationFactory.getInstance().configure().getServerWorkerThreads());
    bootstrap.group(boss, worker).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_BACKLOG, 128)
            .option(ChannelOption.SO_KEEPALIVE, true).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<Channel>() {

                @Override
                protected void initChannel(Channel ch) throws Exception {
                    ch.pipeline().addLast("encoder", new HummerEncoder());
                    ch.pipeline().addLast("decoder", new HummerDecoder());
                    ch.pipeline().addLast("handler", new HummerServerHandler());
                }
            });
}

From source file:org.jboss.aerogear.webpush.netty.WebPushNettyServer.java

License:Apache License

public static void main(final String[] args) throws Exception {
    final WebPushServerConfig config = readConfig(args);
    final DataStore inMemoryDataStore = new InMemoryDataStore();
    final SslContext sslCtx = createSslContext(config);

    final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    final EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//from www . java2s.  c  o  m
        final ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024).group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new WebPushChannelInitializer(sslCtx, inMemoryDataStore, config));
        final Channel ch = b.bind(config.host(), config.port()).sync().channel();
        LOGGER.info("WebPush server bound to {}:{}", config.host(), config.port());
        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.jdiameter.server.impl.io.tcp.netty.NetworkGuard.java

License:Open Source License

private void bind(InetSocketAddress localAddress) {
    logger.debug("Binding to socket [{}]", localAddress);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override/*from   w ww  . j av a 2  s.com*/
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new ClientHandler());
                }
            }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);

    try {
        channels.add(bootstrap.bind(localAddress).sync().channel());
        logger.debug("Bound to socket [{}]", localAddress);
    } catch (InterruptedException e) {
        logger.error("Failed to bind to socket " + localAddress, e);
    }

    /*
     * bootstrap.bind(port).addListener(new ChannelFutureListener() {
     *
     * @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { if (channelFuture.isSuccess()) {
     * channels.add(channelFuture.channel()); } } });
     */
}

From source file:org.jdiameter.server.impl.io.tls.netty.NetworkGuard.java

License:Open Source License

private void bind(InetSocketAddress localAddress) {
    logger.debug("Binding to socket [{}]", localAddress);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override/*from w  w w.  j  a v  a2 s . c  o m*/
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new ClientHandler());
                }
            }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);

    try {
        channels.add(bootstrap.bind(localAddress).sync().channel());
        logger.debug("Bound to socket [{}]", localAddress);
    } catch (InterruptedException e) {
        logger.error("Failed to bind to socket " + localAddress, e);
    }
}

From source file:org.jfxvnc.ui.service.VncRenderService.java

License:Apache License

private void startListening() throws Exception {
    connectProperty.set(true);//  w w  w .j  a  v a2  s  .c o  m
    shutdown();
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100);

    b.childHandler(new ProtocolInitializer(VncRenderService.this, config));

    int port = listeningPortProperty.get() > 0 ? listeningPortProperty.get() : LISTENING_PORT;
    b.bind(port).addListener(l -> {
        logger.info("wait for incoming connection request on port: {}..", port);
        connectProperty.set(l.isSuccess());
    }).sync();

}

From source file:org.jmqtt.broker.acceptor.NettyAcceptor.java

License:Open Source License

private void initFactory(String host, int port, final PipelineInitializer pipeliner) {
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//from   w  ww.j  av  a  2 s  .  com
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline pipeline = ch.pipeline();
                    try {
                        pipeliner.init(pipeline);
                    } catch (Throwable th) {
                        LOG.error("Severe error during pipeline creation", th);
                        throw th;
                    }
                }
            }).option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true);
    try {
        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(host, port);
        LOG.info("Server binded host: {}, port: {}", host, port);
        f.sync();
    } catch (InterruptedException ex) {
        LOG.error(null, ex);
    }
}

From source file:org.jocean.http.server.HttpTestServer.java

License:Apache License

public HttpTestServer(final boolean enableSSL, final SocketAddress localAddress, final EventLoopGroup bossGroup,
        final EventLoopGroup workerGroup, final Class<? extends ServerChannel> serverChannelType,
        final Callable<ChannelInboundHandler> newHandler) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (enableSSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {/* w  w  w.  j a  v a 2s. com*/
        sslCtx = null;
    }

    // Configure the server.
    _bossGroup = bossGroup;
    _workerGroup = workerGroup;

    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_BACKLOG, 1024);
    b.group(_bossGroup, _workerGroup).channel(serverChannelType).handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new HttpTestServerInitializer(sslCtx, newHandler));

    b.bind(localAddress).sync();
}

From source file:org.jooby.Netty.java

License:Apache License

public static void main(final String[] args) throws Exception {

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*w w  w .  java2s. com*/
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                //.handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(final Channel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        p.addLast(new HttpServerCodec());
                        p.addLast(handler());
                    }
                });

        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();
    }
}

From source file:org.jpos.qrest.RestServer.java

License:Open Source License

@Override
protected void initService() throws GeneralSecurityException, IOException {
    sp = SpaceFactory.getSpace();//w ww.ja  v a 2s.co  m
    final SSLContext sslContext = enableTLS ? getSSLContext() : null;
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();
    serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    int timeout = cfg.getInt("timeout", 300);
                    ch.pipeline().addLast(new IdleStateHandler(timeout, timeout, timeout));
                    if (enableTLS) {
                        ch.pipeline().addLast(new SslHandler(getSSLEngine(sslContext), true));
                    }
                    ch.pipeline().addLast(new HttpServerCodec());
                    ch.pipeline().addLast(new HttpObjectAggregator(512 * 1024));
                    ch.pipeline().addLast(new RestSession(RestServer.this));
                }
            }).option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true)
            .childOption(ChannelOption.SO_KEEPALIVE, true);

    if (enableTLS) {
        logSSLEngineInfo(getSSLEngine(sslContext));
    }
}

From source file:org.jupiter.transport.netty.NettyTcpAcceptor.java

License:Apache License

@Override
protected void setOptions() {
    super.setOptions();

    ServerBootstrap boot = bootstrap();//  ww w .j  a  va2  s.c o m

    // parent options
    NettyConfig.NettyTcpConfigGroup.ParentConfig parent = configGroup.parent();
    boot.option(ChannelOption.SO_BACKLOG, parent.getBacklog());
    boot.option(ChannelOption.SO_REUSEADDR, parent.isReuseAddress());
    if (parent.getRcvBuf() > 0) {
        boot.option(ChannelOption.SO_RCVBUF, parent.getRcvBuf());
    }

    // child options
    NettyConfig.NettyTcpConfigGroup.ChildConfig child = configGroup.child();
    boot.childOption(ChannelOption.SO_REUSEADDR, child.isReuseAddress())
            .childOption(ChannelOption.SO_KEEPALIVE, child.isKeepAlive())
            .childOption(ChannelOption.TCP_NODELAY, child.isTcpNoDelay())
            .childOption(ChannelOption.ALLOW_HALF_CLOSURE, child.isAllowHalfClosure());
    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());
    }
    if (child.getIpTos() > 0) {
        boot.childOption(ChannelOption.IP_TOS, child.getIpTos());
    }
    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);
    }
}