public class ModuleRegistry extends Object implements IModuleManager<IModule<?>>, IEventProducer
This class is in charge of loading all configured modules on startup as well as dynamically loading/unloading modules on demand. It also keeps lists of all loaded and available modules.
TODO implement global event manager for all modules ? TODO return weak references to modules ?Constructor and Description |
---|
ModuleRegistry(IModuleConfigRepository configRepos) |
Modifier and Type | Method and Description |
---|---|
void |
destroyModule(String moduleID)
Removes the module with the given id
|
void |
disableModule(String moduleID)
Disables the module with the given id
|
IModule<?> |
enableModule(String moduleID)
Enables/Start the module with the given id
|
List<ModuleConfig> |
getAvailableModules()
Gets the list of all modules handled by this manager
that are configured but not yet loaded (i.e.
|
List<IModuleProvider> |
getInstalledModuleTypes()
Retrieves list of all installed module types
|
List<IModuleProvider> |
getInstalledModuleTypes(Class<?> moduleClass)
Retrieves list of all installed module types that are sub-types
of the specified class
|
List<IModule<?>> |
getLoadedModules()
Gets the list of all modules handled by this manager
that are already loaded (i.e.
|
IModule<?> |
getModuleById(String moduleID)
Retrieves a module instance by its local ID
|
WeakReference<? extends IModule<?>> |
getModuleRef(String moduleID) |
boolean |
isModuleLoaded(String moduleID) |
void |
loadAllModules()
Loads all enabled modules from configuration entries provided
by the specified IModuleConfigRepository
|
IModule<?> |
loadModule(ModuleConfig config)
Instantiates one module using the given configuration
|
void |
registerListener(IEventListener listener)
Registers a listener with this event producer.
|
void |
saveConfiguration(ModuleConfig... configList)
Saves the given module configurations in the repository
|
void |
saveModulesConfiguration()
Save all modules current configuration to the repository
|
void |
shutdown(boolean saveConfig,
boolean saveState)
Shuts down all modules and the config repository
|
void |
unloadModule(String moduleID)
Unloads a module instance.
This causes the module to be removed from registry but its last saved configuration is kept as-is. |
void |
unregisterListener(IEventListener listener)
Unregisters a listener from this event producer.
|
public ModuleRegistry(IModuleConfigRepository configRepos)
public void loadAllModules()
public IModule<?> loadModule(ModuleConfig config) throws SensorHubException
config
- Configuration class to use to instantiate the moduleSensorHubException
public boolean isModuleLoaded(String moduleID)
isModuleLoaded
in interface IModuleManager<IModule<?>>
moduleID
- local ID of modulepublic void unloadModule(String moduleID) throws SensorHubException
saveConfiguration(ModuleConfig...)
first if you want to
keep the current config.moduleID
- SensorHubException
public IModule<?> enableModule(String moduleID) throws SensorHubException
moduleID
- Local ID of module to enableSensorHubException
public void disableModule(String moduleID) throws SensorHubException
moduleID
- Local ID of module to disableSensorHubException
public void destroyModule(String moduleID) throws SensorHubException
moduleID
- Local ID of module to deleteSensorHubException
public void saveModulesConfiguration()
public void saveConfiguration(ModuleConfig... configList)
configList
- public List<IModule<?>> getLoadedModules()
IModuleManager
getLoadedModules
in interface IModuleManager<IModule<?>>
public IModule<?> getModuleById(String moduleID) throws SensorHubException
IModuleManager
getModuleById
in interface IModuleManager<IModule<?>>
moduleID
- Id of module to retrieveSensorHubException
public WeakReference<? extends IModule<?>> getModuleRef(String moduleID) throws SensorHubException
SensorHubException
public List<ModuleConfig> getAvailableModules()
IModuleManager
getAvailableModules
in interface IModuleManager<IModule<?>>
public List<IModuleProvider> getInstalledModuleTypes()
public List<IModuleProvider> getInstalledModuleTypes(Class<?> moduleClass)
moduleClass
- Parent class of modules to search forpublic void shutdown(boolean saveConfig, boolean saveState) throws SensorHubException
saveConfig
- If true, save current modules configsaveState
- If true, save current module stateSensorHubException
public void registerListener(IEventListener listener)
IEventProducer
registerListener
in interface IEventProducer
public void unregisterListener(IEventListener listener)
IEventProducer
unregisterListener
in interface IEventProducer
Copyright © 2015 Sensia Software LLC. All rights reserved.