Class ScheduledDataLoaderRegistry

java.lang.Object
org.dataloader.DataLoaderRegistry
org.dataloader.registries.ScheduledDataLoaderRegistry
All Implemented Interfaces:
AutoCloseable

@ExperimentalApi @NullMarked public class ScheduledDataLoaderRegistry extends DataLoaderRegistry implements AutoCloseable
This DataLoaderRegistry will use DispatchPredicates when dispatchAll() is called to test (for each DataLoader in the registry) if a dispatch should proceed. If the predicate returns false, then a task is scheduled to perform that predicate dispatch again via the ScheduledExecutorService.

It;s possible to have a DispatchPredicate per dataloader as well as a default DispatchPredicate for the whole ScheduledDataLoaderRegistry.

This will continue to loop (test false and reschedule) until such time as the predicate returns true, in which case no rescheduling will occur, and you will need to call dispatch again to restart the process.

In the default mode, when tickerMode is false, the registry will continue to loop (test false and reschedule) until such time as the predicate returns true, in which case no rescheduling will occur, and you will need to call dispatch again to restart the process.

However, when tickerMode is true, the registry will always reschedule continuously after the first ever call to dispatchAll().

This will allow you to chain together DataLoader load calls like this :


   CompletableFuture<String> future = dataLoaderA.load("A")
                                          .thenCompose(value -> dataLoaderB.load(value));
 

However, it may mean your batching will not be as efficient as it might be. In environments like graphql this might mean you are too eager in fetching. The DispatchPredicate still runs to decide if dispatch should happen however in ticker mode it will be continuously rescheduled.

When tickerMode is true, you really SHOULD close the registry say at the end of a request otherwise you will leave a job on the ScheduledExecutorService that is continuously dispatching.

If you wanted to create a ScheduledDataLoaderRegistry that started a rescheduling immediately, just create one and call rescheduleNow().

By default, it uses a Executors.newSingleThreadScheduledExecutor()} to schedule the tasks. However, if you are creating a ScheduledDataLoaderRegistry per request you will want to look at sharing this ScheduledExecutorService to avoid creating a new thread per registry created.

This code is currently marked as ExperimentalApi

  • Method Details