use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup 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 org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project uavstack by uavorg.
the class AbstractHttpServiceComponent2 method start.
@Override
public void start(int port, int backlog, int listenThreadCount, int handleThreadCount, boolean forceExit) {
EventLoopGroup bossGroup = new NioEventLoopGroup(listenThreadCount);
EventLoopGroup workerGroup = new NioEventLoopGroup(handleThreadCount);
server = new ServerBootstrap();
server.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).localAddress(port).option(ChannelOption.SO_BACKLOG, backlog).childHandler(new HttpServerInitializer(this));
try {
this.host = NetworkHelper.getLocalIP();
this.port = port;
// Start the server.
server.bind().sync();
if (log.isTraceEnable()) {
log.info(this, "HttpServiceComponent[" + this.cName + "] for feature[" + this.feature + "] started SUCCESS: port=" + this.port);
}
} catch (InterruptedException e) {
log.err(this, "HttpServiceComponent[" + this.cName + "] for feature[" + this.feature + "] starts FAIL.", e);
if (forceExit == true) {
System.exit(-1);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project java-in-action by xinghalo.
the class EchoClient method start.
public void start() throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).remoteAddress(new InetSocketAddress(host, port)).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast(new EchoClientHandler());
}
});
ChannelFuture f = b.connect().sync();
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully().sync();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project java-in-action by xinghalo.
the class EchoServer method start.
public void start() throws Exception {
final EchoServerHandler serverHandler = new EchoServerHandler();
EventLoopGroup group = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(group).channel(NioServerSocketChannel.class).localAddress(new InetSocketAddress(port)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast(serverHandler);
}
});
ChannelFuture f = b.bind().sync();
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully().sync();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project java-in-action by xinghalo.
the class TimeClient method connect.
public void connect(int port, String host) throws InterruptedException {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new TimeClientHandler());
}
});
ChannelFuture f = b.connect(host, port);
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully().sync();
}
}
Aggregations