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> ServiceReference<T> |
potentiallyProvide(Class<T> service)
Return reference to a provider for the given service that may exist now or at any point in the future.
|
<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) throws ProviderExistsException
If a provider already exists for the given service, it will be
replaced if was flagged as replaceable. Otherwise, a
ProviderExistsException
will be thrown. Plugins should provide
options to not install their providers if the plugin is not dedicated
to a single function (such as purely authorization).
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 implementationProviderExistsException
- Thrown if a provider already exists
and cannot be replacedIllegalArgumentException
- 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> ServiceReference<T> potentiallyProvide(Class<T> service)
This allows performing actions when a service is registered, or on the existing service if it is already registered
T
- The type of serviceservice
- The service<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