|
20 | 20 | import com.uber.m3.tally.Buckets;
|
21 | 21 | import com.uber.m3.tally.Capabilities;
|
22 | 22 | import com.uber.m3.tally.CapableOf;
|
23 |
| -import com.uber.m3.tally.RootScopeBuilder; |
| 23 | +import com.uber.m3.tally.Counter; |
| 24 | +import com.uber.m3.tally.Gauge; |
| 25 | +import com.uber.m3.tally.Histogram; |
24 | 26 | import com.uber.m3.tally.Scope;
|
25 |
| -import com.uber.m3.tally.StatsReporter; |
| 27 | +import com.uber.m3.tally.Stopwatch; |
| 28 | +import com.uber.m3.tally.Timer; |
26 | 29 | import com.uber.m3.util.Duration;
|
27 | 30 | import java.util.Map;
|
28 | 31 |
|
29 |
| -public final class NoopScope { |
30 |
| - private static class NoopReporter implements StatsReporter { |
31 |
| - |
32 |
| - @Override |
33 |
| - public void reportCounter(String name, Map<String, String> tags, long value) {} |
34 |
| - |
35 |
| - @Override |
36 |
| - public void reportGauge(String name, Map<String, String> tags, double value) {} |
37 |
| - |
38 |
| - @Override |
39 |
| - public void reportTimer(String name, Map<String, String> tags, Duration interval) {} |
40 |
| - |
41 |
| - @Override |
42 |
| - public void reportHistogramValueSamples( |
43 |
| - String name, |
44 |
| - Map<String, String> tags, |
45 |
| - Buckets buckets, |
46 |
| - double bucketLowerBound, |
47 |
| - double bucketUpperBound, |
48 |
| - long samples) {} |
49 |
| - |
50 |
| - @Override |
51 |
| - public void reportHistogramDurationSamples( |
52 |
| - String name, |
53 |
| - Map<String, String> tags, |
54 |
| - Buckets buckets, |
55 |
| - Duration bucketLowerBound, |
56 |
| - Duration bucketUpperBound, |
57 |
| - long samples) {} |
58 |
| - |
59 |
| - @Override |
60 |
| - public Capabilities capabilities() { |
61 |
| - return CapableOf.REPORTING_TAGGING; |
62 |
| - } |
| 32 | +public final class NoopScope implements Scope { |
| 33 | + private static Scope noopScope; |
| 34 | + private static Counter noopCounter; |
| 35 | + private static Gauge noopGauge; |
| 36 | + private static Timer noopTimer; |
| 37 | + private static Histogram noopHistogram; |
63 | 38 |
|
64 |
| - @Override |
65 |
| - public void flush() {} |
| 39 | + @Override |
| 40 | + public Counter counter(String name) { |
| 41 | + return noopCounter; |
| 42 | + } |
66 | 43 |
|
67 |
| - @Override |
68 |
| - public void close() {} |
| 44 | + @Override |
| 45 | + public Gauge gauge(String name) { |
| 46 | + return noopGauge; |
69 | 47 | }
|
70 | 48 |
|
71 |
| - private NoopScope() {} |
| 49 | + @Override |
| 50 | + public Timer timer(String name) { |
| 51 | + return noopTimer; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public Histogram histogram(String name, Buckets buckets) { |
| 56 | + return noopHistogram; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public Scope tagged(Map<String, String> tags) { |
| 61 | + return this; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public Scope subScope(String name) { |
| 66 | + return this; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public Capabilities capabilities() { |
| 71 | + return CapableOf.NONE; |
| 72 | + } |
72 | 73 |
|
73 |
| - private static Scope instance; |
| 74 | + @Override |
| 75 | + public void close() {} |
| 76 | + |
| 77 | + private NoopScope() {} |
74 | 78 |
|
75 | 79 | public static synchronized Scope getInstance() {
|
76 |
| - if (instance == null) { |
77 |
| - instance = |
78 |
| - new RootScopeBuilder().reporter(new NoopReporter()).reportEvery(Duration.ofMinutes(1)); |
| 80 | + if (noopScope == null) { |
| 81 | + noopCounter = delta -> {}; |
| 82 | + noopGauge = value -> {}; |
| 83 | + noopTimer = |
| 84 | + new Timer() { |
| 85 | + @Override |
| 86 | + public void record(Duration interval) {} |
| 87 | + |
| 88 | + @Override |
| 89 | + public Stopwatch start() { |
| 90 | + return new Stopwatch(0, stopwatchStart -> {}); |
| 91 | + } |
| 92 | + }; |
| 93 | + noopHistogram = |
| 94 | + new Histogram() { |
| 95 | + @Override |
| 96 | + public void recordValue(double value) {} |
| 97 | + |
| 98 | + @Override |
| 99 | + public void recordDuration(Duration value) {} |
| 100 | + |
| 101 | + @Override |
| 102 | + public Stopwatch start() { |
| 103 | + return new Stopwatch(0, stopwatchStart -> {}); |
| 104 | + } |
| 105 | + }; |
| 106 | + |
| 107 | + noopScope = new NoopScope(); |
79 | 108 | }
|
80 |
| - return instance; |
| 109 | + return noopScope; |
81 | 110 | }
|
82 | 111 | }
|
0 commit comments