Class ServiceHelper

java.lang.Object
io.github.mmm.base.service.ServiceHelper

public final class ServiceHelper extends Object
Helper class for ServiceLoader.
Since:
1.0.0
  • Method Details

    • singleton

      public static final <S> S singleton(ServiceLoader<S> serviceLoader)
      Type Parameters:
      S - type of the service.
      Parameters:
      serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
      Returns:
      the requested service.
    • singleton

      public static final <S> S singleton(ServiceLoader<S> serviceLoader, boolean unique)
      Type Parameters:
      S - type of the service.
      Parameters:
      serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
      unique - - true if an exception is thrown if the service is not unique, false otherwise (allow overriding default).
      Returns:
      the requested service.
    • all

      public static final <S> void all(ServiceLoader<S> serviceLoader, Collection<S> services)
      Type Parameters:
      S - type of the service.
      Parameters:
      serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
      services - the Collection where to add the services from the given ServiceLoader.
    • all

      public static final <S> void all(ServiceLoader<S> serviceLoader, Collection<S> services, int min)
      Type Parameters:
      S - type of the service.
      Parameters:
      serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
      services - the Collection where to add the services from the given ServiceLoader.
      min - the minimum number of services required.
    • all

      public static final <S, K> void all(ServiceLoader<S> serviceLoader, Map<K,S> services, Function<S,K> keyFunction)
      Type Parameters:
      S - type of the service.
      K - type of the Map key.
      Parameters:
      serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
      services - the Collection where to add the services from the given ServiceLoader.
      keyFunction - the Function to get the Map key from the service.
    • all

      public static final <S, K> void all(ServiceLoader<S> serviceLoader, Map<K,S> services, Function<S,K> keyFunction, int min)
      Type Parameters:
      S - type of the service.
      K - type of the Map key.
      Parameters:
      serviceLoader - the ServiceLoader that has to be provided from the module declaring the service API and holds the uses statement in its module-info.
      services - the Collection where to add the services from the given ServiceLoader.
      keyFunction - the Function to get the Map key from the service.
      min - the minimum number of services required.