Search in sources :

Example 1 with ChannelHandler

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

the class HttpTransport method getBaseChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> baseChannelHandlers = super.getBaseChannelHandlers(input);
    if (idleWriterTimeout > 0) {
        // Install read timeout handler to close idle connections after a timeout.
        // This avoids dangling HTTP connections when the HTTP client does not close the connection properly.
        // For details see: https://github.com/Graylog2/graylog2-server/issues/3223#issuecomment-270350500
        baseChannelHandlers.put("read-timeout-handler", () -> new ReadTimeoutHandler(timer, idleWriterTimeout, TimeUnit.SECONDS));
    }
    baseChannelHandlers.put("decoder", () -> new HttpRequestDecoder(DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, maxChunkSize));
    baseChannelHandlers.put("aggregator", () -> new HttpChunkAggregator(maxChunkSize));
    baseChannelHandlers.put("encoder", HttpResponseEncoder::new);
    baseChannelHandlers.put("decompressor", HttpContentDecompressor::new);
    return baseChannelHandlers;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ReadTimeoutHandler(org.jboss.netty.handler.timeout.ReadTimeoutHandler) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) HttpContentDecompressor(org.jboss.netty.handler.codec.http.HttpContentDecompressor)

Example 2 with ChannelHandler

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

the class SyslogTcpTransport method getFinalChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getFinalChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalChannelHandlers = Maps.newLinkedHashMap();
    finalChannelHandlers.putAll(super.getFinalChannelHandlers(input));
    // Replace the "framer" channel handler inserted by the parent.
    finalChannelHandlers.put("framer", new Callable<ChannelHandler>() {

        @Override
        public ChannelHandler call() throws Exception {
            return new SyslogTCPFramingRouterHandler(maxFrameLength, delimiter);
        }
    });
    return finalChannelHandlers;
}
Also used : SyslogTCPFramingRouterHandler(org.graylog2.inputs.syslog.tcp.SyslogTCPFramingRouterHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable)

Example 3 with ChannelHandler

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

the class TcpTransport method getFinalChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getFinalChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalChannelHandlers = Maps.newLinkedHashMap();
    finalChannelHandlers.put("framer", new Callable<ChannelHandler>() {

        @Override
        public ChannelHandler call() throws Exception {
            return new DelimiterBasedFrameDecoder(maxFrameLength, delimiter);
        }
    });
    finalChannelHandlers.putAll(super.getFinalChannelHandlers(input));
    return finalChannelHandlers;
}
Also used : DelimiterBasedFrameDecoder(org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable)

Example 4 with ChannelHandler

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

the class NettyTransport method launch.

@Override
public void launch(final MessageInput input) throws MisfireException {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = getBaseChannelHandlers(input);
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalHandlers = getFinalChannelHandlers(input);
    handlerList.putAll(finalHandlers);
    try {
        bootstrap = getBootstrap();
        bootstrap.setPipelineFactory(getPipelineFactory(handlerList));
        // sigh, bindable bootstraps do not share a common interface
        int receiveBufferSize;
        if (bootstrap instanceof ConnectionlessBootstrap) {
            acceptChannel = ((ConnectionlessBootstrap) bootstrap).bind(socketAddress);
            final DefaultDatagramChannelConfig channelConfig = (DefaultDatagramChannelConfig) acceptChannel.getConfig();
            receiveBufferSize = channelConfig.getReceiveBufferSize();
        } else if (bootstrap instanceof ServerBootstrap) {
            acceptChannel = ((ServerBootstrap) bootstrap).bind(socketAddress);
            final ServerSocketChannelConfig channelConfig = (ServerSocketChannelConfig) acceptChannel.getConfig();
            receiveBufferSize = channelConfig.getReceiveBufferSize();
        } else {
            log.error("Unknown Netty bootstrap class returned: {}. Cannot safely bind.", bootstrap);
            throw new IllegalStateException("Unknown netty bootstrap class returned: " + bootstrap + ". Cannot safely bind.");
        }
        if (receiveBufferSize != getRecvBufferSize()) {
            log.warn("receiveBufferSize (SO_RCVBUF) for input {} should be {} but is {}.", input, getRecvBufferSize(), receiveBufferSize);
        }
    } catch (Exception e) {
        throw new MisfireException(e);
    }
}
Also used : MisfireException(org.graylog2.plugin.inputs.MisfireException) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) DefaultDatagramChannelConfig(org.jboss.netty.channel.socket.DefaultDatagramChannelConfig) ServerSocketChannelConfig(org.jboss.netty.channel.socket.ServerSocketChannelConfig) Callable(java.util.concurrent.Callable) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) MisfireException(org.graylog2.plugin.inputs.MisfireException) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 5 with ChannelHandler

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

the class NettyTransport method getBaseChannelHandlers.

/**
     * Subclasses can override this to add additional ChannelHandlers to the pipeline to support additional features.
     * <p/>
     * Some common use cases are to add SSL/TLS, connection counters or throttling traffic shapers.
     *
     * @param input
     * @return the list of initial channelhandlers to add to the {@link org.jboss.netty.channel.ChannelPipelineFactory}
     */
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(final MessageInput input) {
    LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = Maps.newLinkedHashMap();
    handlerList.put("exception-logger", new Callable<ChannelHandler>() {

        @Override
        public ChannelHandler call() throws Exception {
            return new SimpleChannelUpstreamHandler() {

                @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
                @Override
                public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
                    if ("Connection reset by peer".equals(e.getCause().getMessage())) {
                        log.trace("{} in Input [{}/{}] (channel {})", e.getCause().getMessage(), input.getName(), input.getId(), e.getChannel());
                    } else {
                        log.error("Error in Input [{}/{}] (channel {})", input.getName(), input.getId(), e.getChannel(), e.getCause());
                    }
                    super.exceptionCaught(ctx, e);
                }
            };
        }
    });
    handlerList.put("packet-meta-dumper", new Callable<ChannelHandler>() {

        @Override
        public ChannelHandler call() throws Exception {
            return new PacketInformationDumper(input);
        }
    });
    handlerList.put("traffic-counter", Callables.returning(throughputCounter));
    return handlerList;
}
Also used : ExceptionEvent(org.jboss.netty.channel.ExceptionEvent) ChannelHandlerContext(org.jboss.netty.channel.ChannelHandlerContext) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) SimpleChannelUpstreamHandler(org.jboss.netty.channel.SimpleChannelUpstreamHandler) PacketInformationDumper(org.graylog2.plugin.inputs.util.PacketInformationDumper) Callable(java.util.concurrent.Callable) MisfireException(org.graylog2.plugin.inputs.MisfireException)

Aggregations

ChannelHandler (org.jboss.netty.channel.ChannelHandler)30 Callable (java.util.concurrent.Callable)12 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)9 ArrayList (java.util.ArrayList)5 MessageInput (org.graylog2.plugin.inputs.MessageInput)5 SimpleChannelHandler (org.jboss.netty.channel.SimpleChannelHandler)5 SslHandler (org.jboss.netty.handler.ssl.SslHandler)5 ReadTimeoutHandler (org.jboss.netty.handler.timeout.ReadTimeoutHandler)5 File (java.io.File)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketAddress (java.net.SocketAddress)4 Configuration (org.graylog2.plugin.configuration.Configuration)4 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4 Channel (org.jboss.netty.channel.Channel)4 Test (org.junit.Test)4 NettyHttpDatabusRelayConnection (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection)3 NettyHttpDatabusRelayConnectionInspector (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnectionInspector)3 Checkpoint (com.linkedin.databus.core.Checkpoint)3 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)3 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)3