Package io.helidon.common.serviceloader
Class HelidonServiceLoader<T>
java.lang.Object
io.helidon.common.serviceloader.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 priorities defined either by
Prioritized
or byPriority
- 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" 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 priority handling
Service priority is defined by:
- Value provided in
HelidonServiceLoader.Builder.addService(Object, int)
(if used) - then by
Prioritized.priority()
if service implements it - then by
Priority
annotation if present - otherwise a default priority 5000 from
Prioritized.DEFAULT_PRIORITY
is used
@Priority(4500) public class MyServiceImpl implements Service, Prioritized { public int priority() { return 6200; } }Such a service would have a priority of
6200
as that is more significant than the annotation.
A service with lower priority number is returned before a service with a higher priority number.
Services with the same priority have order defined by the order they are in the configured services
and then as they are loaded from the ServiceLoader
.
Negative priorities are not allowed.
A service with priority 1
will be returned before a service with priority 2
.
-
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 prioritized 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 prioritized service loader from a Java Service loader.void
iterator()
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 prioritized 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 prioritized order.- Returns:
- list of service implementations
-