7
7
import java .util .Set ;
8
8
import java .util .concurrent .ConcurrentHashMap ;
9
9
import java .util .function .Function ;
10
+
10
11
import org .dataloader .stats .Statistics ;
11
12
12
13
/**
@@ -22,7 +23,6 @@ public class DataLoaderRegistry {
22
23
*
23
24
* @param key the key to put the data loader under
24
25
* @param dataLoader the data loader to register
25
- *
26
26
* @return this registry
27
27
*/
28
28
public DataLoaderRegistry register (String key , DataLoader <?, ?> dataLoader ) {
@@ -33,15 +33,14 @@ public DataLoaderRegistry register(String key, DataLoader<?, ?> dataLoader) {
33
33
/**
34
34
* Computes a data loader if absent or return it if it was
35
35
* already registered at that key.
36
- *
36
+ * <p>
37
37
* Note: The entire method invocation is performed atomically,
38
38
* so the function is applied at most once per key.
39
39
*
40
- * @param key the key of the data loader
40
+ * @param key the key of the data loader
41
41
* @param mappingFunction the function to compute a data loader
42
- * @param <K> the type of keys
43
- * @param <V> the type of values
44
- *
42
+ * @param <K> the type of keys
43
+ * @param <V> the type of values
45
44
* @return a data loader
46
45
*/
47
46
@ SuppressWarnings ("unchecked" )
@@ -55,7 +54,6 @@ public <K, V> DataLoader<K, V> computeIfAbsent(final String key,
55
54
* and return a new combined registry
56
55
*
57
56
* @param registry the registry to combine into this registry
58
- *
59
57
* @return a new combined registry
60
58
*/
61
59
public DataLoaderRegistry combine (DataLoaderRegistry registry ) {
@@ -77,7 +75,6 @@ public DataLoaderRegistry combine(DataLoaderRegistry registry) {
77
75
* This will unregister a new dataloader
78
76
*
79
77
* @param key the key of the data loader to unregister
80
- *
81
78
* @return this registry
82
79
*/
83
80
public DataLoaderRegistry unregister (String key ) {
@@ -91,7 +88,6 @@ public DataLoaderRegistry unregister(String key) {
91
88
* @param key the key of the data loader
92
89
* @param <K> the type of keys
93
90
* @param <V> the type of values
94
- *
95
91
* @return a data loader or null if its not present
96
92
*/
97
93
@ SuppressWarnings ("unchecked" )
@@ -114,6 +110,32 @@ public void dispatchAll() {
114
110
getDataLoaders ().forEach (DataLoader ::dispatch );
115
111
}
116
112
113
+ /**
114
+ * Similar to {@link DataLoaderRegistry#dispatchAll()}, this calls {@link org.dataloader.DataLoader#dispatch()} on
115
+ * each of the registered {@link org.dataloader.DataLoader}s, but returns the number of dispatches.
116
+ *
117
+ * @return total number of entries that were dispatched from registered {@link org.dataloader.DataLoader}s.
118
+ */
119
+ public int dispatchAllWithCount () {
120
+ int sum = 0 ;
121
+ for (DataLoader dataLoader : getDataLoaders ()) {
122
+ sum += dataLoader .dispatchWithCounts ().totalEntriesHandled ;
123
+ }
124
+ return sum ;
125
+ }
126
+
127
+ /**
128
+ * @return The sum of all batched key loads that need to be dispatched from all registered
129
+ * {@link org.dataloader.DataLoader}s
130
+ */
131
+ public int dispatchDepth () {
132
+ int totalDispatchDepth = 0 ;
133
+ for (DataLoader dataLoader : getDataLoaders ()) {
134
+ totalDispatchDepth += dataLoader .dispatchDepth ();
135
+ }
136
+ return totalDispatchDepth ;
137
+ }
138
+
117
139
/**
118
140
* @return a combined set of statistics for all data loaders in this registry presented
119
141
* as the sum of all their statistics
0 commit comments