java.lang.Object
io.helidon.common.HelidonServiceLoader<T>
- Type Parameters:
T
- Type of the service to be loaded
- All Implemented Interfaces:
Iterable<T>
Helidon specific support for Java Service Loaders.
This service loader:
- Can have additional implementations added
- Uses weights defined either by
Weighted
or byWeight
- Can have exclusions defined by an exact implementation class name, either
in
HelidonServiceLoader.Builder.addExcludedClass(Class)
orHelidonServiceLoader.Builder.addExcludedClassName(String)
or by a system property "io.helidon.common.serviceloader.exclude"<T> that defines a comma separated list of fully qualified class names to be excluded. Note that if a class implements more than one service, it would be excluded from all.
Note on weight handling
Service weight is defined by:
- Value provided in
HelidonServiceLoader.Builder.addService(Object, double)
(if used) - then by
Weighted.weight()
if service implements it - then by
Weight
annotation if present - otherwise a default weight 100.0 from
Weighted.DEFAULT_WEIGHT
is used
@Weight(4500) public class MyServiceImpl implements Service, Weighted { public double weight() { return 6200; } }Such a service would have a weight of
6200
as that is more significant than the annotation.
A service with higher weight is returned before a service with a lower weight number.
Services with the same weight have order defined by the order they are in the configured services
and then as they are loaded from the ServiceLoader
.
Negative weights are not allowed.
A service with weight 2
will be returned before a service with weight 2
.
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
System property used to exclude some implementation from the list of services that are configured for Java Service loader or services that are registered usingHelidonServiceLoader.Builder
. -
Method Summary
Modifier and TypeMethodDescriptionasList()
Provides a list of service implementations in weighted order.static <T> HelidonServiceLoader.Builder
<T> builder
(ServiceLoader<T> serviceLoader) Create a builder for customizable service loader.static <T> HelidonServiceLoader
<T> create
(ServiceLoader<T> serviceLoader) Create a weighted service loader from a Java Service loader.void
iterator()
stream()
Provides a stream of service implementations, in weighted order.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
spliterator
-
Field Details
-
SYSTEM_PROPERTY_EXCLUDE
System property used to exclude some implementation from the list of services that are configured for Java Service loader or services that are registered usingHelidonServiceLoader.Builder
.- See Also:
-
-
Method Details
-
builder
Create a builder for customizable service loader.- Type Parameters:
T
- type of the service- Parameters:
serviceLoader
- the Java Service loader used to get service implementations- Returns:
- a new fluent API builder
-
create
Create a weighted service loader from a Java Service loader.- Type Parameters:
T
- type of the service- Parameters:
serviceLoader
- the Java service loader- Returns:
- service loader with exclusions defined by system properties and no custom services
-
iterator
-
forEach
-
asList
Provides a list of service implementations in weighted order.- Returns:
- list of service implementations
-
stream
Provides a stream of service implementations, in weighted order.- Returns:
- stream os service implementations
-