Search in sources :

Example 81 with ChannelHandler

use of 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 82 with ChannelHandler

use of 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 83 with ChannelHandler

use of 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 84 with ChannelHandler

use of 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)

Example 85 with ChannelHandler

use of io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.

the class UdpTransportTest method launchTransportForBootStrapTest.

private UdpTransport launchTransportForBootStrapTest(final ChannelInboundHandler channelHandler) throws MisfireException {
    final UdpTransport transport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry()) {

        @Override
        protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(MessageInput input) {
            final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
            handlers.put("logging", () -> new LoggingHandler(LogLevel.INFO));
            handlers.put("counter", () -> channelHandler);
            handlers.putAll(super.getChannelHandlers(input));
            return handlers;
        }
    };
    final MessageInput messageInput = mock(MessageInput.class);
    when(messageInput.getId()).thenReturn("TEST");
    when(messageInput.getName()).thenReturn("TEST");
    transport.launch(messageInput);
    return transport;
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ChannelHandler (io.netty.channel.ChannelHandler)186 Test (org.junit.Test)88 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)44 Channel (io.netty.channel.Channel)26 ChannelPipeline (io.netty.channel.ChannelPipeline)25 SslHandler (io.netty.handler.ssl.SslHandler)25 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)22 FilterChainMatchingHandler (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler)20 ChannelFuture (io.netty.channel.ChannelFuture)20 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)20 FilterChainSelector (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler.FilterChainSelector)19 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)18 DownstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext)17 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)17 InetSocketAddress (java.net.InetSocketAddress)16 Test (org.junit.jupiter.api.Test)16 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Bootstrap (io.netty.bootstrap.Bootstrap)11 ArrayList (java.util.ArrayList)11