public class SharedRegistryImpl extends Object implements SharedRegistry
Modifier | Constructor and Description |
---|---|
protected |
SharedRegistryImpl()
Creates a new shared registry implementation.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
getService(Class<T> service)
Gets the instance of the given service.
|
<T> T |
getService(Class<T> service,
boolean singleton)
Gets the registered implementation for the given service.
|
<T> T |
getService(Class<T> service,
Class<? extends T> defaultImplementation)
Gets the registered implementation for the given service.
|
<T> T |
getService(Class<T> service,
Class<? extends T> defaultImplementation,
boolean singleton)
Gets the registered implementation for the given service.
|
<T> void |
register(Class<T> service,
T implementation)
Registers a service implementation.
|
<T> void |
unregister(Class<T> service,
T implementation)
Unregisters a service implementation.
|
protected SharedRegistryImpl()
public <T> T getService(Class<T> service)
ServiceLoader
Equivalent to calling ServiceLoader.getService(Class, boolean)
passing @{code true} as @{code singleton}.
getService
in interface ServiceLoader
getService
in interface ServiceProvider
T
- the service type.service
- the service.public <T> T getService(Class<T> service, boolean singleton)
ServiceLoader
If a singleton is asked and if an instance of this service has already been created, this instance is returned. Otherwise, creates a new instance of the implementation type.
getService
in interface ServiceLoader
T
- the service type.service
- the service.singleton
- if true
returns an already created instance if any, creates a new one otherwise.null
if no implementation is available.public <T> T getService(Class<T> service, Class<? extends T> defaultImplementation)
ServiceLoader
getService
in interface ServiceLoader
T
- the service type.service
- the service.defaultImplementation
- the default implementation to use.public <T> T getService(Class<T> service, Class<? extends T> defaultImplementation, boolean singleton)
ServiceLoader
If a singleton is asked and if an instance of this service has already been created, this instance is returned. Otherwise, creates a new instance of the implementation type.
getService
in interface ServiceLoader
T
- the service type.service
- the service.defaultImplementation
- the default implementation to use.singleton
- if true
returns an already created instance if any, creates a new one otherwise.public <T> void register(Class<T> service, T implementation)
ServiceRegistry
The given instance is returned each time the service is requested by ServiceProvider.getService(Class)
.
register
in interface ServiceRegistry
T
- the service type.service
- the implemented service.implementation
- the service implementation.public <T> void unregister(Class<T> service, T implementation)
SharedRegistry
The given instance is no more returned each time the service is requested by ServiceLoader.getService(Class)
.
unregister
in interface SharedRegistry
T
- the service type.service
- the implemented service.implementation
- the service implementation.