Class ServiceLoaderUtils
java.lang.Object
de.iip_ecosphere.platform.support.jsl.ServiceLoaderUtils
Helper functions for Java Service Loading.
- Author:
- Holger Eichelberger, SSE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <D> Optional<D> filterExcluded(Class<D> descriptorClass) Filters excluded descriptors, i.e., descriptors marked withExcludeFirst.static <D> Optional<D> Convenience method forfindFirst(ServiceLoader)based on default loading of the service descriptors.static <D> Optional<D> findFirst(ServiceLoader<D> loader) Load the first available service provider of the givenloader's service.static booleanhasExcludeFirst(Object instance) Returns whether aninstanceis tagged with theExcludeFirstannotation.static <D> ServiceLoader<D> Creates a service loader for the givenclsusingPluginSetup.getClassLoader()as class loader.static <D> Stream<D> stream(ServiceLoader<D> loader) Turns the service loader into a stream.
-
Constructor Details
-
ServiceLoaderUtils
public ServiceLoaderUtils()
-
-
Method Details
-
filterExcluded
Filters excluded descriptors, i.e., descriptors marked withExcludeFirst. If selection by filtering does not work, the first descriptor is returned.- Type Parameters:
D- the descriptor type- Parameters:
descriptorClass- the descriptor class- Returns:
- the found descriptor, may be an empty optional instance
- See Also:
-
findFirst
Convenience method forfindFirst(ServiceLoader)based on default loading of the service descriptors.- Type Parameters:
D- the descriptor type- Parameters:
descriptorClass- the descriptor class- Returns:
- the first service provider
- See Also:
-
findFirst
Load the first available service provider of the givenloader's service. [JDK 1.8 compatibility]- Type Parameters:
D- the service descriptor type- Parameters:
loader- the loader instance- Returns:
- the first service provider
-
stream
Turns the service loader into a stream. [JDK 1.8 compatibility]- Type Parameters:
D- the service descriptor type- Parameters:
loader- the loader instance- Returns:
- the stream of descriptor
-
hasExcludeFirst
Returns whether aninstanceis tagged with theExcludeFirstannotation.- Parameters:
instance- the instance to check (may be null)- Returns:
trueif the annotation is present,falseelse
-
load
Creates a service loader for the givenclsusingPluginSetup.getClassLoader()as class loader.- Type Parameters:
D- the descriptor type- Parameters:
cls- the class of the descriptor type- Returns:
- the service loader
-