Search in sources :

Example 26 with IdleStateEvent

use of org.apache.flink.shaded.netty4.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);
                }
            });
        }
    }
}
Also used : SniHandler(io.netty.handler.ssl.SniHandler) SslHandler(io.netty.handler.ssl.SslHandler) IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) SslHandshakeCompletionHandler(io.vertx.core.net.impl.SslHandshakeCompletionHandler)

Example 27 with IdleStateEvent

use of org.apache.flink.shaded.netty4.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();
        }
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent)

Example 28 with IdleStateEvent

use of org.apache.flink.shaded.netty4.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);
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) LoggingHandler(io.netty.handler.logging.LoggingHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ByteToMessageDecoder(io.netty.handler.codec.ByteToMessageDecoder)

Example 29 with IdleStateEvent

use of org.apache.flink.shaded.netty4.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);
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) HttpRequestReadTimeoutEvent(com.netflix.netty.common.HttpRequestReadTimeoutEvent) RequestCancelledEvent(com.netflix.zuul.netty.RequestCancelledEvent) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)

Example 30 with IdleStateEvent

use of org.apache.flink.shaded.netty4.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();
        }
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)30 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)6 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)4 Channel (io.netty.channel.Channel)3 SocketChannel (io.netty.channel.socket.SocketChannel)3 SslHandshakeCompletionEvent (io.netty.handler.ssl.SslHandshakeCompletionEvent)3 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 SslHandler (io.netty.handler.ssl.SslHandler)2 InetSocketAddress (java.net.InetSocketAddress)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseMessage (com.bonree.brfs.common.net.tcp.BaseMessage)1 BaseResponse (com.bonree.brfs.common.net.tcp.BaseResponse)1 TokenMessage (com.bonree.brfs.common.net.tcp.TokenMessage)1 CompleteReason (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)1 HttpRequestReadTimeoutEvent (com.netflix.netty.common.HttpRequestReadTimeoutEvent)1 OutboundException (com.netflix.zuul.exception.OutboundException)1