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>
public final class HelidonServiceLoader<T> extends Object implements Iterable<T>
Helidon specific support for Java Service Loaders.This service loader:
- Can have additional implementations added
- Uses priorities defined either by
Prioritizedor 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
Priorityannotation if present - otherwise a default priority 5000 from
Prioritized.DEFAULT_PRIORITYis used
@Priority(4500) public class MyServiceImpl implements Service, Prioritized { public int priority() { return 6200; } }Such a service would have a priority of6200as 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 priority1will be returned before a service with priority2.- See Also:
ServiceLoader,builder(java.util.ServiceLoader)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHelidonServiceLoader.Builder<T>Fluent api builder forHelidonServiceLoader.
-
Field Summary
Fields Modifier and Type Field Description static StringSYSTEM_PROPERTY_EXCLUDESystem 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<T>asList()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.voidforEach(Consumer<? super T> action)Iterator<T>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 Detail
-
SYSTEM_PROPERTY_EXCLUDE
public static final String 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:
- Constant Field Values
-
-
Method Detail
-
builder
public static <T> HelidonServiceLoader.Builder<T> builder(ServiceLoader<T> serviceLoader)
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
public static <T> HelidonServiceLoader<T> create(ServiceLoader<T> serviceLoader)
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
-
-