use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project async-http-client by AsyncHttpClient.
the class HttpStaticFileServerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpStaticFileServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project async-http-client by AsyncHttpClient.
the class ChannelManager method configureBootstraps.
public void configureBootstraps(NettyRequestSender requestSender) {
final AsyncHttpClientHandler httpHandler = new HttpHandler(config, this, requestSender);
wsHandler = new WebSocketHandler(config, this, requestSender);
final LoggingHandler loggingHandler = new LoggingHandler(LogLevel.TRACE);
httpBootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
ChannelPipeline pipeline = ch.pipeline().addLast(HTTP_CLIENT_CODEC, newHttpClientCodec()).addLast(INFLATER_HANDLER, newHttpContentDecompressor()).addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler()).addLast(AHC_HTTP_HANDLER, httpHandler);
if (LOGGER.isTraceEnabled()) {
pipeline.addFirst(LOGGING_HANDLER, loggingHandler);
}
if (config.getHttpAdditionalChannelInitializer() != null)
config.getHttpAdditionalChannelInitializer().accept(ch);
}
});
wsBootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
ChannelPipeline pipeline = ch.pipeline().addLast(HTTP_CLIENT_CODEC, newHttpClientCodec()).addLast(AHC_WS_HANDLER, wsHandler);
if (config.isEnableWebSocketCompression()) {
pipeline.addBefore(AHC_WS_HANDLER, WS_COMPRESSOR_HANDLER, WebSocketClientCompressionHandler.INSTANCE);
}
if (LOGGER.isDebugEnabled()) {
pipeline.addFirst(LOGGING_HANDLER, loggingHandler);
}
if (config.getWsAdditionalChannelInitializer() != null)
config.getWsAdditionalChannelInitializer().accept(ch);
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project ambry by linkedin.
the class MockChannelHandlerContext method completeRequestWithDelayedCloseTest.
/**
* Tests the invocation of DELAYED_CLOSE when post failures happen in {@link NettyResponseChannel}.
*/
@Test
public void completeRequestWithDelayedCloseTest() throws Exception {
Properties properties = new Properties();
long delayMs = 500;
properties.setProperty(NettyConfig.NETTY_SERVER_CLOSE_DELAY_TIMEOUT_MS, String.valueOf(delayMs));
NettyConfig nettyConfig = new NettyConfig(new VerifiableProperties(properties));
MockNettyMessageProcessor processor = new MockNettyMessageProcessor();
processor.setNettyConfig(nettyConfig);
ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler();
EmbeddedChannel channel = new EmbeddedChannel(chunkedWriteHandler, processor);
RestServiceErrorCode REST_ERROR_CODE = RestServiceErrorCode.BadRequest;
String content = "@@randomContent@@@";
HttpHeaders httpHeaders = new DefaultHttpHeaders();
httpHeaders.set(MockNettyMessageProcessor.REST_SERVICE_ERROR_CODE_HEADER_NAME, REST_ERROR_CODE);
httpHeaders.set(MockNettyMessageProcessor.INCLUDE_EXCEPTION_MESSAGE_IN_RESPONSE_HEADER_NAME, "true");
HttpRequest httpRequest = RestTestUtils.createFullRequest(HttpMethod.POST, TestingUri.OnResponseCompleteWithRestException.toString(), httpHeaders, content.getBytes());
channel.writeInbound(httpRequest);
HttpResponse response = channel.readOutbound();
assertEquals("Unexpected response status", getExpectedHttpResponseStatus(REST_ERROR_CODE), response.status());
// channel should not be closed right away.
assertTrue("Channel closed on the server", channel.isActive());
// wait for delayed time * 2 times (to rule out timing out on border) and then check again.
Thread.sleep(delayMs * 2);
channel.runPendingTasks();
assertFalse("Channel not closed on the server", channel.isActive());
assertEquals("delayed close scheduled counter mismatch", 1, processor.getNettyMetrics().delayedCloseScheduledCount.getCount());
assertEquals("delayed close executed counter mismatch", 1, processor.getNettyMetrics().delayedCloseExecutedCount.getCount());
assertEquals("delayed close expired counter mismatch", 1, processor.getNettyMetrics().delayedCloseActivatedCount.getCount());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project ambry by linkedin.
the class MockChannelHandlerContext method createEmbeddedChannel.
/**
* Creates a new {@link EmbeddedChannel} with a {@link ChunkedWriteHandler} and {@link MockNettyMessageProcessor} in
* the pipeline.
* @return the created {@link EmbeddedChannel}.
*/
private EmbeddedChannel createEmbeddedChannel() {
ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler();
MockNettyMessageProcessor processor = new MockNettyMessageProcessor();
return new EmbeddedChannel(chunkedWriteHandler, processor);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project ambry by linkedin.
the class NettyPerfClient method start.
/**
* Starts the NettyPerfClient.
* @throws InterruptedException
*/
protected void start() {
logger.info("Starting NettyPerfClient");
reporter.start();
group = new NioEventLoopGroup(concurrency);
perfClientStartTime = System.currentTimeMillis();
for (String host : hosts) {
logger.info("Connecting to {}:{}", host, port);
// create a new bootstrap with a fixed remote address for each host. This is the simplest way to support
// reconnection on failure. All bootstraps will share the same event loop group.
Bootstrap bootstrap = new Bootstrap().group(group).channel(NioSocketChannel.class).remoteAddress(host, port);
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
logger.info("Initializing the channel to {}:{}", host, port);
if (sslFactory != null) {
ch.pipeline().addLast(new SslHandler(sslFactory.createSSLEngine(host, port, SSLFactory.Mode.CLIENT)));
}
ch.pipeline().addLast(new HttpClientCodec()).addLast(new ChunkedWriteHandler()).addLast(new ResponseHandler(bootstrap));
}
});
for (int i = 0; i < concurrency; i++) {
ChannelFuture future = bootstrap.connect();
future.addListener(channelConnectListener);
}
hostToRequestCount.put(host, new AtomicLong(0));
hostToSleepTime.put(host, sleepTimeInMs);
}
if (backgroundScheduler != null) {
backgroundScheduler.scheduleAtFixedRate(updater, 0, 1, TimeUnit.SECONDS);
logger.info("Background scheduler is instantiated to update sleep time.");
}
isRunning = true;
logger.info("Created {} channel(s) per remote host", concurrency);
logger.info("NettyPerfClient started");
}
Aggregations