ClassloaderAwarepublic interface ServiceContext extends ClassloaderAware
| Modifier and Type | Field | Description |
|---|---|---|
static boolean |
PRIORITY_ANNOTATION_AVAILABLE |
True if the
Priority annotation class is available on the classpath. |
| Modifier and Type | Method | Description |
|---|---|---|
static boolean |
checkPriorityAnnotation(ClassLoader classLoader) |
Checks if the
Priority annotation class is on the classpath. |
default <T> T |
create(Class<T> serviceType) |
Factory method to createObject a type, hereby a new instance is created on each access.
|
<T> T |
create(Class<T> serviceType,
Supplier<T> supplier) |
Factory method to createObject a type, hereby a new instance is created on each access.
|
static int |
getPriority(Object o) |
Checks the given instance for a @Priority annotation.
|
default URL |
getResource(String resource) |
Loads a resource from the current runtime context.
|
default Collection<URL> |
getResources(String resource) |
Loads resources from the current runtime context.
|
default <T> T |
getService(Class<T> serviceType) |
Access a service singleton via its type.
|
<T> T |
getService(Class<T> serviceType,
Supplier<T> supplier) |
Access a service singleton via its type.
|
default <T> List<T> |
getServices(Class<T> serviceType) |
Access a createList current services, given its type.
|
<T> List<T> |
getServices(Class<T> serviceType,
Supplier<List<T>> supplier) |
Access a createList current services, given its type.
|
default int |
ordinal() |
Get the ordinal of the ServiceContext.
|
<T> List<T> |
register(Class<T> type,
List<T> instances,
boolean force) |
Registers the given instancea as servicea for the given instance, if no
* instance already has been registered.
|
<T> T |
register(Class<T> type,
T instance,
boolean force) |
Registers the given instance as a singleton service for the given instance, if no
instance already has been registered.
|
void |
reset() |
Resets the current service context, removing all loaded services.
|
getClassLoader, initstatic final boolean PRIORITY_ANNOTATION_AVAILABLE
Priority annotation class is available on the classpath.static boolean checkPriorityAnnotation(ClassLoader classLoader)
Priority annotation class is on the classpath.classLoader - the target classloader, not null.default int ordinal()
static int getPriority(Object o)
1 is returned.o - the instance, not null.default <T> T getService(Class<T> serviceType)
Priority will be used.T - the type of the service type.serviceType - the service type.nullConfigException - if there are multiple service implementations with the maximum priority.<T> T getService(Class<T> serviceType, Supplier<T> supplier)
Priority will be used.T - the type of the service type.serviceType - the service type.supplier - the supplier to be used, if no services could be evaluated. If null,
an empty collection is returned, when no services
could be located.nullConfigException - if there are multiple service implementations with the maximum priority.default <T> T create(Class<T> serviceType)
Priority will be used as the base
for creating subsequent instances.T - the type of the service type.serviceType - the service type.nullConfigException - if there are multiple service implementations with the maximum priority.<T> T create(Class<T> serviceType, Supplier<T> supplier)
Priority will be used as the base
for creating subsequent instances.T - the type of the service type.supplier - the supplier to create a new service, if no service could be autodetected.serviceType - the service type.nullConfigException - if there are multiple service implementations with the maximum priority.default <T> List<T> getServices(Class<T> serviceType)
T - the type of the createList element returned by this methodserviceType - the service type.null<T> List<T> getServices(Class<T> serviceType, Supplier<List<T>> supplier)
T - the type of the createList element returned by this methodserviceType - the service type.supplier - the supplier to be used, if no services could be evaluated. If null,
an empty collection is returned, when no services
could be located.nulldefault Collection<URL> getResources(String resource)
resource - the resource, not null.default URL getResource(String resource)
resource - the resource, not null.null.<T> T register(Class<T> type, T instance, boolean force)
T - thy type.type - the type to register, not null.instance - the instance, not null.force - if true, any existing instance will be replaced.<T> List<T> register(Class<T> type, List<T> instances, boolean force)
T - thy type.type - the type to register, not null.instances - the instancea, not null.force - if true, any existing instances will be replaced.void reset()
Copyright © 2014–2019 Apache Software Foundation. All rights reserved.