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

com.tacitknowledge.slowlight.proxyserver.metrics.ExceptionCountHandler Maven / Gradle / Ivy

The newest version!
package com.tacitknowledge.slowlight.proxyserver.metrics;

import com.netflix.servo.annotations.DataSourceType;
import com.netflix.servo.annotations.Monitor;
import com.netflix.servo.monitor.Monitors;
import com.tacitknowledge.slowlight.proxyserver.config.HandlerConfig;
import com.tacitknowledge.slowlight.proxyserver.handler.AbstractChannelHandler;
import io.netty.channel.ChannelHandlerContext;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * A {@link io.netty.channel.ChannelHandler} implementation that counts
 * exception occurred inside channel.
 *
 * @author Pavel Sorocun ([email protected])
 */
public class ExceptionCountHandler extends AbstractChannelHandler
{
    @Monitor(name = "ExceptionCount", type = DataSourceType.GAUGE)
    private AtomicInteger exceptionCount = new AtomicInteger(0);

    public ExceptionCountHandler(final HandlerConfig handlerConfig)
    {
        super(handlerConfig);
        Monitors.registerObject(handlerConfig.getName(), this);
    }

    @Override
    public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception
    {
        exceptionCount.getAndIncrement();
    }

    protected int getExceptionCount()
    {
        return exceptionCount.intValue();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy