@Beta @PublicAPI public final class ServiceUtil extends Object
Please note that in the future different DI solutions might be used instead of ServiceLoader.
Please note that this class is annotated with the Beta
annotation, so
Modifier and Type | Method and Description |
---|---|
static <S> boolean |
isServiceAvailable(Class<S> service)
Check if a specific service is defined and implementation can be loaded.
|
static <S> S |
loadService(Class<S> service,
boolean ensureSingle)
Load and instantiate an implementation for a given service interface.
|
public static <S> S loadService(Class<S> service, boolean ensureSingle) throws ServiceConfigurationError
S
- Interface type to instantiateservice
- Service interface classensureSingle
- Ensure that only one implementation exists. If set and multiple implementations found then a
ServiceConfigurationError
is thrown.ServiceConfigurationError
- When something goes wrong (in the underlying ServiceLoader
, incase no
implementation found, or ensureSingle
is true and multiple implementations foundpublic static <S> boolean isServiceAvailable(Class<S> service) throws ServiceConfigurationError
Note that there is no guarantee regarding the successfull instantiation of the service.
S
- Interface typeservice
- Service interface classServiceConfigurationError
- can be thrown by the underlying ServiceLoader
.