use of io.netty.channel.group.DefaultChannelGroup in project rest.li by linkedin.
the class ChannelPoolManagerFactoryImpl method buildHttp2Stream.
@Override
public ChannelPoolManager buildHttp2Stream(ChannelPoolManagerKey channelPoolManagerKey) {
DefaultChannelGroup channelGroup = new DefaultChannelGroup("R2 client channels", _eventLoopGroup.next());
ChannelPoolFactory channelPoolFactory;
if (_usePipelineV2) {
channelPoolFactory = new Http2ChannelPoolFactory(_scheduler, _eventLoopGroup, channelGroup, channelPoolManagerKey.getStrategy(), channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getMaxPoolSize(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.getPoolWaiterSize(), MAX_INITIAL_LINE_LENGTH, channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getMaxResponseSize(), channelPoolManagerKey.isTcpNoDelay(), _enableSSLSessionResumption, _connectTimeout, _sslHandShakeTimeout);
} else {
channelPoolFactory = new Http2NettyStreamChannelPoolFactory(channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getPoolWaiterSize(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.isTcpNoDelay(), _scheduler, channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getGracefulShutdownTimeout(), channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getMaxResponseSize(), _enableSSLSessionResumption, _eventLoopGroup, channelGroup, _connectTimeout, _sslHandShakeTimeout);
}
return new ChannelPoolManagerImpl(channelPoolFactory, channelPoolManagerKey.getName() + "-HTTP/2-Stream", channelGroup, _scheduler);
}
use of io.netty.channel.group.DefaultChannelGroup in project rest.li by linkedin.
the class ChannelPoolManagerFactoryImpl method buildStream.
@Override
public ChannelPoolManager buildStream(ChannelPoolManagerKey channelPoolManagerKey) {
DefaultChannelGroup channelGroup = new DefaultChannelGroup("R2 client channels", _eventLoopGroup.next());
ChannelPoolFactory channelPoolFactory;
if (_usePipelineV2) {
channelPoolFactory = new HttpChannelPoolFactory(_scheduler, _eventLoopGroup, channelGroup, channelPoolManagerKey.getStrategy(), channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getMaxPoolSize(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.getPoolWaiterSize(), MAX_INITIAL_LINE_LENGTH, channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getMaxConcurrentConnectionInitializations(), channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getMaxResponseSize(), channelPoolManagerKey.isTcpNoDelay(), _enableSSLSessionResumption, _channelPoolWaiterTimeout, _connectTimeout, _sslHandShakeTimeout);
} else {
channelPoolFactory = new HttpNettyStreamChannelPoolFactory(channelPoolManagerKey.getMaxPoolSize(), channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getPoolWaiterSize(), channelPoolManagerKey.getStrategy(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.isTcpNoDelay(), _scheduler, channelPoolManagerKey.getMaxConcurrentConnectionInitializations(), channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getMaxResponseSize(), _enableSSLSessionResumption, _eventLoopGroup, channelGroup, _channelPoolWaiterTimeout, _connectTimeout, _sslHandShakeTimeout);
}
return new ChannelPoolManagerImpl(channelPoolFactory, channelPoolManagerKey.getName() + "-Stream", channelGroup, _scheduler);
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class HttpServerTests method testGracefulShutdown.
@Test
void testGracefulShutdown() throws Exception {
CountDownLatch latch1 = new CountDownLatch(2);
CountDownLatch latch2 = new CountDownLatch(2);
CountDownLatch latch3 = new CountDownLatch(1);
LoopResources loop = LoopResources.create("testGracefulShutdown");
disposableServer = createServer().runOn(loop).doOnConnection(c -> {
c.onDispose().subscribe(null, null, latch2::countDown);
latch1.countDown();
}).channelGroup(new DefaultChannelGroup(new DefaultEventExecutor())).route(r -> r.get("/delay500", (req, res) -> res.sendString(Mono.just("delay500").delayElement(Duration.ofMillis(500)))).get("/delay1000", (req, res) -> res.sendString(Mono.just("delay1000").delayElement(Duration.ofSeconds(1))))).bindNow(Duration.ofSeconds(30));
HttpClient client = createClient(disposableServer::address);
AtomicReference<String> result = new AtomicReference<>();
Flux.just("/delay500", "/delay1000").flatMap(s -> client.get().uri(s).responseContent().aggregate().asString()).collect(Collectors.joining()).subscribe(s -> {
result.set(s);
latch3.countDown();
});
assertThat(latch1.await(30, TimeUnit.SECONDS)).isTrue();
// Stop accepting incoming requests, wait at most 3s for the active requests to finish
disposableServer.disposeNow();
assertThat(latch2.await(30, TimeUnit.SECONDS)).isTrue();
// Dispose the event loop
loop.disposeLater().block(Duration.ofSeconds(30));
assertThat(latch3.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(result.get()).isNotNull().isEqualTo("delay500delay1000");
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class ConnectionPoolTests method testClientWithChannelGroup.
@Test
void testClientWithChannelGroup() {
HttpClient localClient1 = client.port(server1.port()).channelGroup(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE));
HttpClient localClient2 = localClient1.channelGroup(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE));
checkResponsesAndChannelsStates("server1-ConnectionPoolTests", "server1-ConnectionPoolTests", localClient1, localClient2);
}
use of io.netty.channel.group.DefaultChannelGroup in project reactor-netty by reactor.
the class TcpServerTests method testGracefulShutdown.
@Test
void testGracefulShutdown() throws Exception {
CountDownLatch latch1 = new CountDownLatch(2);
CountDownLatch latch2 = new CountDownLatch(2);
CountDownLatch latch3 = new CountDownLatch(1);
LoopResources loop = LoopResources.create("testGracefulShutdown");
DisposableServer disposableServer = TcpServer.create().port(0).runOn(loop).doOnConnection(c -> {
c.onDispose().subscribe(null, null, latch2::countDown);
latch1.countDown();
}).channelGroup(new DefaultChannelGroup(new DefaultEventExecutor())).handle((in, out) -> out.sendString(Mono.just("delay1000").delayElement(Duration.ofSeconds(1)))).wiretap(true).bindNow(Duration.ofSeconds(30));
TcpClient client = TcpClient.create().remoteAddress(disposableServer::address).wiretap(true);
AtomicReference<String> result = new AtomicReference<>();
Flux.merge(client.connect(), client.connect()).flatMap(conn -> conn.inbound().receive().asString()).collect(Collectors.joining()).subscribe(s -> {
result.set(s);
latch3.countDown();
});
assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
// Stop accepting incoming requests, wait at most 3s for the active requests to finish
disposableServer.disposeNow();
// Dispose the event loop
loop.disposeLater().block(Duration.ofSeconds(30));
assertThat(latch2.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(latch3.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(result.get()).isNotNull().isEqualTo("delay1000delay1000");
}
Aggregations