Search in sources :

Example 81 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project vert.x by eclipse.

the class HttpChannelConnector method wrap.

public Future<HttpClientConnection> wrap(EventLoopContext context, NetSocket so_) {
    NetSocketImpl so = (NetSocketImpl) so_;
    Object metric = so.metric();
    Promise<HttpClientConnection> promise = context.promise();
    // Remove all un-necessary handlers
    ChannelPipeline pipeline = so.channelHandlerContext().pipeline();
    List<ChannelHandler> removedHandlers = new ArrayList<>();
    for (Map.Entry<String, ChannelHandler> stringChannelHandlerEntry : pipeline) {
        ChannelHandler handler = stringChannelHandlerEntry.getValue();
        if (!(handler instanceof SslHandler)) {
            removedHandlers.add(handler);
        }
    }
    removedHandlers.forEach(pipeline::remove);
    // 
    Channel ch = so.channelHandlerContext().channel();
    if (ssl) {
        String protocol = so.applicationLayerProtocol();
        if (useAlpn) {
            if ("h2".equals(protocol)) {
                applyHttp2ConnectionOptions(ch.pipeline());
                http2Connected(context, metric, ch, promise);
            } else {
                applyHttp1xConnectionOptions(ch.pipeline());
                HttpVersion fallbackProtocol = "http/1.0".equals(protocol) ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1;
                http1xConnected(fallbackProtocol, server, true, context, metric, ch, promise);
            }
        } else {
            applyHttp1xConnectionOptions(ch.pipeline());
            http1xConnected(version, server, true, context, metric, ch, promise);
        }
    } else {
        if (version == HttpVersion.HTTP_2) {
            if (this.options.isHttp2ClearTextUpgrade()) {
                applyHttp1xConnectionOptions(pipeline);
                http1xConnected(version, server, false, context, metric, ch, promise);
            } else {
                applyHttp2ConnectionOptions(pipeline);
                http2Connected(context, metric, ch, promise);
            }
        } else {
            applyHttp1xConnectionOptions(pipeline);
            http1xConnected(version, server, false, context, metric, ch, promise);
        }
    }
    return promise.future();
}
Also used : Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler) NetSocketImpl(io.vertx.core.net.impl.NetSocketImpl) Map(java.util.Map) HttpVersion(io.vertx.core.http.HttpVersion)

Example 82 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.

the class AbstractTcpTransport method getBootstrap.

protected ServerBootstrap getBootstrap(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> parentHandlers = getChannelHandlers(input);
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> childHandlers = getChildChannelHandlers(input);
    childEventLoopGroup = eventLoopGroupFactory.create(workerThreads, localRegistry, "workers");
    return new ServerBootstrap().group(parentEventLoopGroup, childEventLoopGroup).channelFactory(new ServerSocketChannelFactory(nettyTransportConfiguration.getType())).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(8192)).option(ChannelOption.SO_RCVBUF, getRecvBufferSize()).childOption(ChannelOption.SO_RCVBUF, getRecvBufferSize()).childOption(ChannelOption.SO_KEEPALIVE, tcpKeepalive).handler(getChannelInitializer(parentHandlers)).childHandler(getChannelInitializer(childHandlers));
}
Also used : ServerSocketChannelFactory(org.graylog2.inputs.transports.netty.ServerSocketChannelFactory) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) ChannelHandler(io.netty.channel.ChannelHandler) ExceptionLoggingChannelHandler(org.graylog2.inputs.transports.netty.ExceptionLoggingChannelHandler) Callable(java.util.concurrent.Callable) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 83 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.

