public class SimpleServiceManager extends Object implements ServiceManager
ServiceManager
.Constructor and Description |
---|
SimpleServiceManager(PluginManager pluginManager)
Construct a simple
ServiceManager . |
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.
|
@Inject public SimpleServiceManager(PluginManager pluginManager)
ServiceManager
.pluginManager
- The plugin manager to get the
PluginContainer
for a given pluginpublic <T> void setProvider(Object plugin, Class<T> service, T provider) throws ProviderExistsException
ServiceManager
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.
setProvider
in interface ServiceManager
T
- The type of serviceplugin
- The instance of a pluginservice
- The serviceprovider
- The implementationProviderExistsException
- Thrown if a provider already exists
and cannot be replacedpublic <T> ServiceReference<T> potentiallyProvide(Class<T> service)
ServiceManager
This allows performing actions when a service is registered, or on the existing service if it is already registered
potentiallyProvide
in interface ServiceManager
T
- The type of serviceservice
- The servicepublic <T> Optional<T> provide(Class<T> service)
ServiceManager
The returned provider may be a proxy to the real underlying proxy, depending on the implementation of the service manager.
provide
in interface ServiceManager
T
- The type of serviceservice
- The servicepublic <T> T provideUnchecked(Class<T> service) throws ProvisioningException
ServiceManager
The returned provider may be a proxy to the real underlying proxy, depending on the implementation of the service manager.
provideUnchecked
in interface ServiceManager
T
- The type of serviceservice
- The serviceProvisioningException
- Thrown if a provider cannot be provisioned