Skip to content

Commit 8ae3fb2

Browse files
committed
Extract interfaces for everything.
1 parent 45256db commit 8ae3fb2

File tree

16 files changed

+559
-488
lines changed

16 files changed

+559
-488
lines changed

metrics-core/src/main/java/com/yammer/metrics/Metrics.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ private static void append(StringBuilder builder, String part) {
7575
}
7676

7777
public static Counter counter() {
78-
return new Counter();
78+
return new CounterImpl();
7979
}
8080

8181
public static Histogram histogram() {
8282
return histogram(Histogram.SampleType.UNIFORM);
8383
}
8484

85-
public static Histogram histogram(Histogram.SampleType type) {
85+
public static Histogram histogram(HistogramImpl.SampleType type) {
8686
return histogram(type.newSample());
8787
}
8888

8989
public static Histogram histogram(Sample sample) {
90-
return new Histogram(sample);
90+
return new HistogramImpl(sample);
9191
}
9292

9393
public static Meter meter(String eventType, TimeUnit rateUnit, Clock clock) {
94-
return new Meter(eventType, rateUnit, clock);
94+
return new MeterImpl(eventType, rateUnit, clock);
9595
}
9696

9797
public static Meter meter(String eventType, TimeUnit rateUnit) {
@@ -107,7 +107,7 @@ public static Meter meter() {
107107
}
108108

109109
public static Timer timer(TimeUnit durationUnit, TimeUnit rateUnit, Clock clock) {
110-
return new Timer(durationUnit, rateUnit, clock);
110+
return new TimerImpl(durationUnit, rateUnit, clock);
111111
}
112112

113113
public static Timer timer(TimeUnit durationUnit, TimeUnit rateUnit) {

metrics-core/src/main/java/com/yammer/metrics/core/Clock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.lang.management.ThreadMXBean;
55

66
/**
7-
* An abstraction for how time passes. It is passed to {@link Timer} to track timing.
7+
* An abstraction for how time passes. It is passed to {@link Timer} and others to track timing.
88
*/
99
public abstract class Clock {
1010
/**
Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,42 @@
11
package com.yammer.metrics.core;
22

3-
import java.util.concurrent.atomic.AtomicLong;
4-
53
/**
64
* An incrementing and decrementing counter metric.
75
*/
8-
public class Counter implements Metric {
9-
private final AtomicLong count;
10-
11-
public Counter() {
12-
this.count = new AtomicLong(0);
13-
}
14-
6+
public interface Counter extends Metric {
157
/**
168
* Increment the counter by one.
179
*/
18-
public void inc() {
19-
inc(1);
20-
}
10+
void inc();
2111

2212
/**
2313
* Increment the counter by {@code n}.
2414
*
2515
* @param n the amount by which the counter will be increased
2616
*/
27-
public void inc(long n) {
28-
count.addAndGet(n);
29-
}
17+
void inc(long n);
3018

3119
/**
3220
* Decrement the counter by one.
3321
*/
34-
public void dec() {
35-
dec(1);
36-
}
22+
void dec();
3723

3824
/**
3925
* Decrement the counter by {@code n}.
4026
*
4127
* @param n the amount by which the counter will be increased
4228
*/
43-
public void dec(long n) {
44-
count.addAndGet(0 - n);
45-
}
29+
void dec(long n);
4630

4731
/**
4832
* Returns the counter's current value.
4933
*
5034
* @return the counter's current value
5135
*/
52-
public long getCount() {
53-
return count.get();
54-
}
36+
long getCount();
5537

5638
/**
5739
* Resets the counter to 0.
5840
*/
59-
public void clear() {
60-
count.set(0);
61-
}
41+
void clear();
6242
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.yammer.metrics.core;
2+
3+
import java.util.concurrent.atomic.AtomicLong;
4+
5+
/**
6+
* The default implementation of {@link Counter}.
7+
*/
8+
public class CounterImpl implements Counter {
9+
private final AtomicLong count;
10+
11+
public CounterImpl() {
12+
this.count = new AtomicLong(0);
13+
}
14+
15+
@Override
16+
public void inc() {
17+
inc(1);
18+
}
19+
20+
@Override
21+
public void inc(long n) {
22+
count.addAndGet(n);
23+
}
24+
25+
@Override
26+
public void dec() {
27+
dec(1);
28+
}
29+
30+
@Override
31+
public void dec(long n) {
32+
count.addAndGet(0 - n);
33+
}
34+
35+
@Override
36+
public long getCount() {
37+
return count.get();
38+
}
39+
40+
@Override
41+
public void clear() {
42+
count.set(0);
43+
}
44+
}

0 commit comments

Comments
 (0)