Class ScheduledDataLoaderRegistry
java.lang.Object
org.dataloader.DataLoaderRegistry
org.dataloader.registries.ScheduledDataLoaderRegistry
- All Implemented Interfaces:
AutoCloseable
@ExperimentalApi
public class ScheduledDataLoaderRegistry
extends DataLoaderRegistry
implements AutoCloseable
This
DataLoaderRegistry will use a DispatchPredicate 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.
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final DispatchPredicateprivate final Durationprivate final ScheduledExecutorServiceFields inherited from class DataLoaderRegistry
dataLoaders -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Once closed this registry will never again reschedule checksvoidThis will calledDataLoader.dispatch()on each of the registeredDataLoadersvoidThis will immediately dispatch theDataLoaders in the registry without testing the predicateintSimilar toDataLoaderRegistry.dispatchAll(), this callsDataLoader.dispatch()on each of the registeredDataLoaders, but returns the number of dispatches.intThis will immediately dispatch theDataLoaders in the registry without testing the predicateprivate voiddispatchOrReschedule(String key, DataLoader<?, ?> dataLoader) By default this will create use aExecutors.newSingleThreadScheduledExecutor()and a schedule duration of 10 milli seconds.private voidreschedule(String key, DataLoader<?, ?> dataLoader) voidThis will schedule a task to check the predicate and dispatch if true right now.Methods inherited from class DataLoaderRegistry
combine, computeIfAbsent, dispatchDepth, getDataLoader, getDataLoaders, getDataLoadersMap, getKeys, getStatistics, newRegistry, register, unregister
-
Field Details
-
scheduledExecutorService
-
dispatchPredicate
-
schedule
-
closed
private volatile boolean closed
-
-
Constructor Details
-
ScheduledDataLoaderRegistry
-
-
Method Details
-
close
public void close()Once closed this registry will never again reschedule checks- Specified by:
closein interfaceAutoCloseable
-
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
-
dispatchOrReschedule
-
newScheduledRegistry
By default this will create use aExecutors.newSingleThreadScheduledExecutor()and a schedule duration of 10 milli seconds.- Returns:
- A builder of
ScheduledDataLoaderRegistrys
-