forked from graphql-java/java-dataloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleStatisticsCollector.java
More file actions
91 lines (75 loc) · 2.82 KB
/
SimpleStatisticsCollector.java
File metadata and controls
91 lines (75 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package org.dataloader.stats;
import org.dataloader.stats.context.IncrementBatchLoadCountByStatisticsContext;
import org.dataloader.stats.context.IncrementBatchLoadExceptionCountStatisticsContext;
import org.dataloader.stats.context.IncrementCacheHitCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadErrorCountStatisticsContext;
import java.util.concurrent.atomic.LongAdder;
/**
* This simple collector uses {@link java.util.concurrent.atomic.AtomicLong}s to collect
* statistics
*
* @see org.dataloader.stats.StatisticsCollector
*/
public class SimpleStatisticsCollector implements StatisticsCollector {
private final LongAdder loadCount = new LongAdder();
private final LongAdder batchInvokeCount = new LongAdder();
private final LongAdder batchLoadCount = new LongAdder();
private final LongAdder cacheHitCount = new LongAdder();
private final LongAdder batchLoadExceptionCount = new LongAdder();
private final LongAdder loadErrorCount = new LongAdder();
@Override
public <K> void incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
loadCount.increment();
}
@Deprecated
@Override
public void incrementLoadCount() {
incrementLoadCount(null);
}
@Override
public <K> void incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
loadErrorCount.increment();
}
@Deprecated
@Override
public void incrementLoadErrorCount() {
incrementLoadErrorCount(null);
}
@Override
public <K> void incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
batchInvokeCount.increment();
batchLoadCount.add(delta);
}
@Deprecated
@Override
public void incrementBatchLoadCountBy(long delta) {
incrementBatchLoadCountBy(delta, null);
}
@Override
public <K> void incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
batchLoadExceptionCount.increment();
}
@Deprecated
@Override
public void incrementBatchLoadExceptionCount() {
incrementBatchLoadExceptionCount(null);
}
@Override
public <K> void incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
cacheHitCount.increment();
}
@Deprecated
@Override
public void incrementCacheHitCount() {
incrementCacheHitCount(null);
}
@Override
public Statistics getStatistics() {
return new Statistics(loadCount.sum(), loadErrorCount.sum(), batchInvokeCount.sum(), batchLoadCount.sum(), batchLoadExceptionCount.sum(), cacheHitCount.sum());
}
@Override
public String toString() {
return getStatistics().toString();
}
}