@@ -37,7 +37,8 @@ public class ScheduledDataLoaderRegistry extends DataLoaderRegistry implements A
37
37
private volatile boolean closed ;
38
38
39
39
private ScheduledDataLoaderRegistry (Builder builder ) {
40
- super (builder );
40
+ super ();
41
+ this .dataLoaders .putAll (builder .dataLoaders );
41
42
this .scheduledExecutorService = builder .scheduledExecutorService ;
42
43
this .schedule = builder .schedule ;
43
44
this .closed = false ;
@@ -215,23 +216,35 @@ public static Builder newScheduledRegistry() {
215
216
return new Builder ();
216
217
}
217
218
218
- public static class Builder extends DataLoaderRegistry . Builder < ScheduledDataLoaderRegistry . Builder > {
219
+ public static class Builder {
219
220
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 ;
220
224
private ScheduledExecutorService scheduledExecutorService = Executors .newSingleThreadScheduledExecutor ();
221
225
private Duration schedule = Duration .ofMillis (10 );
222
226
223
- private final Map <DataLoader <?, ?>, DispatchPredicate > dataLoaderPredicates = new ConcurrentHashMap <>();
224
-
225
- private DispatchPredicate dispatchPredicate = DispatchPredicate .DISPATCH_ALWAYS ;
226
-
227
227
public Builder scheduledExecutorService (ScheduledExecutorService executorService ) {
228
228
this .scheduledExecutorService = nonNull (executorService );
229
- return self () ;
229
+ return this ;
230
230
}
231
231
232
232
public Builder schedule (Duration schedule ) {
233
233
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 ;
235
248
}
236
249
237
250
@@ -247,7 +260,7 @@ public Builder schedule(Duration schedule) {
247
260
public Builder register (String key , DataLoader <?, ?> dataLoader , DispatchPredicate dispatchPredicate ) {
248
261
register (key , dataLoader );
249
262
dataLoaderPredicates .put (dataLoader , dispatchPredicate );
250
- return self () ;
263
+ return this ;
251
264
}
252
265
253
266
/**
@@ -259,12 +272,12 @@ public Builder register(String key, DataLoader<?, ?> dataLoader, DispatchPredica
259
272
* @return this builder for a fluent pattern
260
273
*/
261
274
public Builder registerAll (DataLoaderRegistry otherRegistry ) {
262
- super . registerAll (otherRegistry );
275
+ dataLoaders . putAll (otherRegistry . getDataLoadersMap () );
263
276
if (otherRegistry instanceof ScheduledDataLoaderRegistry ) {
264
277
ScheduledDataLoaderRegistry other = (ScheduledDataLoaderRegistry ) otherRegistry ;
265
278
dataLoaderPredicates .putAll (other .dataLoaderPredicates );
266
279
}
267
- return self () ;
280
+ return this ;
268
281
}
269
282
270
283
/**
@@ -277,7 +290,7 @@ public Builder registerAll(DataLoaderRegistry otherRegistry) {
277
290
*/
278
291
public Builder dispatchPredicate (DispatchPredicate dispatchPredicate ) {
279
292
this .dispatchPredicate = dispatchPredicate ;
280
- return self () ;
293
+ return this ;
281
294
}
282
295
283
296
/**
0 commit comments