|
12 | 12 | import org.dataloader.fixtures.UserManager;
|
13 | 13 | import org.dataloader.registries.DispatchPredicate;
|
14 | 14 | import org.dataloader.registries.ScheduledDataLoaderRegistry;
|
| 15 | +import org.dataloader.scheduler.BatchLoaderScheduler; |
15 | 16 | import org.dataloader.stats.Statistics;
|
16 | 17 | import org.dataloader.stats.ThreadLocalStatisticsCollector;
|
17 | 18 |
|
|
23 | 24 | import java.util.Set;
|
24 | 25 | import java.util.concurrent.CompletableFuture;
|
25 | 26 | import java.util.concurrent.CompletionStage;
|
| 27 | +import java.util.function.Function; |
26 | 28 | import java.util.stream.Collectors;
|
27 | 29 |
|
28 | 30 | import static java.lang.String.format;
|
@@ -278,6 +280,30 @@ private void statsConfigExample() {
|
278 | 280 | DataLoader<String, User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader, options);
|
279 | 281 | }
|
280 | 282 |
|
| 283 | + private void snooze(int i) { |
| 284 | + } |
| 285 | + |
| 286 | + private void BatchLoaderSchedulerExample() { |
| 287 | + new BatchLoaderScheduler() { |
| 288 | + |
| 289 | + @Override |
| 290 | + public <K, V> CompletionStage<List<V>> scheduleBatchLoader(ScheduledBatchLoaderCall<V> scheduledCall, List<K> keys, BatchLoaderEnvironment environment) { |
| 291 | + return CompletableFuture.supplyAsync(() -> { |
| 292 | + snooze(10); |
| 293 | + return scheduledCall.invoke(); |
| 294 | + }).thenCompose(Function.identity()); |
| 295 | + } |
| 296 | + |
| 297 | + @Override |
| 298 | + public <K, V> CompletionStage<Map<K, V>> scheduleMappedBatchLoader(ScheduledMappedBatchLoaderCall<K, V> scheduledCall, List<K> keys, BatchLoaderEnvironment environment) { |
| 299 | + return CompletableFuture.supplyAsync(() -> { |
| 300 | + snooze(10); |
| 301 | + return scheduledCall.invoke(); |
| 302 | + }).thenCompose(Function.identity()); |
| 303 | + } |
| 304 | + }; |
| 305 | + } |
| 306 | + |
281 | 307 | private void ScheduledDispatche() {
|
282 | 308 | DispatchPredicate depthOrTimePredicate = DispatchPredicate.dispatchIfDepthGreaterThan(10)
|
283 | 309 | .or(DispatchPredicate.dispatchIfLongerThan(Duration.ofMillis(200)));
|
|
0 commit comments