the class AbstractTcpTransport method getChildChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChildChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
    final CodecAggregator aggregator = getAggregator();
    handlers.put("channel-registration", () -> new ChannelRegistrationHandler(childChannels));
    handlers.put("traffic-counter", () -> throughputCounter);
    handlers.put("connection-counter", () -> connectionCounter);
    if (tlsEnable) {
        LOG.info("Enabled TLS for input [{}/{}]. key-file=\"{}\" cert-file=\"{}\"", input.getName(), input.getId(), tlsKeyFile, tlsCertFile);
        handlers.put("tls", getSslHandlerCallable(input));
    }
    handlers.putAll(getCustomChildChannelHandlers(input));
    if (aggregator != null) {
        LOG.debug("Adding codec aggregator {} to channel pipeline", aggregator);
        handlers.put("codec-aggregator", () -> new ByteBufMessageAggregationHandler(aggregator, localRegistry));
    }
    handlers.put("rawmessage-handler", () -> new RawMessageHandler(input));
    handlers.put("exception-logger", () -> new ExceptionLoggingChannelHandler(input, LOG, this.tcpKeepalive));
    return handlers;
}
Also used : CodecAggregator(org.graylog2.plugin.inputs.codecs.CodecAggregator) ExceptionLoggingChannelHandler(org.graylog2.inputs.transports.netty.ExceptionLoggingChannelHandler) ByteBufMessageAggregationHandler(org.graylog2.inputs.transports.netty.ByteBufMessageAggregationHandler) ChannelRegistrationHandler(org.graylog2.inputs.transports.netty.ChannelRegistrationHandler) ChannelHandler(io.netty.channel.ChannelHandler) ExceptionLoggingChannelHandler(org.graylog2.inputs.transports.netty.ExceptionLoggingChannelHandler) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) RawMessageHandler(org.graylog2.inputs.transports.netty.RawMessageHandler)

Example 84 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.

the class NettyTransport method getChannelInitializer.

protected ChannelInitializer<? extends Channel> getChannelInitializer(final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList) {
    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            final ChannelPipeline p = ch.pipeline();
            Map.Entry<String, Callable<? extends ChannelHandler>> postentry = null;
            for (final Map.Entry<String, Callable<? extends ChannelHandler>> entry : handlerList.entrySet()) {
                // Handle exceptions at the top of the (bottom-up evaluated) pipeline
                if (entry.getKey().equals("exception-logger")) {
                    postentry = entry;
                } else {
                    p.addLast(entry.getKey(), entry.getValue().call());
                }
            }
            if (postentry != null) {
                p.addLast(postentry.getKey(), postentry.getValue().call());
            }
        }
    };
}
Also used : Channel(io.netty.channel.Channel) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelHandler(io.netty.channel.ChannelHandler) ExceptionLoggingChannelHandler(org.graylog2.inputs.transports.netty.ExceptionLoggingChannelHandler) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ChannelPipeline(io.netty.channel.ChannelPipeline) Callable(java.util.concurrent.Callable)

Example 85 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.

the class TcpTransport method getCustomChildChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getCustomChildChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> childChannelHandlers = new LinkedHashMap<>();
    childChannelHandlers.put("framer", () -> new LenientDelimiterBasedFrameDecoder(maxFrameLength, delimiter));
    childChannelHandlers.putAll(super.getCustomChildChannelHandlers(input));
    return childChannelHandlers;
}
Also used : LenientDelimiterBasedFrameDecoder(org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoder) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ChannelHandler (io.netty.channel.ChannelHandler)216 Test (org.junit.Test)88 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)44 Channel (io.netty.channel.Channel)27 ChannelPipeline (io.netty.channel.ChannelPipeline)26 SslHandler (io.netty.handler.ssl.SslHandler)25 Test (org.junit.jupiter.api.Test)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)23 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)21 FilterChainMatchingHandler (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler)20 ChannelFuture (io.netty.channel.ChannelFuture)20 FilterChainSelector (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler.FilterChainSelector)19 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)18 InetSocketAddress (java.net.InetSocketAddress)18 DownstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext)17 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)17 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 TcpIngester (com.wavefront.ingester.TcpIngester)15 ByteBuf (io.netty.buffer.ByteBuf)13