77import java .util .Set ;
88import java .util .concurrent .ConcurrentHashMap ;
99import java .util .function .Function ;
10+
1011import org .dataloader .stats .Statistics ;
1112
1213/**
@@ -22,7 +23,6 @@ public class DataLoaderRegistry {
2223 *
2324 * @param key the key to put the data loader under
2425 * @param dataLoader the data loader to register
25- *
2626 * @return this registry
2727 */
2828 public DataLoaderRegistry register (String key , DataLoader <?, ?> dataLoader ) {
@@ -33,15 +33,14 @@ public DataLoaderRegistry register(String key, DataLoader<?, ?> dataLoader) {
3333 /**
3434 * Computes a data loader if absent or return it if it was
3535 * already registered at that key.
36- *
36+ * <p>
3737 * Note: The entire method invocation is performed atomically,
3838 * so the function is applied at most once per key.
3939 *
40- * @param key the key of the data loader
40+ * @param key the key of the data loader
4141 * @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
4544 * @return a data loader
4645 */
4746 @ SuppressWarnings ("unchecked" )
@@ -55,7 +54,6 @@ public <K, V> DataLoader<K, V> computeIfAbsent(final String key,
5554 * and return a new combined registry
5655 *
5756 * @param registry the registry to combine into this registry
58- *
5957 * @return a new combined registry
6058 */
6159 public DataLoaderRegistry combine (DataLoaderRegistry registry ) {
@@ -77,7 +75,6 @@ public DataLoaderRegistry combine(DataLoaderRegistry registry) {
7775 * This will unregister a new dataloader
7876 *
7977 * @param key the key of the data loader to unregister
80- *
8178 * @return this registry
8279 */
8380 public DataLoaderRegistry unregister (String key ) {
@@ -91,7 +88,6 @@ public DataLoaderRegistry unregister(String key) {
9188 * @param key the key of the data loader
9289 * @param <K> the type of keys
9390 * @param <V> the type of values
94- *
9591 * @return a data loader or null if its not present
9692 */
9793 @ SuppressWarnings ("unchecked" )
@@ -114,6 +110,32 @@ public void dispatchAll() {
114110 getDataLoaders ().forEach (DataLoader ::dispatch );
115111 }
116112
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+
117139 /**
118140 * @return a combined set of statistics for all data loaders in this registry presented
119141 * as the sum of all their statistics
0 commit comments