Package org.dspace.servicemanager
Class DSpaceServiceManager
- java.lang.Object
-
- org.dspace.servicemanager.DSpaceServiceManager
-
- All Implemented Interfaces:
ServiceManager
,ServiceManagerSystem
public final class DSpaceServiceManager extends Object implements ServiceManagerSystem
A service locator based on Spring.- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Field Summary
Fields Modifier and Type Field Description static String
ADDON_RESOURCE_PATH
static String
CONFIG_PATH
static String
CORE_RESOURCE_PATH
protected boolean
developing
protected boolean
running
protected String[]
springXmlConfigFiles
protected boolean
testing
-
Constructor Summary
Constructors Modifier Constructor Description DSpaceServiceManager(DSpaceConfigurationService configurationService)
Standard constructor.protected
DSpaceServiceManager(DSpaceConfigurationService configurationService, String... springXmlConfigFiles)
TESTING - This is for testing only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.context.support.ClassPathXmlApplicationContext
getApplicationContext()
Get the application context.org.springframework.beans.factory.ListableBeanFactory
getBeanFactory()
<T> T
getServiceByName(String name, Class<T> type)
Allows developers to get the desired service singleton by the provided name and type.Map<String,Object>
getServices()
Map service names to their beans.<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.static String[]
getSpringPaths(boolean testMode, String[] configPaths, DSpaceConfigurationService configurationService)
Build the complete list of Spring configuration paths, including hard-wired paths.boolean
isRunning()
boolean
isServiceExists(String name)
Lookup to see if a service exists with the given name.void
notifyServiceManagerReady()
This will call all the services which want to be notified when the service manager is ready.void
pushConfig(Map<String,Object> properties)
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
shutdown()
Shut down the Spring context and leave the "running" state.void
startup()
Startup the service manager and initialize all services.void
unregisterService(String name)
Allows a service to be unregistered (which will only work if nothing depends on it).
-
-
-
Field Detail
-
CONFIG_PATH
public static final String CONFIG_PATH
- See Also:
- Constant Field Values
-
CORE_RESOURCE_PATH
public static final String CORE_RESOURCE_PATH
- See Also:
- Constant Field Values
-
ADDON_RESOURCE_PATH
public static final String ADDON_RESOURCE_PATH
- See Also:
- Constant Field Values
-
running
protected boolean running
-
developing
protected boolean developing
-
testing
protected boolean testing
-
springXmlConfigFiles
protected String[] springXmlConfigFiles
-
-
Constructor Detail
-
DSpaceServiceManager
public DSpaceServiceManager(DSpaceConfigurationService configurationService)
Standard constructor.- Parameters:
configurationService
- current DSpace configuration service
-
DSpaceServiceManager
protected DSpaceServiceManager(DSpaceConfigurationService configurationService, String... springXmlConfigFiles)
TESTING - This is for testing only.- Parameters:
configurationService
- current DSpace configuration service.springXmlConfigFiles
- one or more Spring XML configuration files.
-
-
Method Detail
-
isRunning
public boolean isRunning()
- Returns:
- true if the service manager is running
-
getBeanFactory
public org.springframework.beans.factory.ListableBeanFactory getBeanFactory()
- Returns:
- the current spring bean factory OR null if there is not one.
-
getApplicationContext
public org.springframework.context.support.ClassPathXmlApplicationContext getApplicationContext()
Description copied from interface:ServiceManager
Get the application context.- Specified by:
getApplicationContext
in interfaceServiceManager
- Returns:
- the parent core Spring
ApplicationContext
-
notifyServiceManagerReady
public void notifyServiceManagerReady()
This will call all the services which want to be notified when the service manager is ready.
-
shutdown
public void shutdown()
Shut down the Spring context and leave the "running" state.- Specified by:
shutdown
in interfaceServiceManagerSystem
-
startup
public void startup()
Description copied from interface:ServiceManagerSystem
Startup the service manager and initialize all services.- Specified by:
startup
in interfaceServiceManagerSystem
-
registerService
public void registerService(String name, Object service)
Description copied from interface:ServiceManager
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
ServiceManager.unregisterService(String)
if you are shutting down the context (webapp, etc.) that registered the service so that the full lifecycle completes correctly.- Specified by:
registerService
in interfaceServiceManager
- Parameters:
name
- the name of the service (must be unique)service
- the object to register as a singleton service
-
registerServiceNoAutowire
public void registerServiceNoAutowire(String name, Object service)
Description copied from interface:ServiceManager
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.- Specified by:
registerServiceNoAutowire
in interfaceServiceManager
- Parameters:
name
- the name of the service (must be unique).service
- the instance to register as a singleton service.
-
registerServiceClass
public <T> T registerServiceClass(String name, Class<T> type)
Description copied from interface:ServiceManager
Allows adding singleton services and providers in at runtime or after the service manager has started up. This is the same asServiceManager.registerService(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 ofServiceManager.getServiceByName(String, Class)
.- Specified by:
registerServiceClass
in interfaceServiceManager
- 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
- See Also:
ServiceManager.getServiceByName(String, Class)
-
unregisterService
public void unregisterService(String name)
Description copied from interface:ServiceManager
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.- Specified by:
unregisterService
in interfaceServiceManager
- Parameters:
name
- the name of the service (must be unique)
-
getServiceByName
public <T> T getServiceByName(String name, Class<T> type)
Description copied from interface:ServiceManager
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);
- Specified by:
getServiceByName
in interfaceServiceManager
- 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
-
getServicesByType
public <T> List<T> getServicesByType(Class<T> type)
Description copied from interface:ServiceManager
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).- Specified by:
getServicesByType
in interfaceServiceManager
- 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
-
getServicesNames
public List<String> getServicesNames()
Description copied from interface:ServiceManager
Get the names of all registered service singletons. By convention, the name typically matches the fully qualified class name).- Specified by:
getServicesNames
in interfaceServiceManager
- Returns:
- the list of all current registered services
-
isServiceExists
public boolean isServiceExists(String name)
Description copied from interface:ServiceManager
Lookup to see if a service exists with the given name.- Specified by:
isServiceExists
in interfaceServiceManager
- Parameters:
name
- the unique name for this service- Returns:
- true if it exists, false otherwise
-
getServices
public Map<String,Object> getServices()
Description copied from interface:ServiceManagerSystem
Map service names to their beans.- Specified by:
getServices
in interfaceServiceManagerSystem
- Returns:
- a map of name to bean for all services that are currently known
-
pushConfig
public void pushConfig(Map<String,Object> properties)
Description copied from interface:ServiceManager
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.- Specified by:
pushConfig
in interfaceServiceManager
- Parameters:
properties
- a map of keys (names) and values
-
getSpringPaths
public static String[] getSpringPaths(boolean testMode, String[] configPaths, DSpaceConfigurationService configurationService)
Build the complete list of Spring configuration paths, including hard-wired paths.- Parameters:
testMode
- are we testing the service manager?configPaths
- paths supplied at startup.configurationService
- DSpace configuration source.- Returns:
-
-