use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project turbo-rpc by hank-whu.
the class NettyRestServer method start.
public void start() throws InterruptedException {
InetSocketAddress inet = new InetSocketAddress(hostPort.host, hostPort.port);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(eventLoopGroup);
bootstrap.option(ChannelOption.SO_BACKLOG, 256);
bootstrap.option(ChannelOption.SO_REUSEADDR, true);
if (eventLoopGroup instanceof EpollEventLoopGroup) {
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
bootstrap.channel(EpollServerSocketChannel.class);
} else if (eventLoopGroup instanceof NioEventLoopGroup) {
bootstrap.channel(NioServerSocketChannel.class);
}
bootstrap.childHandler(new NettyRestChannelInitializer(invokerFactory, jsonMapper, filters));
bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
channel = bootstrap.bind(inet).sync().channel();
System.out.println("NettyRestServer started. Listening on: " + hostPort);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project turbo-rpc by hank-whu.
the class NettyRpcServer method start.
public void start() throws InterruptedException {
InetSocketAddress inet = new InetSocketAddress(hostPort.host, hostPort.port);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(eventLoopGroup);
bootstrap.option(ChannelOption.SO_BACKLOG, 256);
bootstrap.option(ChannelOption.SO_REUSEADDR, true);
if (eventLoopGroup instanceof EpollEventLoopGroup) {
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
bootstrap.channel(EpollServerSocketChannel.class);
} else if (eventLoopGroup instanceof NioEventLoopGroup) {
bootstrap.channel(NioServerSocketChannel.class);
}
bootstrap.childHandler(new NettyRpcChannelInitializer(invokerFactory, serializer, filters));
bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
channel = bootstrap.bind(inet).sync().channel();
System.out.println("TurboRpcServer started. Listening on: " + hostPort);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.
the class TcpIngester method run.
public void run() {
activeListeners.inc();
ServerBootstrap b = new ServerBootstrap();
EventLoopGroup parentGroup;
EventLoopGroup childGroup;
Class<? extends ServerChannel> socketChannelClass;
if (Epoll.isAvailable()) {
logger.fine("Using native socket transport for port " + listeningPort);
parentGroup = new EpollEventLoopGroup(1);
childGroup = new EpollEventLoopGroup();
socketChannelClass = EpollServerSocketChannel.class;
} else {
logger.fine("Using NIO socket transport for port " + listeningPort);
parentGroup = new NioEventLoopGroup(1);
childGroup = new NioEventLoopGroup();
socketChannelClass = NioServerSocketChannel.class;
}
try {
b.group(parentGroup, childGroup).channel(socketChannelClass).option(ChannelOption.SO_BACKLOG, 1024).localAddress(listeningPort).childHandler(initializer);
if (parentChannelOptions != null) {
for (Map.Entry<ChannelOption<?>, ?> entry : parentChannelOptions.entrySet()) {
b.option((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
}
if (childChannelOptions != null) {
for (Map.Entry<ChannelOption<?>, ?> entry : childChannelOptions.entrySet()) {
b.childOption((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
}
// Start the server.
ChannelFuture f = b.bind().sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} catch (final InterruptedException e) {
logger.log(Level.WARNING, "Interrupted");
parentGroup.shutdownGracefully();
childGroup.shutdownGracefully();
logger.info("Listener on port " + String.valueOf(listeningPort) + " shut down");
} catch (Exception e) {
// ChannelFuture throws undeclared checked exceptions, so we need to handle it
if (e instanceof BindException) {
logger.severe("Unable to start listener - port " + String.valueOf(listeningPort) + " is already in use!");
} else {
logger.log(Level.SEVERE, "TcpIngester exception: ", e);
}
} finally {
activeListeners.dec();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.
the class UdpIngester method run.
@Override
public void run() {
activeListeners.inc();
Bootstrap bootstrap = new Bootstrap();
EventLoopGroup group;
Class<? extends Channel> datagramChannelClass;
if (Epoll.isAvailable()) {
logger.fine("Using native socket transport for port " + listeningPort);
group = new EpollEventLoopGroup();
datagramChannelClass = EpollDatagramChannel.class;
} else {
logger.fine("Using NIO socket transport for port " + listeningPort);
group = new NioEventLoopGroup();
datagramChannelClass = NioDatagramChannel.class;
}
try {
bootstrap.group(group).channel(datagramChannelClass).localAddress(listeningPort).handler(initializer);
// Start the server.
bootstrap.bind().sync().channel().closeFuture().sync();
} catch (final InterruptedException e) {
logger.log(Level.WARNING, "Interrupted", e);
} catch (Exception e) {
// ChannelFuture throws undeclared checked exceptions, so we need to handle it
if (e instanceof BindException) {
logger.severe("Unable to start listener - port " + String.valueOf(listeningPort) + " is already in use!");
} else {
logger.log(Level.SEVERE, "UdpIngester exception: ", e);
}
} finally {
activeListeners.dec();
group.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.
the class HistogramLineIngester method run.
@Override
public void run() {
activeListeners.inc();
ServerBootstrap bootstrap = new ServerBootstrap();
EventLoopGroup parent;
EventLoopGroup children;
Class<? extends ServerChannel> socketChannelClass;
if (Epoll.isAvailable()) {
logger.fine("Using native socket transport for port " + port);
parent = new EpollEventLoopGroup(1);
children = new EpollEventLoopGroup(handlers.size());
socketChannelClass = EpollServerSocketChannel.class;
} else {
logger.fine("Using NIO socket transport for port " + port);
parent = new NioEventLoopGroup(1);
children = new NioEventLoopGroup(handlers.size());
socketChannelClass = NioServerSocketChannel.class;
}
try {
bootstrap.group(parent, children).channel(socketChannelClass).option(ChannelOption.SO_BACKLOG, MAXIMUM_OUTSTANDING_CONNECTIONS).localAddress(port).childHandler(this);
ChannelFuture f = bootstrap.bind().sync();
f.channel().closeFuture().sync();
} catch (final InterruptedException e) {
logger.log(Level.WARNING, "Interrupted");
parent.shutdownGracefully();
children.shutdownGracefully();
logger.info("Listener on port " + String.valueOf(port) + " shut down");
} catch (Exception e) {
// ChannelFuture throws undeclared checked exceptions, so we need to handle it
if (e instanceof BindException) {
logger.severe("Unable to start listener - port " + String.valueOf(port) + " is already in use!");
} else {
logger.log(Level.SEVERE, "HistogramLineIngester exception: ", e);
}
} finally {
activeListeners.dec();
}
}
Aggregations