T
- the managed item type.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 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.
|
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.
|
public AbstractClassloaderAwareItemLoader()
public AbstractClassloaderAwareItemLoader(ClassLoader classLoader)
classLoader
- the target top level classloader, not null.public void loadItems(ClassLoader classLoader)
classLoader
- the target top level classloader, not null.public void loadItems(ClassLoader classLoader, boolean update)
classLoader
- the target top level classloader, not null.update
- if set to true, resources not visible on former runs are added during this load.protected abstract T createItem(ClassLoader classLoader)
classLoader
- the classloader, not null.protected abstract void updateItem(T currentItemSet, ClassLoader classLoader)
currentItemSet
- the current found ItemContainer instance to be updated.classLoader
- the classloader, not null.public static String getClassLoaderID(ClassLoader classLoader)
classLoader
- ClassLoader
to be identified, must not be null
.public static String getClassLoaderID()
public Set<T> getItems()
public Set<T> getItems(ClassLoader classLoader)
classLoader
- the target top level classloader, not null.public Set<T> getParentItems()
public Set<T> getParentItems(ClassLoader classLoader)
classLoader
- the target top level classloader, not null.public T getItemNoParent()
public T getItemNoParent(boolean loadIfMissing)
loadIfMissing
- Flag that allows to define if this method will trigger an item load, when no item is loaded
for the current class loader.public T getItemNoParent(ClassLoader classLoader, boolean loadIfMissing)
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.loadIfMissing
is set to true, the result is normally not to be
expected to be null.public static ClassLoader getDefaultClassLoader()
Copyright © 2014–2016 Apache Software Foundation. All rights reserved.