use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project netty by netty.
the class MqttHeartBeatBroker method main.
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup);
b.option(ChannelOption.SO_BACKLOG, 1024);
b.channel(NioServerSocketChannel.class);
b.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("encoder", MqttEncoder.INSTANCE);
ch.pipeline().addLast("decoder", new MqttDecoder());
ch.pipeline().addLast("heartBeatHandler", new IdleStateHandler(45, 0, 0, TimeUnit.SECONDS));
ch.pipeline().addLast("handler", MqttHeartBeatBrokerHandler.INSTANCE);
}
});
ChannelFuture f = b.bind(1883).sync();
System.out.println("Broker initiated...");
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project netty by netty.
the class FlowControlHandlerTest method testSwallowedReadComplete.
@Test
public void testSwallowedReadComplete() throws Exception {
final long delayMillis = 100;
final Queue<IdleStateEvent> userEvents = new LinkedBlockingQueue<IdleStateEvent>();
final EmbeddedChannel channel = new EmbeddedChannel(false, false, new FlowControlHandler(), new IdleStateHandler(delayMillis, 0, 0, MILLISECONDS), new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.fireChannelActive();
ctx.read();
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ctx.fireChannelRead(msg);
ctx.read();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.fireChannelReadComplete();
ctx.read();
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof IdleStateEvent) {
userEvents.add((IdleStateEvent) evt);
}
ctx.fireUserEventTriggered(evt);
}
});
channel.config().setAutoRead(false);
assertFalse(channel.config().isAutoRead());
channel.register();
// Reset read timeout by some message
assertTrue(channel.writeInbound(Unpooled.EMPTY_BUFFER));
channel.flushInbound();
assertEquals(Unpooled.EMPTY_BUFFER, channel.readInbound());
// Emulate 'no more messages in NIO channel' on the next read attempt.
channel.flushInbound();
assertNull(channel.readInbound());
Thread.sleep(delayMillis + 20L);
channel.runPendingTasks();
assertEquals(IdleStateEvent.FIRST_READER_IDLE_STATE_EVENT, userEvents.poll());
assertFalse(channel.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project vert.x by eclipse.
the class HttpServerWorker method configureHttp1OrH2C.
private void configureHttp1OrH2C(ChannelPipeline pipeline) {
if (logEnabled) {
pipeline.addLast("logging", new LoggingHandler(options.getActivityLogDataFormat()));
}
if (HttpServerImpl.USE_FLASH_POLICY_HANDLER) {
pipeline.addLast("flashpolicy", new FlashPolicyHandler());
}
pipeline.addLast("httpDecoder", new VertxHttpRequestDecoder(options));
pipeline.addLast("httpEncoder", new VertxHttpResponseEncoder());
if (options.isDecompressionSupported()) {
pipeline.addLast("inflater", new HttpContentDecompressor(false));
}
if (options.isCompressionSupported()) {
pipeline.addLast("deflater", new HttpChunkContentCompressor(options.getCompressionLevel()));
}
if (sslHelper.isSSL() || options.isCompressionSupported()) {
// only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
// For large file / sendfile support
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
}
int idleTimeout = options.getIdleTimeout();
int readIdleTimeout = options.getReadIdleTimeout();
int writeIdleTimeout = options.getWriteIdleTimeout();
if (idleTimeout > 0 || readIdleTimeout > 0 || writeIdleTimeout > 0) {
pipeline.addLast("idle", new IdleStateHandler(readIdleTimeout, writeIdleTimeout, idleTimeout, options.getIdleTimeoutUnit()));
}
if (disableH2C) {
configureHttp1(pipeline);
} else {
pipeline.addLast("h2c", new Http1xUpgradeToH2CHandler(this, options.isCompressionSupported(), options.isDecompressionSupported()));
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project vert.x by eclipse.
the class HttpServerWorker method configureHttp2.
void configureHttp2(ChannelPipeline pipeline) {
if (!server.requestAccept()) {
// That should send an HTTP/2 go away
pipeline.channel().close();
return;
}
int idleTimeout = options.getIdleTimeout();
int readIdleTimeout = options.getReadIdleTimeout();
int writeIdleTimeout = options.getWriteIdleTimeout();
if (idleTimeout > 0 || readIdleTimeout > 0 || writeIdleTimeout > 0) {
pipeline.addBefore("handler", "idle", new IdleStateHandler(readIdleTimeout, writeIdleTimeout, idleTimeout, options.getIdleTimeoutUnit()));
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project vert.x by eclipse.
the class HttpChannelConnector method applyHttp1xConnectionOptions.
private void applyHttp1xConnectionOptions(ChannelPipeline pipeline) {
int idleTimeout = options.getIdleTimeout();
int readIdleTimeout = options.getReadIdleTimeout();
int writeIdleTimeout = options.getWriteIdleTimeout();
if (idleTimeout > 0 || readIdleTimeout > 0 || writeIdleTimeout > 0) {
pipeline.addLast("idle", new IdleStateHandler(readIdleTimeout, writeIdleTimeout, idleTimeout, options.getIdleTimeoutUnit()));
}
if (options.getLogActivity()) {
pipeline.addLast("logging", new LoggingHandler(options.getActivityLogDataFormat()));
}
pipeline.addLast("codec", new HttpClientCodec(options.getMaxInitialLineLength(), options.getMaxHeaderSize(), options.getMaxChunkSize(), false, !HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION, options.getDecoderInitialBufferSize()));
if (options.isTryUseCompression()) {
pipeline.addLast("inflater", new HttpContentDecompressor(false));
}
}
Aggregations