@Priority(value=10) public class CLAwareServiceContext extends AbstractClassloaderAwareItemLoader<org.apache.tamaya.clsupport.ServiceContainer> implements org.apache.tamaya.spi.ServiceContext
This class implements a ServiceContext
, which basically provides a similar loading mechanism as used
by the ServiceLoader
. Whereas the ServiceLoader
only loads configurations
and instances from one classloader, this loader manages configs found and the related instances for each
classloader along the classloader hierarchies individually. It ensures instances are loaded on the classloader
level, where they first are visible. Additionally it ensures the same configuration resource (and its
declared services) are loaded multiple times, when going up the classloader hierarchy.
Finally classloaders are not stored by reference by this class, to ensure they still can be garbage collected. Refer also the inherited parent class for further details.
This class uses an ordinal of 10
, so it overrides any default ServiceContext
implementations
provided with the Tamaya core modules.
Constructor and Description |
---|
CLAwareServiceContext()
Constructor, using the current default classloader as defined by
AbstractClassloaderAwareItemLoader.getDefaultClassLoader() . |
CLAwareServiceContext(ClassLoader classLoader)
Constructor, using the given classloader.
|
Modifier and Type | Method and Description |
---|---|
protected org.apache.tamaya.clsupport.ServiceContainer |
createItem(ClassLoader classLoader)
Implementation that creates a
ServiceContainer , which manages all configs and instances loaded
for a given classloader. |
static int |
getPriority(Object o)
Checks the given instance for a @Priority annotation.
|
<T> T |
getService(Class<T> serviceType)
This method tries to evaluate the current singleton from the
ServiceContainer attached to the
current classloader. |
<T> T |
getService(Class<T> serviceType,
ClassLoader classLoader)
Evaluates the current singleton instance using the given classloader context.
|
<T> List<T> |
getServices(Class<T> serviceType)
Gets the services visible.
|
<T> List<T> |
getServices(Class<T> serviceType,
ClassLoader classLoader)
Gets the services visible.
|
int |
ordinal() |
protected void |
updateItem(org.apache.tamaya.clsupport.ServiceContainer currentContainer,
ClassLoader classLoader)
Creates a new item for being stored linked with the given lassloader.
|
getClassLoaderID, getClassLoaderID, getDefaultClassLoader, getItemNoParent, getItemNoParent, getItemNoParent, getItems, getItems, getParentItems, getParentItems, loadItems, loadItems
public CLAwareServiceContext()
AbstractClassloaderAwareItemLoader.getDefaultClassLoader()
.public CLAwareServiceContext(ClassLoader classLoader)
classLoader
- the target classloader for initializing of services, not null.protected org.apache.tamaya.clsupport.ServiceContainer createItem(ClassLoader classLoader)
ServiceContainer
, which manages all configs and instances loaded
for a given classloader.createItem
in class AbstractClassloaderAwareItemLoader<org.apache.tamaya.clsupport.ServiceContainer>
classLoader
- the classloader, not null.ServiceContainer
instance.protected void updateItem(org.apache.tamaya.clsupport.ServiceContainer currentContainer, ClassLoader classLoader)
AbstractClassloaderAwareItemLoader
updateItem
in class AbstractClassloaderAwareItemLoader<org.apache.tamaya.clsupport.ServiceContainer>
currentContainer
- the current found ItemContainer instance to be updated.classLoader
- the classloader, not null.public int ordinal()
ordinal
in interface org.apache.tamaya.spi.ServiceContext
public <T> T getService(Class<T> serviceType)
ServiceContainer
attached to the
current classloader. If not found the singleton instance is evaluated based on the priorities
assigned for all known providers. The resulting instance is then cached and always returned as
singleton instance fomr this loader, when the same current classloader instance is active.getService
in interface org.apache.tamaya.spi.ServiceContext
T
- the typeserviceType
- the service type.public <T> T getService(Class<T> serviceType, ClassLoader classLoader)
T
- the typeserviceType
- the service type.classLoader
- the classloader, not null.public <T> List<T> getServices(Class<T> serviceType)
getServices
in interface org.apache.tamaya.spi.ServiceContext
T
- the type paramserviceType
- the service type.public <T> List<T> getServices(Class<T> serviceType, ClassLoader classLoader)
T
- the type paramserviceType
- the service type.classLoader
- the classloaderpublic static int getPriority(Object o)
o
- the instance, not null.Copyright © 2014–2016 Apache Software Foundation. All rights reserved.