Package org.dspace.kernel
Interface ServiceManager
-
- All Known Subinterfaces:
ExternalServiceManagerSystem
,ServiceManagerSystem
- All Known Implementing Classes:
DSpaceServiceManager
public interface ServiceManager
Allows for non-specific access to the core services. No dependency on the underlying mechanism is exposed.- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description org.springframework.context.ConfigurableApplicationContext
getApplicationContext()
Get the application context.<T> T
getServiceByName(String name, Class<T> type)
Allows developers to get the desired service singleton by the provided name and type.<T> List<T>
getServicesByType(Class<T> type)
Allows developers to get the desired service singleton by the provided type.List<String>
getServicesNames()
Get the names of all registered service singletons.boolean
isServiceExists(String name)
Lookup to see if a service exists with the given name.void
pushConfig(Map<String,Object> settings)
Allows new configuration settings to be pushed into the core DSpace configuration.void
registerService(String name, Object service)
Allows adding singleton services and providers in at runtime or after the service manager has started up.<T> T
registerServiceClass(String name, Class<T> type)
Allows adding singleton services and providers in at runtime or after the service manager has started up.void
registerServiceNoAutowire(String name, Object service)
Add a singleton service at runtime, but do not inject dependencies.void
unregisterService(String name)
Allows a service to be unregistered (which will only work if nothing depends on it).
-
-
-
Method Detail
-
getApplicationContext
org.springframework.context.ConfigurableApplicationContext getApplicationContext()
Get the application context.- Returns:
- the Spring application context.
-
getServicesByType
<T> List<T> getServicesByType(Class<T> type)
Allows developers to get the desired service singleton by the provided type.
This should return all instantiated objects of the type specified (may not all be singletons).- Type Parameters:
T
- Class type- Parameters:
type
- the type for the requested service (this will typically be the interface class but can be concrete as well)- Returns:
- the list of service singletons OR empty list if none is found
-
getServiceByName
<T> T getServiceByName(String name, Class<T> type)
Allows developers to get the desired service singleton by the provided name and type. Providenull
for the name if it is not known, but it is better to ensure it is set.NOTE: This also allows special access to the underlying service manager objects. If using Spring this allows access to the underlying ApplicationContext object like so:
getServiceByName(ApplicationContext.class.getName(), ApplicationContext.class);
- Type Parameters:
T
- Class type.- Parameters:
name
- (optional) the unique name for this service. If null then the bean will be returned if there is only one service of this type.type
- the type for the requested service (this will typically be the interface class but can be concrete as well).- Returns:
- the service singleton OR null if none is found
-
isServiceExists
boolean isServiceExists(String name)
Lookup to see if a service exists with the given name.- Parameters:
name
- the unique name for this service- Returns:
- true if it exists, false otherwise
-
getServicesNames
List<String> getServicesNames()
Get the names of all registered service singletons. By convention, the name typically matches the fully qualified class name).- Returns:
- the list of all current registered services
-
registerService
void registerService(String name, Object service)
Allows adding singleton services and providers in at runtime or after the service manager has started up. This is primarily useful for registering providers, filters, and plugins with the DSpace core.NOTE: It is important that you also call
unregisterService(String)
if you are shutting down the context (webapp, etc.) that registered the service so that the full lifecycle completes correctly.- Parameters:
name
- the name of the service (must be unique)service
- the object to register as a singleton service- Throws:
IllegalArgumentException
- if the service cannot be registered
-
registerServiceNoAutowire
void registerServiceNoAutowire(String name, Object service)
Add a singleton service at runtime, but do not inject dependencies. Typically used with a service instance that has already had all dependencies injected explicitly, for example in test code.- Parameters:
name
- the name of the service (must be unique).service
- the instance to register as a singleton service.
-
registerServiceClass
<T> T registerServiceClass(String name, Class<T> type)
Allows adding singleton services and providers in at runtime or after the service manager has started up. This is the same asregisterService(String, Object)
except that it allows the core service manager to startup your service for you instead of you providing a service to the core. In general, it is better if you use your own service manager (like Spring) to manage your services and simply inherit the core service beans from the DSpace core service manager using the special capabilities ofgetServiceByName(String, Class)
.- Type Parameters:
T
- Class type- Parameters:
name
- the name of the service (must be unique)type
- the class type of the service (must be in the current classloader)- Returns:
- the service class
- Throws:
IllegalArgumentException
- if the service cannot be registered because the name is taken or type is invalid or other- See Also:
getServiceByName(String, Class)
-
unregisterService
void unregisterService(String name)
Allows a service to be unregistered (which will only work if nothing depends on it). This is primarily used for providers, filters, plugins, etc. which were registered but are no longer available because the context they are running in is shutting down or restarting.
WARNING: This should not be used to attempt to unregister core services as that will fail.- Parameters:
name
- the name of the service (must be unique)- Throws:
IllegalArgumentException
- if the bean cannot be unregistered
-
pushConfig
void pushConfig(Map<String,Object> settings)
Allows new configuration settings to be pushed into the core DSpace configuration. These will cause a settings refresh action to be called for all services which are listening and will cause any bean properties to be pushed into existing beans.- Parameters:
settings
- a map of keys (names) and values
-
-