use of io.netty.handler.timeout.IdleStateEvent in project vert.x by eclipse.
the class HttpServerWorker method configurePipeline.
private void configurePipeline(Channel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslHelper.isSSL()) {
if (options.isSni()) {
SniHandler sniHandler = new SniHandler(sslHelper.serverNameMapper(vertx));
pipeline.addLast(sniHandler);
} else {
SslHandler handler = new SslHandler(sslHelper.createEngine(vertx));
handler.setHandshakeTimeout(sslHelper.getSslHandshakeTimeout(), sslHelper.getSslHandshakeTimeoutUnit());
pipeline.addLast("ssl", handler);
}
ChannelPromise p = ch.newPromise();
pipeline.addLast("handshaker", new SslHandshakeCompletionHandler(p));
p.addListener(future -> {
if (future.isSuccess()) {
if (options.isUseAlpn()) {
SslHandler sslHandler = pipeline.get(SslHandler.class);
String protocol = sslHandler.applicationProtocol();
if ("h2".equals(protocol)) {
handleHttp2(ch);
} else {
handleHttp1(ch);
}
} else {
handleHttp1(ch);
}
} else {
handleException(future.cause());
}
});
} else {
if (disableH2C) {
handleHttp1(ch);
} else {
IdleStateHandler idle;
int idleTimeout = options.getIdleTimeout();
int readIdleTimeout = options.getReadIdleTimeout();
int writeIdleTimeout = options.getWriteIdleTimeout();
if (idleTimeout > 0 || readIdleTimeout > 0 || writeIdleTimeout > 0) {
pipeline.addLast("idle", idle = new IdleStateHandler(readIdleTimeout, writeIdleTimeout, idleTimeout, options.getIdleTimeoutUnit()));
} else {
idle = null;
}
// Handler that detects whether the HTTP/2 connection preface or just process the request
// with the HTTP 1.x pipeline to support H2C with prior knowledge, i.e a client that connects
// and uses HTTP/2 in clear text directly without an HTTP upgrade.
pipeline.addLast(new Http1xOrH2CHandler() {
@Override
protected void configure(ChannelHandlerContext ctx, boolean h2c) {
if (idle != null) {
// It will be re-added but this way we don't need to pay attention to order
pipeline.remove(idle);
}
if (h2c) {
handleHttp2(ctx.channel());
} else {
handleHttp1(ch);
}
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == IdleState.ALL_IDLE) {
ctx.close();
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
handleException(cause);
}
});
}
}
}
use of io.netty.handler.timeout.IdleStateEvent in project cxf by apache.
the class NettyHttpServletHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.READER_IDLE || e.state() == IdleState.WRITER_IDLE) {
LOG.log(Level.FINE, "Closing idle channel: {}", e.state());
ctx.close();
}
}
}
use of io.netty.handler.timeout.IdleStateEvent in project cassandra by apache.
the class PipelineConfigurator method configureInitialPipeline.
public void configureInitialPipeline(Channel channel, Connection.Factory connectionFactory) {
ChannelPipeline pipeline = channel.pipeline();
// Add the ConnectionLimitHandler to the pipeline if configured to do so.
if (DatabaseDescriptor.getNativeTransportMaxConcurrentConnections() > 0 || DatabaseDescriptor.getNativeTransportMaxConcurrentConnectionsPerIp() > 0) {
// Add as first to the pipeline so the limit is enforced as first action.
pipeline.addFirst(CONNECTION_LIMIT_HANDLER, connectionLimitHandler);
}
long idleTimeout = DatabaseDescriptor.nativeTransportIdleTimeout();
if (idleTimeout > 0) {
pipeline.addLast(IDLE_STATE_HANDLER, new IdleStateHandler(false, 0, 0, idleTimeout, TimeUnit.MILLISECONDS) {
@Override
protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) {
logger.info("Closing client connection {} after timeout of {}ms", channel.remoteAddress(), idleTimeout);
ctx.close();
}
});
}
if (DEBUG)
pipeline.addLast(DEBUG_HANDLER, new LoggingHandler(LogLevel.INFO));
pipeline.addLast(ENVELOPE_ENCODER, Envelope.Encoder.instance);
pipeline.addLast(INITIAL_HANDLER, new InitialConnectionHandler(new Envelope.Decoder(), connectionFactory, this));
// The exceptionHandler will take care of handling exceptionCaught(...) events while still running
// on the same EventLoop as all previous added handlers in the pipeline. This is important as the used
// eventExecutorGroup may not enforce strict ordering for channel events.
// As the exceptionHandler runs in the EventLoop as the previous handlers we are sure all exceptions are
// correctly handled before the handler itself is removed.
// See https://issues.apache.org/jira/browse/CASSANDRA-13649
pipeline.addLast(EXCEPTION_HANDLER, PreV5Handlers.ExceptionHandler.instance);
onInitialPipelineReady(pipeline);
}
use of io.netty.handler.timeout.IdleStateEvent in project zuul by Netflix.
the class ZuulFilterChainHandler method userEventTriggered.
@Override
public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof CompleteEvent) {
final CompleteEvent completeEvent = (CompleteEvent) evt;
fireEndpointFinish(completeEvent.getReason() != SESSION_COMPLETE);
} else if (evt instanceof HttpRequestReadTimeoutEvent) {
sendResponse(FAILURE_CLIENT_TIMEOUT, 408, ctx);
} else if (evt instanceof IdleStateEvent) {
sendResponse(FAILURE_LOCAL_IDLE_TIMEOUT, 504, ctx);
} else if (evt instanceof RequestCancelledEvent) {
if (zuulRequest != null) {
StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulRequest.getContext(), FAILURE_CLIENT_CANCELLED);
}
fireEndpointFinish(true);
ctx.close();
}
super.userEventTriggered(ctx, evt);
}
use of io.netty.handler.timeout.IdleStateEvent in project java by wavefrontHQ.
the class IdleStateEventHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
// close idle connections
InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress();
logger.info("Closing idle connection on port " + localAddress.getPort() + ", remote address: " + remoteAddress.getAddress().getHostAddress());
idleClosedConnections.inc();
ctx.channel().close();
}
}
}
Aggregations