package org.automon.implentations;

import com.codahale.metrics.Counter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import org.automon.OpenMon;

import static com.codahale.metrics.MetricRegistry.name;

/**
 * Created by stevesouza on 2/26/15.
 */
public class Metrics implements OpenMon<Timer.Context> {
    private MetricRegistry metrics = new MetricRegistry();

    @Override
    public Timer.Context start(String label) {
        Timer timer = metrics.timer(name(label));
        return timer.time();
    }

    @Override
    public void stop(Timer.Context timerContext) {
        timerContext.stop();
        System.out.println("Metrics Timer.Context: "+timerContext);
    }

    @Override
    public void exception(String label) {
        Counter mon = metrics.counter(label);
        mon.inc();
        System.out.println("Metrics counter: "+mon);
    }

    @Override
    public void enable(boolean enable) {

    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}

@@ -321,24 +321,16 @@
 on%3CTimer
-.Context
 %3E %7B%0A    
@@ -415,24 +415,16 @@
 ic Timer
-.Context
  start(S
@@ -450,21 +450,14 @@
     
-Timer timer =
+return
  met
@@ -485,37 +485,8 @@
 ));%0A
-        return timer.time();%0A
     
@@ -532,127 +532,44 @@
 imer
-.Context timerContext) %7B%0A        timerContext.stop();%0A        System.out.println(%22Metrics Timer.Context: %22+timerContext
+ timer) %7B%0A        timer.time().stop(
 );%0A 
@@ -641,22 +641,8 @@
     
- Counter mon =
  met
@@ -664,79 +664,13 @@
 bel)
-;%0A        mon.inc();%0A        System.out.println(%22Metrics counter: %22+mon
+.inc(
 );%0A 
@@ -812,10 +812,189 @@
 ;%0A    %7D%0A
+%0A    public MetricRegistry getMetricRegistry() %7B%0A        return metrics;%0A    %7D%0A%0A    public void setMetricRegistry(MetricRegistry metrics) %7B%0A        this.metrics = metrics;%0A    %7D%0A%0A
 %7D%0A

refactor Metrics class