@@ -37,7 +37,8 @@ public class ScheduledDataLoaderRegistry extends DataLoaderRegistry implements A
3737 private volatile boolean closed ;
3838
3939 private ScheduledDataLoaderRegistry (Builder builder ) {
40- super (builder );
40+ super ();
41+ this .dataLoaders .putAll (builder .dataLoaders );
4142 this .scheduledExecutorService = builder .scheduledExecutorService ;
4243 this .schedule = builder .schedule ;
4344 this .closed = false ;
@@ -215,23 +216,35 @@ public static Builder newScheduledRegistry() {
215216 return new Builder ();
216217 }
217218
218- public static class Builder extends DataLoaderRegistry . Builder < ScheduledDataLoaderRegistry . Builder > {
219+ public static class Builder {
219220
221+ private final Map <String , DataLoader <?, ?>> dataLoaders = new LinkedHashMap <>();
222+ private final Map <DataLoader <?, ?>, DispatchPredicate > dataLoaderPredicates = new LinkedHashMap <>();
223+ private DispatchPredicate dispatchPredicate = DispatchPredicate .DISPATCH_ALWAYS ;
220224 private ScheduledExecutorService scheduledExecutorService = Executors .newSingleThreadScheduledExecutor ();
221225 private Duration schedule = Duration .ofMillis (10 );
222226
223- private final Map <DataLoader <?, ?>, DispatchPredicate > dataLoaderPredicates = new ConcurrentHashMap <>();
224-
225- private DispatchPredicate dispatchPredicate = DispatchPredicate .DISPATCH_ALWAYS ;
226-
227227 public Builder scheduledExecutorService (ScheduledExecutorService executorService ) {
228228 this .scheduledExecutorService = nonNull (executorService );
229- return self () ;
229+ return this ;
230230 }
231231
232232 public Builder schedule (Duration schedule ) {
233233 this .schedule = schedule ;
234- return self ();
234+ return this ;
235+ }
236+
237+ /**
238+ * This will register a new dataloader
239+ *
240+ * @param key the key to put the data loader under
241+ * @param dataLoader the data loader to register
242+ *
243+ * @return this builder for a fluent pattern
244+ */
245+ public Builder register (String key , DataLoader <?, ?> dataLoader ) {
246+ dataLoaders .put (key , dataLoader );
247+ return this ;
235248 }
236249
237250
@@ -247,7 +260,7 @@ public Builder schedule(Duration schedule) {
247260 public Builder register (String key , DataLoader <?, ?> dataLoader , DispatchPredicate dispatchPredicate ) {
248261 register (key , dataLoader );
249262 dataLoaderPredicates .put (dataLoader , dispatchPredicate );
250- return self () ;
263+ return this ;
251264 }
252265
253266 /**
@@ -259,12 +272,12 @@ public Builder register(String key, DataLoader<?, ?> dataLoader, DispatchPredica
259272 * @return this builder for a fluent pattern
260273 */
261274 public Builder registerAll (DataLoaderRegistry otherRegistry ) {
262- super . registerAll (otherRegistry );
275+ dataLoaders . putAll (otherRegistry . getDataLoadersMap () );
263276 if (otherRegistry instanceof ScheduledDataLoaderRegistry ) {
264277 ScheduledDataLoaderRegistry other = (ScheduledDataLoaderRegistry ) otherRegistry ;
265278 dataLoaderPredicates .putAll (other .dataLoaderPredicates );
266279 }
267- return self () ;
280+ return this ;
268281 }
269282
270283 /**
@@ -277,7 +290,7 @@ public Builder registerAll(DataLoaderRegistry otherRegistry) {
277290 */
278291 public Builder dispatchPredicate (DispatchPredicate dispatchPredicate ) {
279292 this .dispatchPredicate = dispatchPredicate ;
280- return self () ;
293+ return this ;
281294 }
282295
283296 /**
0 commit comments