All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.graylog2.inputs.transports.netty.PromiseFailureHandler Maven / Gradle / Ivy

There is a newer version: 6.1.4
Show newest version
/*
 * Copyright (C) 2020 Graylog, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Server Side Public License, version 1,
 * as published by MongoDB, Inc.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Server Side Public License for more details.
 *
 * You should have received a copy of the Server Side Public License
 * along with this program. If not, see
 * .
 */
package org.graylog2.inputs.transports.netty;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Singleton;

@Singleton
@ChannelHandler.Sharable
public class PromiseFailureHandler extends ChannelOutboundHandlerAdapter {
    public static final PromiseFailureHandler INSTANCE = new PromiseFailureHandler();
    private static final Logger LOG = LoggerFactory.getLogger(PromiseFailureHandler.class);

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        promise.addListener(Listener.INSTANCE);
        super.write(ctx, msg, promise);
    }


    private static final class Listener implements ChannelFutureListener {
        private static final Listener INSTANCE = new Listener();

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                LOG.info("Write on channel {} failed", future.channel(), future.cause());
            }
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy