org.apache.tamaya.clsupport

## Class AbstractClassloaderAwareItemLoader<T>

- java.lang.Object
- - org.apache.tamaya.clsupport.AbstractClassloaderAwareItemLoader<T>

- Type Parameters:
    `T` - the managed item type.
  Direct Known Subclasses:
    CLAwareServiceContext

      public abstract class AbstractClassloaderAwareItemLoader<T>
      extends Object

  This class implements an abstract base class, which basically provides a loading mechanism that supports loading and managing resources along the classloader hierarchies individually. It ensures resources are loaded and stored related to the each target classloader within the hierarchy individually. Additionally it enables mechanisms to ensure an item T is not loaded multiple times, when traversing up the classloader hierarchy.

  Finally classloaders are not stored by reference by this class, to ensure they still can be garbage collected. Instead this class uses the fully qualified class name of the loader and the corresponsing hashCode as returned by `Objects.hashCode(Object)`.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractClassloaderAwareItemLoader()` Creates a new instance, using the current Thread context classloader, or - if null - the classloader that loaded this class for initially initializing the loader instance.
    `AbstractClassloaderAwareItemLoader(ClassLoader classLoader)` Creates a new instance, using the class loader given for initializing the resources loaded.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract T` | `createItem(ClassLoader classLoader)` Creates a new item for being stored linked with the given lassloader.
    `static String` | `getClassLoaderID()` Evaluates a String key for identfying a classloader instance, based on the loader class and its hashCode.
    `static String` | `getClassLoaderID(ClassLoader classLoader)` Evaluates a String key for identfying a classloader instance, based on the loader class and its hashCode.
    `static ClassLoader` | `getDefaultClassLoader()` Utility method that either returns the current thread context classloader or - if not available - the classloader that loaded this class.
    `T` | `getItemNoParent()` Return the item assigned to the current thread context class loader or - if null - the class that loaded this class.
    `T` | `getItemNoParent(boolean loadIfMissing)` Return the item assigned to the current thread context class loader or - if null - the class that loaded this class.
    `T` | `getItemNoParent(ClassLoader classLoader, boolean loadIfMissing)` Return the item assigned to the current thread context class loader or - if null - the class that loaded this class.
    `Set<T>` | `getItems()` Get all items valid for the current thread context class loader, or - if null - the classloader that loaded this class.
    `Set<T>` | `getItems(ClassLoader classLoader)` Get all items found for the given classloader and all its parent classloaders.
    `Set<T>` | `getParentItems()` Get all items valid for the parent class loader of the current thread context class loader, or - if null - the parent of the classloader that loaded this class.
    `Set<T>` | `getParentItems(ClassLoader classLoader)` Get all items found for the parent of the given classloader and all its parent classloaders.
    `void` | `loadItems(ClassLoader classLoader)` Loads the items for the given classloader and all its parent classloaders.
    `void` | `loadItems(ClassLoader classLoader, boolean update)` Loads the items for the given classloader and all its parent classloaders.
    `protected abstract void` | `updateItem(T currentItemSet, ClassLoader classLoader)` Creates a new item for being stored linked with the given lassloader.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AbstractClassloaderAwareItemLoader

          public AbstractClassloaderAwareItemLoader()

      Creates a new instance, using the current Thread context classloader, or - if null - the classloader that loaded this class for initially initializing the loader instance.

    - #### AbstractClassloaderAwareItemLoader

          public AbstractClassloaderAwareItemLoader(ClassLoader classLoader)

      Creates a new instance, using the class loader given for initializing the resources loaded.
      Parameters:
        `classLoader` - the target top level classloader, not null.

  - ### Method Detail

    - #### loadItems

          public void loadItems(ClassLoader classLoader)

      Loads the items for the given classloader and all its parent classloaders. This method will not update the items already found for any class loader involved.
      Parameters:
        `classLoader` - the target top level classloader, not null.

    - #### loadItems

          public void loadItems(ClassLoader classLoader,
                       boolean update)

      Loads the items for the given classloader and all its parent classloaders.
      Parameters:
        `classLoader` - the target top level classloader, not null.
        `update` - if set to true, resources not visible on former runs are added during this load.

    - #### createItem

          protected abstract T createItem(ClassLoader classLoader)

      Creates a new item for being stored linked with the given lassloader.
      Parameters:
        `classLoader` - the classloader, not null.
      Returns:
        the new item loaded.

    - #### updateItem

          protected abstract void updateItem(T currentItemSet,
                        ClassLoader classLoader)

      Creates a new item for being stored linked with the given lassloader.
      Parameters:
        `currentItemSet` - the current found ItemContainer instance to be updated.
        `classLoader` - the classloader, not null.

    - #### getClassLoaderID

          public static String getClassLoaderID(ClassLoader classLoader)

      Evaluates a String key for identfying a classloader instance, based on the loader class and its hashCode. This prevents the storage of classloader references as keys and therefore enables classloaders not used anymore to be garbage collected.
      Parameters:
        `classLoader` - `ClassLoader` to be identified, must not be `null`.
      Returns:
        the unique key for the given classloader

    - #### getClassLoaderID

          public static String getClassLoaderID()

      Evaluates a String key for identfying a classloader instance, based on the loader class and its hashCode. This prevents the storage of classloader references as keys and therefore enables classloaders not used anymore to be garbage collected.
      Returns:
        the unique key for the current default classloader as returned by #getDefaultClassLoader.

    - #### getItems

          public Set<T> getItems()

      Get all items valid for the current thread context class loader, or - if null - the classloader that loaded this class.
      Returns:
        the items found, never null.

    - #### getItems

          public Set<T> getItems(ClassLoader classLoader)

      Get all items found for the given classloader and all its parent classloaders.
      Parameters:
        `classLoader` - the target top level classloader, not null.
      Returns:
        the items found, never null.

    - #### getParentItems

          public Set<T> getParentItems()

      Get all items valid for the parent class loader of the current thread context class loader, or - if null - the parent of the classloader that loaded this class. This allows to build a delta list of instances only visible on the target classloader given.
      Returns:
        the items found, never null.

    - #### getParentItems

          public Set<T> getParentItems(ClassLoader classLoader)

      Get all items found for the parent of the given classloader and all its parent classloaders. This allows to build a delta list of instances only visible on the target classloader given.
      Parameters:
        `classLoader` - the target top level classloader, not null.
      Returns:
        the items found, never null.

    - #### getItemNoParent

          public T getItemNoParent()

      Return the item assigned to the current thread context class loader or - if null - the class that loaded this class. If not yet loaded this method will NOT trigger a load.
      Returns:
        the item attached, or null.

    - #### getItemNoParent

          public T getItemNoParent(boolean loadIfMissing)

      Return the item assigned to the current thread context class loader or - if null - the class that loaded this class.
      Parameters:
        `loadIfMissing` - Flag that allows to define if this method will trigger an item load, when no item is loaded for the current class loader.
      Returns:
        the item attached, or null.

    - #### getItemNoParent

          public T getItemNoParent(ClassLoader classLoader,
                          boolean loadIfMissing)

      Return the item assigned to the current thread context class loader or - if null - the class that loaded this class.
      Parameters:
        `classLoader` - the target top level classloader, not null.
        `loadIfMissing` - Flag that allows to define if this method will trigger an item load, when no item is loaded for the current class loader.
      Returns:
        the item attached, or null. If `loadIfMissing` is set to true, the result is normally not to be expected to be null.

    - #### getDefaultClassLoader

          public static ClassLoader getDefaultClassLoader()

      Utility method that either returns the current thread context classloader or - if not available - the classloader that loaded this class.
      Returns:
        the default classloader to be used, if no explicit classloader has been passed.

Copyright © 2014–2016 Apache Software Foundation. All rights reserved.