use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project jdepth by Crab2died.
the class C2DServer method bind.
private void bind(String host, int port) throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new C2DHessianMsgDecoder(1024 * 1024, 4, 4, -8, 0)).addLast("MessageEncoder", new C2DHessianMsgEncoder()).addLast("ReadTimeoutHandler", new ReadTimeoutHandler(TIME_OUT)).addLast("LoginAuthResp", new LoginAuthRespHandler()).addLast("Pong", new PongHandler());
}
});
ChannelFuture future = bootstrap.bind(host, port).sync();
future.channel().closeFuture().sync();
logger.info("server is started");
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project x-pipe by ctripcorp.
the class PsyncLatencyTest method startGetLatency.
private void startGetLatency() {
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Bootstrap b = new Bootstrap();
b.group(eventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new LoggingHandler(LogLevel.DEBUG));
p.addLast(new NettySimpleMessageHandler());
p.addLast(new ReceiveMessageHandler(runId, offset));
}
});
b.connect(dest);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project component-runtime by Talend.
the class HandlerImpl method start.
public synchronized HandlerImpl<T> start() {
if (instance != null) {
throw new IllegalStateException("Instance already started");
}
if (handler.getPort() <= 0) {
handler.setPort(newRandomPort());
}
final CountDownLatch startingPistol = new CountDownLatch(1);
instance = new Thread(() -> {
// todo: config
final EventLoopGroup bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("talend-api-boss"));
final EventLoopGroup workerGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), new DefaultThreadFactory("talend-api-worker"));
try {
final ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_REUSEADDR, true).group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ProxyInitializer(handler)).bind("localhost", handler.getPort()).sync().addListener((ChannelFutureListener) f -> {
if (f.isSuccess()) {
shutdown = () -> {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
};
} else {
log.error("Can't start API server");
}
startingPistol.countDown();
}).channel().closeFuture().sync();
} catch (final InterruptedException e) {
Thread.interrupted();
close();
}
}) {
{
setName("Talend-API-monitor_" + HandlerImpl.this.getClass().getSimpleName() + "_" + HandlerImpl.this.hashCode());
}
};
log.info("Starting Talend API server on port {}", handler.getPort());
instance.start();
try {
if (!startingPistol.await(Integer.getInteger("talend.junit.http.starting.timeout", 60), SECONDS)) {
log.warn("API server took more than the expected timeout to start, you can tune it " + "setting talend.junit.http.starting.timeout system property");
}
} catch (final InterruptedException e) {
Thread.interrupted();
log.warn(e.getMessage());
}
if (shutdown != null && handler.isGlobalProxyConfiguration()) {
final String pt = Integer.toString(handler.getPort());
Stream.of("", "s").forEach(s -> {
shutdown = decorate(setProperty("http" + s + ".proxyHost", "localhost"), shutdown);
shutdown = decorate(setProperty("http" + s + ".proxyPort", pt), shutdown);
shutdown = decorate(setProperty("http" + s + ".nonProxyHosts", "local|*.local"), shutdown);
});
if (handler.getSslContext() != null) {
try {
final SSLContext defaultSslContext = SSLContext.getDefault();
final HostnameVerifier defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
shutdown = decorate(() -> SSLContext.setDefault(defaultSslContext), shutdown);
shutdown = decorate(() -> {
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
}, shutdown);
SSLContext.setDefault(handler.getSslContext());
HttpsURLConnection.setDefaultSSLSocketFactory(handler.getSslContext().getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier((host, sslSession) -> true);
} catch (final NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
}
log.info("Configured the JVM to use the {} API proxy localhost:{}", handler.getSslContext() != null ? "SSL" : "plain", handler.getPort());
}
return this;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project cassandra by apache.
the class ProxyHandlerTest method test.
public void test(DoTest test) throws Throwable {
EventLoopGroup serverGroup = new NioEventLoopGroup(1);
EventLoopGroup clientGroup = new NioEventLoopGroup(1);
InboundProxyHandler.Controller controller = new InboundProxyHandler.Controller();
InboundProxyHandler proxyHandler = new InboundProxyHandler(controller);
TestHandler testHandler = new TestHandler();
ServerBootstrap sb = new ServerBootstrap();
sb.group(serverGroup).channel(LocalServerChannel.class).childHandler(new ChannelInitializer<LocalChannel>() {
@Override
public void initChannel(LocalChannel ch) {
ch.pipeline().addLast(proxyHandler).addLast(testHandler);
}
}).childOption(ChannelOption.AUTO_READ, false);
Bootstrap cb = new Bootstrap();
cb.group(clientGroup).channel(LocalChannel.class).handler(new ChannelInitializer<LocalChannel>() {
@Override
public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
}
});
final LocalAddress addr = new LocalAddress("test");
Channel serverChannel = sb.bind(addr).sync().channel();
Channel clientChannel = cb.connect(addr).sync().channel();
test.doTest(controller, testHandler, clientChannel);
clientChannel.close();
serverChannel.close();
serverGroup.shutdownGracefully();
clientGroup.shutdownGracefully();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project flink by apache.
the class AbstractServerBase method shutdownServer.
/**
* Shuts down the server and all related thread pools.
*
* @return A {@link CompletableFuture} that will be completed upon termination of the shutdown
* process.
*/
public CompletableFuture<Void> shutdownServer() {
CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();
if (serverShutdownFuture.compareAndSet(null, shutdownFuture)) {
log.info("Shutting down {} @ {}", serverName, serverAddress);
final CompletableFuture<Void> groupShutdownFuture = new CompletableFuture<>();
if (bootstrap != null) {
EventLoopGroup group = bootstrap.group();
if (group != null && !group.isShutdown()) {
group.shutdownGracefully(0L, 0L, TimeUnit.MILLISECONDS).addListener(finished -> {
if (finished.isSuccess()) {
groupShutdownFuture.complete(null);
} else {
groupShutdownFuture.completeExceptionally(finished.cause());
}
});
} else {
groupShutdownFuture.complete(null);
}
} else {
groupShutdownFuture.complete(null);
}
final CompletableFuture<Void> handlerShutdownFuture = new CompletableFuture<>();
if (handler == null) {
handlerShutdownFuture.complete(null);
} else {
handler.shutdown().whenComplete((result, throwable) -> {
if (throwable != null) {
handlerShutdownFuture.completeExceptionally(throwable);
} else {
handlerShutdownFuture.complete(null);
}
});
}
final CompletableFuture<Void> queryExecShutdownFuture = CompletableFuture.runAsync(() -> {
if (queryExecutor != null) {
ExecutorUtils.gracefulShutdown(10L, TimeUnit.MINUTES, queryExecutor);
}
});
CompletableFuture.allOf(queryExecShutdownFuture, groupShutdownFuture, handlerShutdownFuture).whenComplete((result, throwable) -> {
if (throwable != null) {
shutdownFuture.completeExceptionally(throwable);
} else {
shutdownFuture.complete(null);
}
});
}
return serverShutdownFuture.get();
}
Aggregations