Example usage for io.netty.bootstrap ServerBootstrap childOption

List of usage examples for io.netty.bootstrap ServerBootstrap childOption

Introduction

In this page you can find the example usage for io.netty.bootstrap ServerBootstrap childOption.

Prototype

public <T> ServerBootstrap childOption(ChannelOption<T> childOption, T value) 

Source Link

Document

Allow to specify a ChannelOption which is used for the Channel instances once they get created (after the acceptor accepted the Channel ).

Usage

From source file:org.onosproject.ovsdb.controller.impl.Controller.java

License:Apache License

/**
 * Accepts incoming connections./*from   ww w  .j  a  v a 2s.c  om*/
 */
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();

    b.group(bossGroup, workerGroup).channel(serverChannelClass)
            .childHandler(new OnosCommunicationChannelInitializer());
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);
    b.bind(ovsdbPort).sync();
}

From source file:org.onosproject.store.cluster.messaging.impl.NettyMessagingManager.java

License:Apache License

private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.SO_RCVBUF, 1048576);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.group(serverGroup, clientGroup);//from w w w  . j  a  va 2s  .c  om
    b.channel(serverChannelClass);
    if (enableNettyTls) {
        b.childHandler(new SslServerCommunicationChannelInitializer());
    } else {
        b.childHandler(new OnosCommunicationChannelInitializer());
    }
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);

    // Bind and start to accept incoming connections.
    b.bind(localEp.port()).sync().addListener(future -> {
        if (future.isSuccess()) {
            log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port());
        } else {
            log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause());
        }
    });
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java

License:Open Source License

public static ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer,
        final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {//from  ww  w . ja  v  a2s  .c  om
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);

    serverBootstrap.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE));
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);

    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);

    if (serverBootstrap.group() == null) {
        serverBootstrap.group(bossGroup, workerGroup);
    }
    return serverBootstrap;
}

From source file:org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl.java

License:Open Source License

@Override
public ChannelFuture createServer(final InetSocketAddress address, final BmpSessionListenerFactory slf,
        final Optional<KeyMapping> keys) {
    Preconditions.checkNotNull(address);
    Preconditions.checkNotNull(slf);// ww  w  .  java 2s.c o  m

    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(final Channel ch) throws Exception {
            ch.pipeline().addLast(BmpDispatcherImpl.this.hf.getDecoders());
            ch.pipeline().addLast(BmpDispatcherImpl.this.sessionFactory.getSession(ch, slf));
        }
    });

    b.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
    } else {
        b.channel(NioServerSocketChannel.class);
    }

    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    b.group(this.bossGroup, this.workerGroup);
    final ChannelFuture f = b.bind(address);

    LOG.debug("Initiated BMP server {} at {}.", f, address);
    return f;
}

From source file:org.opendaylight.protocol.bmp.mock.BmpMockDispatcher.java

License:Open Source License

private ServerBootstrap createServerInstance() {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.childHandler(new ChannelInitializer<Channel>() {
        @Override/*from w w w .  j a v a  2 s.  co m*/
        protected void initChannel(final Channel ch) throws Exception {
            ch.pipeline().addLast(BmpMockDispatcher.this.sessionFactory.getSession(ch, null));
            ch.pipeline().addLast(BmpMockDispatcher.this.hf.getEncoders());
        }
    });

    serverBootstrap.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.channel(NioServerSocketChannel.class);
    serverBootstrap.group(bossGroup, workerGroup);
    return serverBootstrap;
}

From source file:org.opendaylight.protocol.framework.AbstractDispatcher.java

License:Open Source License

/**
 * Creates server. Each server needs factories to pass their instances to client sessions.
 *
 * @param address address to which the server should be bound
 * @param channelClass The {@link Class} which is used to create {@link Channel} instances from.
 * @param initializer instance of PipelineInitializer used to initialize the channel pipeline
 *
 * @return ChannelFuture representing the binding process
 *//*from ww w .j  av  a  2 s  .co  m*/
protected <CH extends Channel> ChannelFuture createServer(final SocketAddress address,
        final Class<? extends ServerChannel> channelClass,
        final ChannelPipelineInitializer<CH, S> initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<CH>() {

        @Override
        protected void initChannel(final CH ch) {
            initializer.initializeChannel(ch, new DefaultPromise<S>(executor));
        }
    });

    b.option(ChannelOption.SO_BACKLOG, 128);
    if (LocalServerChannel.class.equals(channelClass) == false) {
        // makes no sense for LocalServer and produces warning
        b.childOption(ChannelOption.SO_KEEPALIVE, true);
        b.childOption(ChannelOption.TCP_NODELAY, true);
    }
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    customizeBootstrap(b);

    if (b.group() == null) {
        b.group(bossGroup, workerGroup);
    }
    try {
        b.channel(channelClass);
    } catch (IllegalStateException e) {
        // FIXME: if this is ok, document why
        LOG.trace("Not overriding channelFactory on bootstrap {}", b, e);
    }

    // Bind and start to accept incoming connections.
    final ChannelFuture f = b.bind(address);
    LOG.debug("Initiated server {} at {}.", f, address);
    return f;
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl.java

License:Open Source License

protected ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override/* ww  w. ja v  a  2s. co m*/
        protected void initChannel(final SocketChannel ch) {
            initializer.initializeChannel(ch, new DefaultPromise(PCEPDispatcherImpl.this.executor));
        }
    });
    b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);

    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
        b.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        b.channel(NioServerSocketChannel.class);
    }
    if (this.keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, this.keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }

    // Make sure we are doing round-robin processing
    b.childOption(ChannelOption.MAX_MESSAGES_PER_READ, 1);

    if (b.group() == null) {
        b.group(this.bossGroup, this.workerGroup);
    }

    return b;
}

From source file:org.ratpackframework.bootstrap.internal.NettyRatpackService.java

License:Apache License

@Override
protected void startUp() throws Exception {
    ServerBootstrap bootstrap = new ServerBootstrap();
    group = new NioEventLoopGroup(MultithreadEventLoopGroup.DEFAULT_EVENT_LOOP_THREADS,
            new DefaultThreadFactory("ratpack-group", Thread.MAX_PRIORITY));

    bootstrap.group(group).channel(NioServerSocketChannel.class).childHandler(channelInitializer);

    bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.option(ChannelOption.SO_BACKLOG, 1024);

    channel = bootstrap.bind(requestedAddress).sync().channel();
    boundAddress = (InetSocketAddress) channel.localAddress();

    if (logger.isLoggable(Level.INFO)) {
        logger.info(String.format("Ratpack started for http://%s:%s", getBindHost(), getBindPort()));
    }//from   w ww  . j  a v a  2 s  .c  om
}

From source file:org.vertx.java.core.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   w  w  w  . j  av  a  2s .c om*/
    if (tcpReceiveBufferSize != -1) {
        bootstrap.childOption(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize);
        bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR,
                new FixedRecvByteBufAllocator(tcpReceiveBufferSize));
    }

    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:org.waarp.common.utility.WaarpNettyUtil.java

License:Open Source License

/**
 * Add default configuration for server bootstrap
 * //from  w w w  . j  ava2 s.  co  m
 * @param bootstrap
 * @param groupBoss
 * @param groupWorker
 * @param timeout
 */
public static void setServerBootstrap(ServerBootstrap bootstrap, EventLoopGroup groupBoss,
        EventLoopGroup groupWorker, int timeout) {
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.group(groupBoss, groupWorker);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    bootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
    bootstrap.childOption(ChannelOption.SO_RCVBUF, 1048576);
    bootstrap.childOption(ChannelOption.SO_SNDBUF, 1048576);
}