Skip to content

Commit 69528f1

Browse files
committed
Adds a predicate to ScheduledDataLoaderRegistry - removed generic builders
1 parent 1c8d48c commit 69528f1

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

src/main/java/org/dataloader/DataLoaderRegistry.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class DataLoaderRegistry {
2525
public DataLoaderRegistry() {
2626
}
2727

28-
protected DataLoaderRegistry(Builder<?> builder) {
28+
private DataLoaderRegistry(Builder builder) {
2929
this.dataLoaders.putAll(builder.dataLoaders);
3030
}
3131

@@ -179,15 +179,10 @@ public static Builder newRegistry() {
179179
return new Builder();
180180
}
181181

182-
public static class Builder<B extends Builder<B>> {
182+
public static class Builder {
183183

184184
private final Map<String, DataLoader<?, ?>> dataLoaders = new HashMap<>();
185185

186-
protected B self() {
187-
//noinspection unchecked
188-
return (B) this;
189-
}
190-
191186
/**
192187
* This will register a new dataloader
193188
*
@@ -196,9 +191,9 @@ protected B self() {
196191
*
197192
* @return this builder for a fluent pattern
198193
*/
199-
public B register(String key, DataLoader<?, ?> dataLoader) {
194+
public Builder register(String key, DataLoader<?, ?> dataLoader) {
200195
dataLoaders.put(key, dataLoader);
201-
return self();
196+
return this;
202197
}
203198

204199
/**
@@ -209,9 +204,9 @@ public B register(String key, DataLoader<?, ?> dataLoader) {
209204
*
210205
* @return this builder for a fluent pattern
211206
*/
212-
public B registerAll(DataLoaderRegistry otherRegistry) {
207+
public Builder registerAll(DataLoaderRegistry otherRegistry) {
213208
dataLoaders.putAll(otherRegistry.dataLoaders);
214-
return self();
209+
return this;
215210
}
216211

217212
/**

src/main/java/org/dataloader/registries/ScheduledDataLoaderRegistry.java

+25-12
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)