forked from graphql-java/java-dataloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegatingStatisticsCollector.java
More file actions
103 lines (85 loc) · 3.27 KB
/
DelegatingStatisticsCollector.java
File metadata and controls
103 lines (85 loc) · 3.27 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
92
93
94
95
96
97
98
99
100
101
102
103
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 static org.dataloader.impl.Assertions.nonNull;
/**
* This statistics collector keeps dataloader statistics AND also calls the delegate
* collector at the same time. This allows you to keep a specific set of statistics
* and also delegate the calls onto another collector.
*/
public class DelegatingStatisticsCollector implements StatisticsCollector {
private final StatisticsCollector collector = new SimpleStatisticsCollector();
private final StatisticsCollector delegateCollector;
/**
* @param delegateCollector a non null delegate collector
*/
public DelegatingStatisticsCollector(StatisticsCollector delegateCollector) {
this.delegateCollector = nonNull(delegateCollector);
}
@Override
public <K> void incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
delegateCollector.incrementLoadCount(context);
collector.incrementLoadCount(context);
}
@Deprecated
@Override
public void incrementLoadCount() {
incrementLoadCount(null);
}
@Override
public <K> void incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
delegateCollector.incrementLoadErrorCount(context);
collector.incrementLoadErrorCount(context);
}
@Deprecated
@Override
public void incrementLoadErrorCount() {
incrementLoadErrorCount(null);
}
@Override
public <K> void incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
delegateCollector.incrementBatchLoadCountBy(delta, context);
collector.incrementBatchLoadCountBy(delta, context);
}
@Deprecated
@Override
public void incrementBatchLoadCountBy(long delta) {
incrementBatchLoadCountBy(delta, null);
}
@Override
public <K> void incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
delegateCollector.incrementBatchLoadExceptionCount(context);
collector.incrementBatchLoadExceptionCount(context);
}
@Deprecated
@Override
public void incrementBatchLoadExceptionCount() {
incrementBatchLoadExceptionCount(null);
}
@Override
public <K> void incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
delegateCollector.incrementCacheHitCount(context);
collector.incrementCacheHitCount(context);
}
@Deprecated
@Override
public void incrementCacheHitCount() {
incrementCacheHitCount(null);
}
/**
* @return the statistics of the collector (and not its delegate)
*/
@Override
public Statistics getStatistics() {
return collector.getStatistics();
}
/**
* @return the statistics of the delegate
*/
public Statistics getDelegateStatistics() {
return delegateCollector.getStatistics();
}
}