public class ModuleFactory extends Object
Modifier and Type | Field and Description |
---|---|
protected static Map<String,List<Extension>> |
extensionMap |
protected static com.google.common.cache.Cache<String,Module> |
loadedModules |
protected static com.google.common.cache.Cache<Module,ModuleClassLoader> |
moduleClassLoaders |
protected static com.google.common.cache.Cache<String,Module> |
startedModules |
Modifier and Type | Method and Description |
---|---|
static List<String> |
getDependencies(String moduleId)
Convenience method used to identify module interdependencies and alert the user before modules
are shut down.
|
static Map<String,List<Extension>> |
getExtensionMap()
Return the current extension map keyed on extension point id
|
static List<Extension> |
getExtensions(String pointId)
Return all of the extensions associated with the given
pointId Returns empty
extension list if no modules extend this pointId |
static List<Extension> |
getExtensions(String pointId,
Extension.MEDIA_TYPE type)
Return all of the extensions associated with the given
pointId Returns
getExtension(pointId) if no modules extend this pointId for given media type |
static List<GlobalProperty> |
getGlobalProperties()
Get a list of required GlobalProperties defined by the modules
|
static Collection<Module> |
getLoadedModules()
Returns all modules found/loaded into the system (started and not started)
|
static List<Module> |
getLoadedModulesCoreFirst()
Returns all modules found/loaded into the system (started and not started), with the core modules
at the start of that list
|
static Map<String,Module> |
getLoadedModulesMap()
Returns all modules found/loaded into the system (started and not started) in the form of a
map<ModuleId, Module>
|
static Map<String,Module> |
getLoadedModulesMapPackage()
Returns all modules found/loaded into the system (started and not started) in the form of a
map<PackageName, Module>
|
static Module |
getModuleById(String moduleId) |
static Module |
getModuleByPackage(String modulePackage) |
static ModuleClassLoader |
getModuleClassLoader(Module mod)
Get a module's classloader
|
static ModuleClassLoader |
getModuleClassLoader(String moduleId)
Get a module's classloader via the module id
|
static Map<Module,ModuleClassLoader> |
getModuleClassLoaderMap()
Return all current classloaders keyed on module object
|
static Collection<ModuleClassLoader> |
getModuleClassLoaders()
Returns all module classloaders This method will not return null
|
static Set<ModuleClassLoader> |
getModuleClassLoadersForPackage(String packageName) |
static List<Module> |
getModulesInStartupOrder(Collection<Module> modules)
Sort modules in startup order based on required and aware-of dependencies
|
static List<Privilege> |
getPrivileges()
Get a list of required Privileges defined by the modules
|
static Module |
getStartedModuleById(String moduleId) |
static Collection<Module> |
getStartedModules()
Returns the modules that have been successfully started
|
static List<Module> |
getStartedModulesInOrder() |
static Map<String,Module> |
getStartedModulesMap()
Returns the modules that have been successfully started in the form of a map<ModuleId,
Module>
|
static boolean |
isModuleStarted(Module mod)
Checks whether the given module is activated
|
static boolean |
isModuleStarted(String moduleId)
Checks whether the given module, identified by its id, is started.
|
static boolean |
isTokenValid(DaemonToken token)
Validates the given token.
|
static void |
loadAdvice(Module module)
Loop over the given module's advice objects and load them into the Context This needs to be
called for all started modules after every restart of the Spring Application Context
|
static Module |
loadModule(File moduleFile)
Add a module (in the form of a jar file) to the list of openmrs modules Returns null if an error
occurred and/or module was not successfully loaded
|
static Module |
loadModule(File moduleFile,
Boolean replaceIfExists)
Add a module (in the form of a jar file) to the list of openmrs modules Returns null if an error
occurred and/or module was not successfully loaded
|
static Module |
loadModule(Module module,
Boolean replaceIfExists)
Add a module to the list of openmrs modules
|
static void |
loadModules()
Load OpenMRS modules from
OpenmrsUtil.getModuleRepository() |
static void |
loadModules(List<File> modulesToLoad)
Attempt to load the given files as OpenMRS modules
|
static Module |
startModule(Module module) |
static Module |
startModule(Module module,
boolean isOpenmrsStartup,
org.springframework.context.support.AbstractRefreshableApplicationContext applicationContext)
Runs through extensionPoints and then calls
BaseModuleActivator.willStart() on the
Module's activator. |
static Module |
startModuleInternal(Module module)
This method should not be called directly.
|
static Module |
startModuleInternal(Module module,
boolean isOpenmrsStartup,
org.springframework.context.support.AbstractRefreshableApplicationContext applicationContext)
This method should not be called directly.
|
static void |
startModules()
Try to start all of the loaded modules that have the global property moduleId.started is
set to "true" or the property does not exist.
|
static void |
stopModule(Module mod)
Runs through the advice and extension points and removes from api.
|
static void |
stopModule(Module mod,
boolean isShuttingDown)
Runs through the advice and extension points and removes from api.
|
static List<Module> |
stopModule(Module mod,
boolean skipOverStartedProperty,
boolean isFailedStartup)
Runs through the advice and extension points and removes from api.
|
static void |
unloadModule(Module mod)
Removes module from module repository
|
static Module |
updateModule(Module mod)
Update the module: 1) Download the new module 2) Unload the old module 3) Load/start the new
module
|
protected static final com.google.common.cache.Cache<Module,ModuleClassLoader> moduleClassLoaders
public static Module loadModule(File moduleFile) throws ModuleException
moduleFile
- ModuleException
public static Module loadModule(File moduleFile, Boolean replaceIfExists) throws ModuleException
moduleFile
- replaceIfExists
- unload a module that has the same moduleId if one is loaded alreadyModuleException
public static Module loadModule(Module module, Boolean replaceIfExists) throws ModuleException
module
- replaceIfExists
- unload a module that has the same moduleId if one is loaded already
Should load module if it is currently not loaded
Should not load module if already loaded Should
always load module if replacement is wanted Should not load an older
version of the same module Should load a newer version of the same
moduleModuleException
public static void loadModules()
OpenmrsUtil.getModuleRepository()
public static void loadModules(List<File> modulesToLoad)
modulesToLoad
- the list of files to try and load Should not crash when
file is not found or broken Should setup requirement mappings for
every module Should not start the loaded modulespublic static void startModules()
public static List<Module> getModulesInStartupOrder(Collection<Module> modules) throws CycleException
modules
- list of modules to sortCycleException
public static List<Module> getLoadedModulesCoreFirst()
List<Module>
of the modules loaded into the system, with the core
modules first.public static Collection<Module> getLoadedModules()
Collection<Module>
of the modules loaded into the systempublic static Map<String,Module> getLoadedModulesMap()
public static Map<String,Module> getLoadedModulesMapPackage()
public static Collection<Module> getStartedModules()
Collection<Module>
of the started modulespublic static Map<String,Module> getStartedModulesMap()
public static Module getModuleById(String moduleId)
moduleId
- public static Module getStartedModuleById(String moduleId)
moduleId
- public static Module getModuleByPackage(String modulePackage)
modulePackage
- public static Module startModule(Module module) throws ModuleException
public static Module startModule(Module module, boolean isOpenmrsStartup, org.springframework.context.support.AbstractRefreshableApplicationContext applicationContext) throws ModuleException
BaseModuleActivator.willStart()
on the
Module's activator. This method is run in a new thread and is authenticated as the Daemon user.
If a non null application context is passed in, it gets refreshed to make the module's services
availablemodule
- Module to startisOpenmrsStartup
- Specifies whether this module is being started at application startup or
not, this argument is ignored if a null application context is passed inapplicationContext
- the spring application context instance to refreshModuleException
- if the module throws any kind of error at startup or in an activatorstartModuleInternal(Module, boolean, AbstractRefreshableApplicationContext)
,
Daemon.startModule(Module, boolean, AbstractRefreshableApplicationContext)
public static Module startModuleInternal(Module module) throws ModuleException
startModule(Module)
(and hence Daemon.startModule(Module)
) calls this method
in a new Thread and is authenticated as the Daemon
userBaseModuleActivator.willStart()
on the
Module's activator.module
- Module to startModuleException
public static Module startModuleInternal(Module module, boolean isOpenmrsStartup, org.springframework.context.support.AbstractRefreshableApplicationContext applicationContext) throws ModuleException
startModule(Module)
(and hence Daemon.startModule(Module)
) calls this method
in a new Thread and is authenticated as the Daemon
userBaseModuleActivator.willStart()
on the
Module's activator. module
- Module to startisOpenmrsStartup
- Specifies whether this module is being started at application startup or
not, this argument is ignored if a null application context is passed inapplicationContext
- the spring application context instance to refreshModuleException
public static Set<ModuleClassLoader> getModuleClassLoadersForPackage(String packageName)
public static void loadAdvice(Module module)
module
- public static void stopModule(Module mod)
mod
- module to stopstopModule(Module, boolean, boolean)
public static void stopModule(Module mod, boolean isShuttingDown)
mod
- the module to stopisShuttingDown
- true if this is called during the process of shutting down openmrsstopModule(Module, boolean, boolean)
public static List<Module> stopModule(Module mod, boolean skipOverStartedProperty, boolean isFailedStartup) throws ModuleMustStartException
skipOverStartedProperty
should only be true when openmrs is stopping modules because
it is shutting down. When normally stopping a module, use stopModule(Module)
(or leave
value as false). This property controls whether the globalproperty is set for startup/shutdown.
ModuleActivator.stopped()
mod
- module to stopskipOverStartedProperty
- true if we don't want to set <moduleid>.started to falseisFailedStartup
- true if this is being called as a cleanup because of a failed module
startupModuleMustStartException
public static void unloadModule(Module mod)
mod
- module to unloadpublic static List<Extension> getExtensions(String pointId)
pointId
Returns empty
extension list if no modules extend this pointIdpointId
- public static List<Extension> getExtensions(String pointId, Extension.MEDIA_TYPE type)
pointId
Returns
getExtension(pointId) if no modules extend this pointId for given media typepointId
- type
- Extension.MEDIA_TYPEpublic static List<Privilege> getPrivileges()
List<Privilege>
of the required privilegespublic static List<GlobalProperty> getGlobalProperties()
List<GlobalProperty>
object of the module's global propertiespublic static boolean isModuleStarted(Module mod)
mod
- Module to checkpublic static boolean isModuleStarted(String moduleId)
moduleId
- module id. e.g formentry, logicpublic static ModuleClassLoader getModuleClassLoader(Module mod) throws ModuleException
mod
- Module to fetch the class loader forModuleException
- if the module does not have a registered classloaderpublic static ModuleClassLoader getModuleClassLoader(String moduleId) throws ModuleException
moduleId
- String
id of the moduleModuleException
- if this module isn't started or doesn't have a classloadergetModuleClassLoader(Module)
public static Collection<ModuleClassLoader> getModuleClassLoaders()
public static Map<Module,ModuleClassLoader> getModuleClassLoaderMap()
public static Map<String,List<Extension>> getExtensionMap()
public static Module updateModule(Module mod) throws ModuleException
mod
- ModuleException
public static boolean isTokenValid(DaemonToken token)
It is thread safe.
token
- public static List<String> getDependencies(String moduleId)
moduleId
- the moduleId used to identify the module being validatedCopyright © 2024 OpenMRS Inc.. All rights reserved.