public interface ServiceManager
A service is a standard interface or class. A provider is an implementation of that service. A manager tracks registered providers with the service(s) that the provider implements.
Providers are registered at runtime using
setProvider(Object, Class, Object)
. Only one provider
can be registered for each service, but a provider can be marked as
replaceable if it can be replaced with a new provider.
Modifier and Type | Method and Description |
---|---|
<T> Optional<ProviderRegistration<T>> |
getRegistration(Class<T> service)
Gets the
ProviderRegistration for the given service, if available. |
default boolean |
isRegistered(Class<?> service)
Gets whether the class of the type of service is already registered with
this manager.
|
<T> Optional<T> |
provide(Class<T> service)
Return a provider for the given service, if one is available.
|
<T> T |
provideUnchecked(Class<T> service)
Return a provider for the given service, raising an unchecked exception
if a provider does not exist.
|
<T> void |
setProvider(Object plugin,
Class<T> service,
T provider)
Register a provider with the service manager.
|
<T> void setProvider(Object plugin, Class<T> service, T provider)
Services are by definition replaceable at any given time.
Services should only be registered during initialization. If services are registered later, then they may not be utilized.
T
- The type of serviceplugin
- The instance of a pluginservice
- The serviceprovider
- The implementationIllegalArgumentException
- Thrown if plugin
is not a
plugin instance<T> Optional<T> provide(Class<T> service)
The returned provider may be a proxy to the real underlying proxy, depending on the implementation of the service manager.
T
- The type of serviceservice
- The service<T> Optional<ProviderRegistration<T>> getRegistration(Class<T> service)
ProviderRegistration
for the given service, if available.T
- The type of serviceservice
- The serviceProviderRegistration
, if available.default boolean isRegistered(Class<?> service)
service
- The service class<T> T provideUnchecked(Class<T> service) throws ProvisioningException
The returned provider may be a proxy to the real underlying proxy, depending on the implementation of the service manager.
T
- The type of serviceservice
- The serviceProvisioningException
- Thrown if a provider cannot be provisioned