Package org.dataloader.registries
Class ScheduledDataLoaderRegistry
- java.lang.Object
-
- org.dataloader.DataLoaderRegistry
-
- org.dataloader.registries.ScheduledDataLoaderRegistry
-
- All Implemented Interfaces:
java.lang.AutoCloseable
@ExperimentalApi public class ScheduledDataLoaderRegistry extends DataLoaderRegistry implements java.lang.AutoCloseable
ThisDataLoaderRegistrywill use aDispatchPredicatewhendispatchAll()is called to test (for eachDataLoaderin the registry) if a dispatch should proceed. If the predicate returns false, then a task is scheduled to perform that predicate dispatch again via theScheduledExecutorService.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.
If you wanted to create a ScheduledDataLoaderRegistry that started a rescheduling immediately, just create one and call
rescheduleNow().This code is currently marked as
ExperimentalApi
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classScheduledDataLoaderRegistry.Builder
-
Field Summary
Fields Modifier and Type Field Description private booleanclosedprivate DispatchPredicatedispatchPredicateprivate java.time.Durationscheduleprivate java.util.concurrent.ScheduledExecutorServicescheduledExecutorService-
Fields inherited from class org.dataloader.DataLoaderRegistry
dataLoaders
-
-
Constructor Summary
Constructors Modifier Constructor Description privateScheduledDataLoaderRegistry(ScheduledDataLoaderRegistry.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Once closed this registry will never again reschedule checksvoiddispatchAll()This will calledDataLoader.dispatch()on each of the registeredDataLoadersvoiddispatchAllImmediately()This will immediately dispatch theDataLoaders in the registry without testing the predicateintdispatchAllWithCount()Similar toDataLoaderRegistry.dispatchAll(), this callsDataLoader.dispatch()on each of the registeredDataLoaders, but returns the number of dispatches.intdispatchAllWithCountImmediately()This will immediately dispatch theDataLoaders in the registry without testing the predicateprivate voiddispatchOrReschedule(java.lang.String key, DataLoader<?,?> dataLoader)java.time.DurationgetScheduleDuration()static ScheduledDataLoaderRegistry.BuildernewScheduledRegistry()By default this will create use aExecutors.newSingleThreadScheduledExecutor()and a schedule duration of 10 milli seconds.private voidreschedule(java.lang.String key, DataLoader<?,?> dataLoader)voidrescheduleNow()This will schedule a task to check the predicate and dispatch if true right now.-
Methods inherited from class org.dataloader.DataLoaderRegistry
combine, computeIfAbsent, dispatchDepth, getDataLoader, getDataLoaders, getDataLoadersMap, getKeys, getStatistics, newRegistry, register, unregister
-
-
-
-
Field Detail
-
scheduledExecutorService
private final java.util.concurrent.ScheduledExecutorService scheduledExecutorService
-
dispatchPredicate
private final DispatchPredicate dispatchPredicate
-
schedule
private final java.time.Duration schedule
-
closed
private volatile boolean closed
-
-
Constructor Detail
-
ScheduledDataLoaderRegistry
private ScheduledDataLoaderRegistry(ScheduledDataLoaderRegistry.Builder builder)
-
-
Method Detail
-
close
public void close()
Once closed this registry will never again reschedule checks- Specified by:
closein interfacejava.lang.AutoCloseable
-
getScheduleDuration
public java.time.Duration getScheduleDuration()
- Returns:
- how long the
ScheduledExecutorServicetask will wait before checking the predicate again
-
dispatchAll
public void dispatchAll()
Description copied from class:DataLoaderRegistryThis will calledDataLoader.dispatch()on each of the registeredDataLoaders- Overrides:
dispatchAllin classDataLoaderRegistry
-
dispatchAllWithCount
public int dispatchAllWithCount()
Description copied from class:DataLoaderRegistrySimilar toDataLoaderRegistry.dispatchAll(), this callsDataLoader.dispatch()on each of the registeredDataLoaders, but returns the number of dispatches.- Overrides:
dispatchAllWithCountin classDataLoaderRegistry- Returns:
- total number of entries that were dispatched from registered
DataLoaders.
-
dispatchAllImmediately
public void dispatchAllImmediately()
This will immediately dispatch theDataLoaders in the registry without testing the predicate
-
dispatchAllWithCountImmediately
public int dispatchAllWithCountImmediately()
This will immediately dispatch theDataLoaders in the registry without testing the predicate- Returns:
- total number of entries that were dispatched from registered
DataLoaders.
-
rescheduleNow
public void rescheduleNow()
This will schedule a task to check the predicate and dispatch if true right now. It will not do a pre check of the preodicate likedispatchAll()would
-
reschedule
private void reschedule(java.lang.String key, DataLoader<?,?> dataLoader)
-
dispatchOrReschedule
private void dispatchOrReschedule(java.lang.String key, DataLoader<?,?> dataLoader)
-
newScheduledRegistry
public static ScheduledDataLoaderRegistry.Builder newScheduledRegistry()
By default this will create use aExecutors.newSingleThreadScheduledExecutor()and a schedule duration of 10 milli seconds.- Returns:
- A builder of
ScheduledDataLoaderRegistrys
-
-