Search in sources :

Example 1 with SimpleChannelUpstreamHandler

use of org.jboss.netty.channel.SimpleChannelUpstreamHandler 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)

Example 2 with SimpleChannelUpstreamHandler

use of org.jboss.netty.channel.SimpleChannelUpstreamHandler in project cdap by caskdata.

the class NettyRouter method startUp.

@Override
protected void startUp() throws ServiceBindException {
    ChannelUpstreamHandler connectionTracker = new SimpleChannelUpstreamHandler() {

        @Override
        public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
            channelGroup.add(e.getChannel());
            super.channelOpen(ctx, e);
        }
    };
    tokenValidator.startAndWait();
    timer = new HashedWheelTimer(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("router-idle-event-generator-timer").build());
    bootstrapClient(connectionTracker);
    bootstrapServer(connectionTracker);
}
Also used : SimpleChannelUpstreamHandler(org.jboss.netty.channel.SimpleChannelUpstreamHandler) ChannelUpstreamHandler(org.jboss.netty.channel.ChannelUpstreamHandler) ChannelStateEvent(org.jboss.netty.channel.ChannelStateEvent) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ChannelHandlerContext(org.jboss.netty.channel.ChannelHandlerContext) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) SimpleChannelUpstreamHandler(org.jboss.netty.channel.SimpleChannelUpstreamHandler)

Aggregations

ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)2 SimpleChannelUpstreamHandler (org.jboss.netty.channel.SimpleChannelUpstreamHandler)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Callable (java.util.concurrent.Callable)1 MisfireException (org.graylog2.plugin.inputs.MisfireException)1 PacketInformationDumper (org.graylog2.plugin.inputs.util.PacketInformationDumper)1 ChannelHandler (org.jboss.netty.channel.ChannelHandler)1 ChannelStateEvent (org.jboss.netty.channel.ChannelStateEvent)1 ChannelUpstreamHandler (org.jboss.netty.channel.ChannelUpstreamHandler)1 ExceptionEvent (org.jboss.netty.channel.ExceptionEvent)1 SimpleChannelHandler (org.jboss.netty.channel.SimpleChannelHandler)1 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)1