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