Search in sources :

Example 1 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project vert.x by eclipse.

the class NetServerBase method applyConnectionOptions.

/**
   * Apply the connection option to the server.
   *
   * @param bootstrap the Netty server bootstrap
   */
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());
    }
}
Also used : FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator)

Example 2 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project vert.x by eclipse.

the class HttpServerImpl method applyConnectionOptions.

private 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());
    }
}
Also used : FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator)

Example 3 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project camel by apache.

the class SingleUDPNettyServerBootstrapFactory method startServerBootstrap.

protected void startServerBootstrap() throws Exception {
    // create non-shared worker pool
    EventLoopGroup wg = configuration.getWorkerGroup();
    if (wg == null) {
        // create new pool which we should shutdown when stopping as its not shared
        workerGroup = new NettyWorkerPoolBuilder().withNativeTransport(configuration.isNativeTransport()).withWorkerCount(configuration.getWorkerCount()).withName("NettyServerTCPWorker").build();
        wg = workerGroup;
    }
    Bootstrap bootstrap = new Bootstrap();
    if (configuration.isNativeTransport()) {
        bootstrap.group(wg).channel(EpollDatagramChannel.class);
    } else {
        bootstrap.group(wg).channel(NioDatagramChannel.class);
    }
    // We cannot set the child option here      
    bootstrap.option(ChannelOption.SO_REUSEADDR, configuration.isReuseAddress());
    bootstrap.option(ChannelOption.SO_SNDBUF, configuration.getSendBufferSize());
    bootstrap.option(ChannelOption.SO_RCVBUF, configuration.getReceiveBufferSize());
    bootstrap.option(ChannelOption.SO_BROADCAST, configuration.isBroadcast());
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.getConnectTimeout());
    // only set this if user has specified
    if (configuration.getReceiveBufferSizePredictor() > 0) {
        bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(configuration.getReceiveBufferSizePredictor()));
    }
    if (configuration.getBacklog() > 0) {
        bootstrap.option(ChannelOption.SO_BACKLOG, configuration.getBacklog());
    }
    Map<String, Object> options = configuration.getOptions();
    if (options != null) {
        for (Map.Entry<String, Object> entry : options.entrySet()) {
            String value = entry.getValue().toString();
            ChannelOption<Object> option = ChannelOption.valueOf(entry.getKey());
            //TODO: find a way to add primitive Netty options without having to add them to the Camel registry.
            if (EndpointHelper.isReferenceParameter(value)) {
                String name = value.substring(1);
                Object o = CamelContextHelper.mandatoryLookup(camelContext, name);
                bootstrap.option(option, o);
            } else {
                bootstrap.option(option, value);
            }
        }
    }
    LOG.debug("Created Bootstrap {}", bootstrap);
    // set the pipeline factory, which creates the pipeline for each newly created channels
    bootstrap.handler(pipelineFactory);
    InetSocketAddress hostAddress = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    SubnetUtils multicastSubnet = new SubnetUtils(MULTICAST_SUBNET);
    if (multicastSubnet.getInfo().isInRange(configuration.getHost())) {
        ChannelFuture channelFuture = bootstrap.bind(configuration.getPort()).sync();
        channel = channelFuture.channel();
        DatagramChannel datagramChannel = (DatagramChannel) channel;
        String networkInterface = configuration.getNetworkInterface() == null ? LOOPBACK_INTERFACE : configuration.getNetworkInterface();
        multicastNetworkInterface = NetworkInterface.getByName(networkInterface);
        ObjectHelper.notNull(multicastNetworkInterface, "No network interface found for '" + networkInterface + "'.");
        LOG.info("ConnectionlessBootstrap joining {}:{} using network interface: {}", new Object[] { configuration.getHost(), configuration.getPort(), multicastNetworkInterface.getName() });
        datagramChannel.joinGroup(hostAddress, multicastNetworkInterface).syncUninterruptibly();
        allChannels.add(datagramChannel);
    } else {
        LOG.info("ConnectionlessBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
        ChannelFuture channelFuture = bootstrap.bind(hostAddress).sync();
        channel = channelFuture.channel();
        allChannels.add(channel);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SubnetUtils(org.apache.camel.component.netty4.util.SubnetUtils) InetSocketAddress(java.net.InetSocketAddress) EpollDatagramChannel(io.netty.channel.epoll.EpollDatagramChannel) DatagramChannel(io.netty.channel.socket.DatagramChannel) NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) Bootstrap(io.netty.bootstrap.Bootstrap) Map(java.util.Map)

Example 4 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project camel by apache.

the class NettyUDPMessageLargerThanDefaultBufferSizeTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry jndi = super.createRegistry();
    FixedRecvByteBufAllocator fixedRecvByteBufAllocator = new FixedRecvByteBufAllocator(4096);
    jndi.bind(ChannelOption.RCVBUF_ALLOCATOR.name(), fixedRecvByteBufAllocator);
    return jndi;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator)

Example 5 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project bgpcep by opendaylight.

the class BGPDispatcherImpl method createServerBootstrap.

private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);
    serverBootstrap.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
    if (serverBootstrap.config().group() == null) {
        serverBootstrap.group(this.bossGroup, this.workerGroup);
    }
    return serverBootstrap;
}
Also used : FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) ChannelHandler(io.netty.channel.ChannelHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Aggregations

FixedRecvByteBufAllocator (io.netty.channel.FixedRecvByteBufAllocator)20 Bootstrap (io.netty.bootstrap.Bootstrap)6 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 InetSocketAddress (java.net.InetSocketAddress)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 EventLoopGroup (io.netty.channel.EventLoopGroup)3 NioDatagramChannel (io.netty.channel.socket.nio.NioDatagramChannel)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 ServerChannel (io.netty.channel.ServerChannel)2 DatagramChannel (io.netty.channel.socket.DatagramChannel)2 DatagramPacket (io.netty.channel.socket.DatagramPacket)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1