Class DataLoaderRegistry
- Direct Known Subclasses:
ScheduledDataLoaderRegistry
Notes on DataLoaderInstrumentation
: A DataLoaderRegistry
can have an instrumentation
associated with it. As each DataLoader
is added to the registry, the DataLoaderInstrumentation
of the registry is applied to that DataLoader
.
The DataLoader
is changed and hence the object in the registry is not the
same one as was originally registered. So you MUST get access to the DataLoader
via getDataLoader(String)
methods
and not use the original DataLoader
object.
If the DataLoader
has no DataLoaderInstrumentation
then the registry one is added to it. If it does have one already
then a ChainedDataLoaderInstrumentation
is created with the registry DataLoaderInstrumentation
in it first and then any other
DataLoaderInstrumentation
s added after that. If the registry DataLoaderInstrumentation
instance and DataLoader
DataLoaderInstrumentation
instance
are the same object, then nothing is changed, since the same instrumentation code is being run.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String,
DataLoader<?, ?>> protected final @Nullable DataLoaderInstrumentation
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DataLoaderRegistry
(Map<String, DataLoader<?, ?>> dataLoaders, @Nullable DataLoaderInstrumentation instrumentation) -
Method Summary
Modifier and TypeMethodDescriptioncombine
(DataLoaderRegistry registry) This will combine all the current data loaders in this registry and all the data loaders from the specified registry and return a new combined registry<K,
V> DataLoader<K, V> computeIfAbsent
(String key, Function<String, DataLoader<?, ?>> mappingFunction) Computes a data loader if absent or return it if it was already registered at that key.void
This will be calledDataLoader.dispatch()
on each of the registeredDataLoader
sint
Similar todispatchAll()
, this callsDataLoader.dispatch()
on each of the registeredDataLoader
s, but returns the number of dispatches.int
<K,
V> @Nullable DataLoader<K, V> getDataLoader
(String key) Returns the dataloader that was registered under the specified keyList<DataLoader<?,
?>> Map<String,
DataLoader<?, ?>> @Nullable DataLoaderInstrumentation
getKeys()
static DataLoaderRegistry.Builder
register
(String key, DataLoader<?, ?> dataLoader) This will register a newDataLoader
register
(DataLoader<?, ?> dataLoader) This will register a new named dataloader.<K,
V> DataLoader<K, V> registerAndGet
(String key, DataLoader<?, ?> dataLoader) This will register a newDataLoader
and then return it.unregister
(String key) This will unregister a new dataloader
-
Field Details
-
dataLoaders
-
instrumentation
-
-
Constructor Details
-
DataLoaderRegistry
public DataLoaderRegistry() -
DataLoaderRegistry
protected DataLoaderRegistry(Map<String, DataLoader<?, ?>> dataLoaders, @Nullable DataLoaderInstrumentation instrumentation)
-
-
Method Details
-
getInstrumentation
- Returns:
- the
DataLoaderInstrumentation
associated with this registry which can be null
-
register
This will register a new named dataloader. TheDataLoader
must be named something and cannot have a null name.Note: Registration can change the data loader instance since it might get an
DataLoaderInstrumentation
applied to it. So theDataLoader
instance your read viagetDataLoader(String)
might not be the same object that was registered.- Parameters:
dataLoader
- the named data loader to register- Returns:
- this registry
-
register
This will register a newDataLoader
Note: Registration can change the data loader instance since it might get an
DataLoaderInstrumentation
applied to it. So theDataLoader
instance your read viagetDataLoader(String)
might not be the same object that was registered.- Parameters:
key
- the key to put the data loader underdataLoader
- the data loader to register- Returns:
- this registry
-
registerAndGet
This will register a newDataLoader
and then return it.Note: Registration can change the data loader instance since it might get an
DataLoaderInstrumentation
applied to it. So theDataLoader
instance your read viagetDataLoader(String)
might not be the same object that was registered.- Parameters:
key
- the key to put the data loader underdataLoader
- the data loader to register- Returns:
- the data loader instance that was registered
-
computeIfAbsent
public <K,V> DataLoader<K,V> computeIfAbsent(String key, Function<String, DataLoader<?, ?>> mappingFunction) Computes a data loader if absent or return it if it was already registered at that key.Note: The entire method invocation is performed atomically, so the function is applied at most once per key.
Note: Registration can change the data loader instance since it might get an
DataLoaderInstrumentation
applied to it. So theDataLoader
instance your read viagetDataLoader(String)
might not be the same object that was registered.- Type Parameters:
K
- the type of keysV
- the type of values- Parameters:
key
- the key of the data loadermappingFunction
- the function to compute a data loader- Returns:
- a data loader
-
combine
This will combine all the current data loaders in this registry and all the data loaders from the specified registry and return a new combined registry- Parameters:
registry
- the registry to combine into this registry- Returns:
- a new combined registry
-
getDataLoaders
- Returns:
- the currently registered data loaders
-
getDataLoadersMap
- Returns:
- the currently registered data loaders as a map
-
unregister
This will unregister a new dataloader- Parameters:
key
- the key of the data loader to unregister- Returns:
- this registry
-
getDataLoader
Returns the dataloader that was registered under the specified key- Type Parameters:
K
- the type of keysV
- the type of values- Parameters:
key
- the key of the data loader- Returns:
- a data loader or null if it's not present
-
getKeys
- Returns:
- the keys of the data loaders in this registry
-
dispatchAll
public void dispatchAll()This will be calledDataLoader.dispatch()
on each of the registeredDataLoader
s -
dispatchAllWithCount
public int dispatchAllWithCount()Similar todispatchAll()
, this callsDataLoader.dispatch()
on each of the registeredDataLoader
s, but returns the number of dispatches.- Returns:
- total number of entries that were dispatched from registered
DataLoader
s.
-
dispatchDepth
public int dispatchDepth()- Returns:
- The sum of all batched key loads that need to be dispatched from all registered
DataLoader
s
-
getStatistics
- Returns:
- a combined set of statistics for all data loaders in this registry presented as the sum of all their statistics
-
newRegistry
- Returns:
- A builder of
DataLoaderRegistry
s
-