Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2012 Palomino Labs, Inc.
  */
 
 package com.palominolabs.metrics.jersey;
 
Filter that increments per-status-code counters.
    private final ConcurrentMap<IntegerCountercounters = new ConcurrentHashMap<>();
    private final Class<?> resourceClass;
    private final String metricBaseName;
    private final MetricRegistry metricsRegistry;
    HttpStatusCodeCounterResourceFilter(MetricRegistry metricsRegistryString metricBaseNameClass<?> resourceClass) {
        this. = metricsRegistry;
        this. = metricBaseName;
        this. = resourceClass;
    }
    @Override
        // don't filter requests
        return null;
    }
    @Override
        return this;
    }
    @Override
    public ContainerResponse filter(ContainerRequest requestContainerResponse response) {
        Integer status = response.getStatus();
        Counter counter = .get(status);
        if (counter == null) {
            // despite the method name, this actually will return a previously created metric with the same name
            Counter newCounter = .counter(
                MetricRegistry.name( + " " + status + " counter"));
            Counter otherCounter = .putIfAbsent(statusnewCounter);
            if (otherCounter != null) {
                // we lost the race to set that counter, but shouldn't create a duplicate since Metrics.newCounter will do the right thing
                counter = otherCounter;
            } else {
                counter = newCounter;
            }
        }
        counter.inc();
        return response;
    }
New to GrepCode? Check out our FAQ X