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:

Note on priority handling

Service priority is defined by:

Example:
 @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.

See Also:
  • Field Details

    • 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 using HelidonServiceLoader.Builder.
      See Also:
  • Method Details

    • 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
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • forEach

      public void forEach(Consumer<? super T> action)
      Specified by:
      forEach in interface Iterable<T>
    • asList

      public List<T> asList()
      Provides a list of service implementations in prioritized order.
      Returns:
      list of service implementations