Package org.dataloader.registries
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 boolean
private final DispatchPredicate
private final Duration
private final ScheduledExecutorService
Fields inherited from class org.dataloader.DataLoaderRegistry
dataLoaders
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Once closed this registry will never again reschedule checksvoid
This will calledDataLoader.dispatch()
on each of the registeredDataLoader
svoid
This will immediately dispatch theDataLoader
s in the registry without testing the predicateint
Similar toDataLoaderRegistry.dispatchAll()
, this callsDataLoader.dispatch()
on each of the registeredDataLoader
s, but returns the number of dispatches.int
This will immediately dispatch theDataLoader
s in the registry without testing the predicateprivate void
dispatchOrReschedule
(String key, DataLoader<?, ?> dataLoader) By default this will create use aExecutors.newSingleThreadScheduledExecutor()
and a schedule duration of 10 milli seconds.private void
reschedule
(String key, DataLoader<?, ?> dataLoader) void
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 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:
close
in interfaceAutoCloseable
-
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
-
dispatchOrReschedule
-
newScheduledRegistry
By default this will create use aExecutors.newSingleThreadScheduledExecutor()
and a schedule duration of 10 milli seconds.- Returns:
- A builder of
ScheduledDataLoaderRegistry
s
-