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
ThisDataLoaderRegistry
will use aDispatchPredicate
whendispatchAll()
is called to test (for eachDataLoader
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 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 class
ScheduledDataLoaderRegistry.Builder
-
Field Summary
Fields Modifier and Type Field Description private boolean
closed
private DispatchPredicate
dispatchPredicate
private java.time.Duration
schedule
private java.util.concurrent.ScheduledExecutorService
scheduledExecutorService
-
Fields inherited from class org.dataloader.DataLoaderRegistry
dataLoaders
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ScheduledDataLoaderRegistry(ScheduledDataLoaderRegistry.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Once closed this registry will never again reschedule checksvoid
dispatchAll()
This will calledDataLoader.dispatch()
on each of the registeredDataLoader
svoid
dispatchAllImmediately()
This will immediately dispatch theDataLoader
s in the registry without testing the predicateint
dispatchAllWithCount()
Similar toDataLoaderRegistry.dispatchAll()
, this callsDataLoader.dispatch()
on each of the registeredDataLoader
s, but returns the number of dispatches.int
dispatchAllWithCountImmediately()
This will immediately dispatch theDataLoader
s in the registry without testing the predicateprivate void
dispatchOrReschedule(java.lang.String key, DataLoader<?,?> dataLoader)
java.time.Duration
getScheduleDuration()
static ScheduledDataLoaderRegistry.Builder
newScheduledRegistry()
By default this will create use aExecutors.newSingleThreadScheduledExecutor()
and a schedule duration of 10 milli seconds.private void
reschedule(java.lang.String key, DataLoader<?,?> dataLoader)
void
rescheduleNow()
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:
close
in interfacejava.lang.AutoCloseable
-
getScheduleDuration
public java.time.Duration getScheduleDuration()
- Returns:
- how long the
ScheduledExecutorService
task will wait before checking the predicate again
-
dispatchAll
public void dispatchAll()
Description copied from class:DataLoaderRegistry
This will calledDataLoader.dispatch()
on each of the registeredDataLoader
s- Overrides:
dispatchAll
in classDataLoaderRegistry
-
dispatchAllWithCount
public int dispatchAllWithCount()
Description copied from class:DataLoaderRegistry
Similar toDataLoaderRegistry.dispatchAll()
, this callsDataLoader.dispatch()
on each of the registeredDataLoader
s, but returns the number of dispatches.- Overrides:
dispatchAllWithCount
in classDataLoaderRegistry
- Returns:
- total number of entries that were dispatched from registered
DataLoader
s.
-
dispatchAllImmediately
public void dispatchAllImmediately()
This will immediately dispatch theDataLoader
s in the registry without testing the predicate
-
dispatchAllWithCountImmediately
public int dispatchAllWithCountImmediately()
This will immediately dispatch theDataLoader
s in the registry without testing the predicate- Returns:
- total number of entries that were dispatched from registered
DataLoader
s.
-
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
ScheduledDataLoaderRegistry
s
-
-