Class DataLoaderRegistry

    • Field Detail

      • dataLoaders

        protected final java.util.Map<java.lang.String,​DataLoader<?,​?>> dataLoaders
    • Constructor Detail

      • DataLoaderRegistry

        public DataLoaderRegistry()
      • DataLoaderRegistry

        protected DataLoaderRegistry​(java.util.Map<java.lang.String,​DataLoader<?,​?>> dataLoaders,
                                     @Nullable DataLoaderInstrumentation instrumentation)
    • Method Detail

      • register

        public DataLoaderRegistry register​(DataLoader<?,​?> dataLoader)
        This will register a new named dataloader. The DataLoader 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 the DataLoader instance your read via getDataLoader(String) might not be the same object that was registered.

        Parameters:
        dataLoader - the named data loader to register
        Returns:
        this registry
      • register

        public DataLoaderRegistry register​(java.lang.String key,
                                           DataLoader<?,​?> dataLoader)
        This will register a new DataLoader

        Note: Registration can change the data loader instance since it might get an DataLoaderInstrumentation applied to it. So the DataLoader instance your read via getDataLoader(String) might not be the same object that was registered.

        Parameters:
        key - the key to put the data loader under
        dataLoader - the data loader to register
        Returns:
        this registry
      • registerAndGet

        public <K,​V> DataLoader<K,​V> registerAndGet​(java.lang.String key,
                                                                DataLoader<?,​?> dataLoader)
        This will register a new DataLoader and then return it.

        Note: Registration can change the data loader instance since it might get an DataLoaderInstrumentation applied to it. So the DataLoader instance your read via getDataLoader(String) might not be the same object that was registered.

        Parameters:
        key - the key to put the data loader under
        dataLoader - the data loader to register
        Returns:
        the data loader instance that was registered
      • computeIfAbsent

        public <K,​V> DataLoader<K,​V> computeIfAbsent​(java.lang.String key,
                                                                 java.util.function.Function<java.lang.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 the DataLoader instance your read via getDataLoader(String) might not be the same object that was registered.

        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        key - the key of the data loader
        mappingFunction - the function to compute a data loader
        Returns:
        a data loader
      • combine

        public DataLoaderRegistry combine​(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
        Parameters:
        registry - the registry to combine into this registry
        Returns:
        a new combined registry
      • getDataLoaders

        public java.util.List<DataLoader<?,​?>> getDataLoaders()
        Returns:
        the currently registered data loaders
      • getDataLoadersMap

        public java.util.Map<java.lang.String,​DataLoader<?,​?>> getDataLoadersMap()
        Returns:
        the currently registered data loaders as a map
      • unregister

        public DataLoaderRegistry unregister​(java.lang.String key)
        This will unregister a new dataloader
        Parameters:
        key - the key of the data loader to unregister
        Returns:
        this registry
      • getDataLoader

        public <K,​V> DataLoader<K,​V> getDataLoader​(java.lang.String key)
        Returns the dataloader that was registered under the specified key
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        key - the key of the data loader
        Returns:
        a data loader or null if its not present
      • getKeys

        public java.util.Set<java.lang.String> getKeys()
        Returns:
        the keys of the data loaders in this registry
      • dispatchAllWithCount

        public int dispatchAllWithCount()
        Similar to dispatchAll(), this calls DataLoader.dispatch() on each of the registered DataLoaders, but returns the number of dispatches.
        Returns:
        total number of entries that were dispatched from registered DataLoaders.
      • dispatchDepth

        public int dispatchDepth()
        Returns:
        The sum of all batched key loads that need to be dispatched from all registered DataLoaders
      • getStatistics

        public Statistics getStatistics()
        Returns:
        a combined set of statistics for all data loaders in this registry presented as the sum of all their statistics