public abstract class BaseModuleManager<M extends ModuleMetadata,T extends RuntimeModule> extends Object implements ModuleManager<T>
ModuleManager implementations.| Modifier and Type | Field and Description |
|---|---|
protected ModuleMetadataRepository |
metadataRepository |
protected Map<String,T> |
modules |
| Modifier | Constructor and Description |
|---|---|
protected |
BaseModuleManager(ModuleMetadataRepository metadataRepository,
StatsCollector statsCollector)
Construct a new manager.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract M |
acknowledgeMetadata(T module,
M metadata)
Acknowledge module metadata after it has been created afresh or successfully loaded from a
ModuleMetadataRepository. |
void |
checkNotAlreadyRegistered(RuntimeModule module)
Check that the given module isn't already registered with the manager.
|
void |
cleanupMetadata(Set<String> usedModules)
Perform cleanup metadata written by modules that are no longer present.
|
protected abstract M |
createFreshMetadata(T module)
Create new metadata for a module.
|
<M extends RuntimeModule> |
getModule(Class<M> clazz)
Get a module registered with the manager.
|
<M extends RuntimeModule> |
getModule(String moduleId,
Class<M> clazz)
Get a module registered with the manager.
|
protected void |
handleCorruptMetadata(T module)
Handle the fact that metadata for a module has been corrupted.
|
protected void |
handleNoMetadata(T module)
Handle the fact that there was no metadata for a module.
|
Set<String> |
loadMetadata()
Load module metadata from wherever they are stored in between database restarts and do whatever is necessary
to do with this metadata before the modules can be used.
|
void |
registerModule(T module)
Register a module with this manager.
|
void |
shutdownModules()
Bring all modules to an orderly shutdown, when the database is stopped.
|
void |
startModules()
Perform work needed to make modules start doing their job.
|
protected final Map<String,T extends RuntimeModule> modules
protected final ModuleMetadataRepository metadataRepository
protected BaseModuleManager(ModuleMetadataRepository metadataRepository, StatsCollector statsCollector)
metadataRepository - repository for storing module metadata.public final void registerModule(T module)
registerModule in interface ModuleManager<T extends RuntimeModule>module - to register.public <M extends RuntimeModule> M getModule(String moduleId, Class<M> clazz)
getModule in interface ModuleManager<T extends RuntimeModule>M - type of the class above.moduleId - module ID.clazz - expected class of the module.null if no such module exists.public <M extends RuntimeModule> M getModule(Class<M> clazz)
getModule in interface ModuleManager<T extends RuntimeModule>M - type of the class above.clazz - class of the module.null if no such module exists.public void checkNotAlreadyRegistered(RuntimeModule module)
checkNotAlreadyRegistered in interface ModuleManager<T extends RuntimeModule>module - to check.IllegalStateException - in case the module is already registered.public final Set<String> loadMetadata()
loadMetadata in interface ModuleManager<T extends RuntimeModule>protected void handleCorruptMetadata(T module)
createFreshMetadata(com.graphaware.runtime.module.RuntimeModule)
will be called. This means that if the module doesn't heavily rely on its metadata, there is no need to override
this method.module - that had corrupted metadata.protected void handleNoMetadata(T module)
ModuleMetadataRepository
stores them.
After this method has returned, it is guaranteed that createFreshMetadata(com.graphaware.runtime.module.RuntimeModule)
will be called. This means that there is no need to override this method unless there is some work that needs to
be done in addition to creating new metadata.module - that had no metadata.protected abstract M createFreshMetadata(T module)
module - for which to create metadata.protected abstract M acknowledgeMetadata(T module, M metadata)
ModuleMetadataRepository.
The implementation can, for example, choose to let the module know about its own metadata. This method also gives
the subclasses the opportunity to modify the metadata before it is persisted to the database.module - for which to acknowledge metadata.metadata - to acknowledge.public void cleanupMetadata(Set<String> usedModules)
cleanupMetadata in interface ModuleManager<T extends RuntimeModule>usedModules - IDs of all modules that are known to be used by the runtime during the current run.public void startModules()
startModules in interface ModuleManager<T extends RuntimeModule>public void shutdownModules()
shutdownModules in interface ModuleManager<T extends RuntimeModule>Copyright © 2013-2016–2018 Graph Aware Limited. All rights reserved.