use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project netty by netty.
the class SniHandlerTest method testSniWithApnHandler.
@Test
public void testSniWithApnHandler() throws Exception {
SslContext nettyContext = makeSslContext(provider, true);
SslContext sniContext = makeSslContext(provider, true);
final SslContext clientContext = makeSslClientContext(provider, true);
try {
final CountDownLatch serverApnDoneLatch = new CountDownLatch(1);
final CountDownLatch clientApnDoneLatch = new CountDownLatch(1);
final DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext).add("*.netty.io", nettyContext).add("sni.fake.site", sniContext).build();
final SniHandler handler = new SniHandler(mapping);
EventLoopGroup group = new NioEventLoopGroup(2);
Channel serverChannel = null;
Channel clientChannel = null;
try {
ServerBootstrap sb = new ServerBootstrap();
sb.group(group);
sb.channel(NioServerSocketChannel.class);
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// Server side SNI.
p.addLast(handler);
// Catch the notification event that APN has completed successfully.
p.addLast(new ApplicationProtocolNegotiationHandler("foo") {
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
serverApnDoneLatch.countDown();
}
});
}
});
Bootstrap cb = new Bootstrap();
cb.group(group);
cb.channel(NioSocketChannel.class);
cb.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new SslHandler(clientContext.newEngine(ch.alloc(), "sni.fake.site", -1)));
// Catch the notification event that APN has completed successfully.
ch.pipeline().addLast(new ApplicationProtocolNegotiationHandler("foo") {
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
clientApnDoneLatch.countDown();
}
});
}
});
serverChannel = sb.bind(new InetSocketAddress(0)).sync().channel();
ChannelFuture ccf = cb.connect(serverChannel.localAddress());
assertTrue(ccf.awaitUninterruptibly().isSuccess());
clientChannel = ccf.channel();
assertTrue(serverApnDoneLatch.await(5, TimeUnit.SECONDS));
assertTrue(clientApnDoneLatch.await(5, TimeUnit.SECONDS));
assertThat(handler.hostname(), is("sni.fake.site"));
assertThat(handler.sslContext(), is(sniContext));
} finally {
if (serverChannel != null) {
serverChannel.close().sync();
}
if (clientChannel != null) {
clientChannel.close().sync();
}
group.shutdownGracefully(0, 0, TimeUnit.MICROSECONDS);
}
} finally {
releaseAll(clientContext, nettyContext, sniContext);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project grpc-java by grpc.
the class Utils method newNettyClientChannel.
private static NettyChannelBuilder newNettyClientChannel(Transport transport, SocketAddress address, boolean tls, boolean testca, int flowControlWindow, boolean useDefaultCiphers) throws IOException {
NettyChannelBuilder builder = NettyChannelBuilder.forAddress(address).flowControlWindow(flowControlWindow);
if (tls) {
builder.negotiationType(NegotiationType.TLS);
SslContext sslContext = null;
if (testca) {
File cert = TestUtils.loadCert("ca.pem");
SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient().trustManager(cert);
if (transport == Transport.NETTY_NIO) {
sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.JDK);
} else {
// Native transport with OpenSSL
sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.OPENSSL);
}
if (useDefaultCiphers) {
sslContextBuilder.ciphers(null);
}
sslContext = sslContextBuilder.build();
}
builder.sslContext(sslContext);
} else {
builder.negotiationType(NegotiationType.PLAINTEXT);
}
DefaultThreadFactory tf = new DefaultThreadFactory("client-elg-", true);
switch(transport) {
case NETTY_NIO:
builder.eventLoopGroup(new NioEventLoopGroup(0, tf)).channelType(NioSocketChannel.class);
break;
case NETTY_EPOLL:
// These classes only work on Linux.
builder.eventLoopGroup(new EpollEventLoopGroup(0, tf)).channelType(EpollSocketChannel.class);
break;
case NETTY_UNIX_DOMAIN_SOCKET:
// These classes only work on Linux.
builder.eventLoopGroup(new EpollEventLoopGroup(0, tf)).channelType(EpollDomainSocketChannel.class);
break;
default:
// Should never get here.
throw new IllegalArgumentException("Unsupported transport: " + transport);
}
return builder;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project rest.li by linkedin.
the class TestHttpClientFactory method testShutdownAfterClients.
@Test
public void testShutdownAfterClients() throws Exception {
NioEventLoopGroup eventLoop = new NioEventLoopGroup();
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
HttpClientFactory factory = getHttpClientFactory(eventLoop, true, scheduler, true);
Server server = new HttpServerBuilder().build();
try {
server.start();
List<Client> clients = new ArrayList<Client>();
for (int i = 0; i < 1; i++) {
clients.add(new TransportClientAdapter(factory.getClient(Collections.<String, String>emptyMap()), true));
}
for (Client c : clients) {
RestRequest r = new RestRequestBuilder(new URI(URI)).build();
FutureCallback<RestResponse> futureCallback = new FutureCallback<RestResponse>();
c.restRequest(r, futureCallback);
futureCallback.get(30, TimeUnit.SECONDS);
}
for (Client c : clients) {
FutureCallback<None> callback = new FutureCallback<None>();
c.shutdown(callback);
callback.get(30, TimeUnit.SECONDS);
}
FutureCallback<None> factoryShutdown = new FutureCallback<None>();
factory.shutdown(factoryShutdown);
factoryShutdown.get(30, TimeUnit.SECONDS);
Assert.assertTrue(eventLoop.awaitTermination(30, TimeUnit.SECONDS), "Failed to shut down event-loop");
Assert.assertTrue(scheduler.awaitTermination(30, TimeUnit.SECONDS), "Failed to shut down scheduler");
} finally {
server.stop();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project camel by apache.
the class NettyUDPByteArrayProviderTest method createNettyUdpReceiver.
public void createNettyUdpReceiver() {
group = new NioEventLoopGroup();
bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioDatagramChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(new UdpHandler());
channel.pipeline().addLast(new ByteArrayDecoder());
channel.pipeline().addLast(new ContentHandler());
}
}).localAddress(new InetSocketAddress(getPort()));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project camel by apache.
the class NettyUdpConnectedSendTest method createNettyUdpReceiver.
public void createNettyUdpReceiver() {
group = new NioEventLoopGroup();
bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioDatagramChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(new UdpHandler());
channel.pipeline().addLast(new ContentHandler());
}
}).localAddress(new InetSocketAddress(getPort()));
}
Aggregations