/**
 * Copyright (C) 2015 Zalando SE (http://tech.zalando.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zalando.stups.fullstop.plugin.count;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;

import com.google.common.collect.Maps;

/**
 * @author  jbellmann
 */
@Component
public class CountEventsMetric {

    private static final String METER = "meter.events.";

    private final MetricRegistry metricRegistry;

    private final Map<String, Meter> eventMeters = new HashMap<String, Meter>();
// private final Map<String, Counter> eventCounter = new HashMap<String, Counter>();

    @Autowired
    public CountEventsMetric(final MetricRegistry metricRegistry) {
        this.metricRegistry = metricRegistry;
    }

    public Map<String, Meter> getEventMeters() {
        return Maps.newHashMap(eventMeters);
    }

    protected Meter getOrCreateMeter(final Map<String, Meter> meters, final String name) {
        Meter m = meters.get(name);
        if (null != null) {
            return m;
        }

        synchronized (this) {
            m = meters.get(name);
            if (m != null) {
                return m;
            } else {
                Meter created = metricRegistry.meter(name);
                meters.put(name, created);
                return created;
            }
        }
    }

// protected Counter getOrCreateCounter(final Map<String, Counter> counters, final String name) {
// Counter c = counters.get(name);
// if (c != null) {
// return c;
// }
//
// synchronized (this) {
// c = counters.get(name);
// if (c != null) {
// return c;
// } else {
// Counter created = metricRegistry.counter(name);
// counters.put(name, created);
// return created;
// }
// }
// }

    public void markEvent(final String event) {
        getOrCreateMeter(eventMeters, METER + event).mark();
    }
}

@@ -1222,93 +1222,8 @@
 %3E();
-%0A// private final Map%3CString, Counter%3E eventCounter = new HashMap%3CString, Counter%3E();
 %0A%0A  
@@ -1955,397 +1955,8 @@
  %7D%0A%0A
-// protected Counter getOrCreateCounter(final Map%3CString, Counter%3E counters, final String name) %7B%0A// Counter c = counters.get(name);%0A// if (c != null) %7B%0A// return c;%0A// %7D%0A//%0A// synchronized (this) %7B%0A// c = counters.get(name);%0A// if (c != null) %7B%0A// return c;%0A// %7D else %7B%0A// Counter created = metricRegistry.counter(name);%0A// counters.put(name, created);%0A// return created;%0A// %7D%0A// %7D%0A// %7D%0A%0A
     

remove commented code