Package eu.cloudnetservice.driver.module
Class DefaultModuleWrapper
java.lang.Object
eu.cloudnetservice.driver.module.DefaultModuleWrapper
- All Implemented Interfaces:
InjectionLayerHolder<dev.derklaro.aerogel.SpecifiedInjector>,ModuleWrapper
Represents the default implementation of the module wrapper.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final URLClassLoaderprivate final Pathprivate final Set<ModuleDependency>private final AtomicReference<ModuleLifeCycle>protected static final eu.cloudnetservice.common.log.Loggerprivate final Moduleprivate final ModuleConfigurationprivate final InjectionLayer<dev.derklaro.aerogel.SpecifiedInjector>private final Lockprivate final ModuleProviderprivate final URLprivate final URIprotected static final Comparator<ModuleTaskEntry>private final Map<ModuleLifeCycle,List<ModuleTaskEntry>> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultModuleWrapper(@NonNull URL source, @NonNull Module module, @NonNull Path dataDirectory, @NonNull ModuleProvider provider, @NonNull URLClassLoader classLoader, @NonNull Set<ModuleDependency> dependingModules, @NonNull ModuleConfiguration moduleConfiguration, @NonNull InjectionLayer<dev.derklaro.aerogel.SpecifiedInjector> moduleInjectionLayer) Creates a new instance of a default module wrapper. -
Method Summary
Modifier and TypeMethodDescriptionGet the class loader which is responsible for this module.Get the data directory of this module in which the module should store its configuration files.Get all modules this module is depending on.protected booleanFires a specific module task entry.@NonNull InjectionLayer<dev.derklaro.aerogel.SpecifiedInjector>Get the injection layer which was used while creating this module instance and is used to inject module tasks.Changes the lifecycle of this module toModuleLifeCycle.LOADEDif possible and fires all associated tasks.module()Get the wrapped module instance of this wrapper.Get the module configuration on which base the module was created.Get the current lifecycle of this wrapper.Get the module provider which loaded this module.Get all module tasks which were detected in the main class of the module.protected voidpushLifecycleChange(@NonNull ModuleLifeCycle lifeCycle, boolean notifyProvider) Fires all handlers registered for the specified lifeCycle.Changes the lifecycle of this module toModuleLifeCycle.RELOADINGif possible and fires all associated tasks.protected @NonNull Map<ModuleLifeCycle,List<ModuleTaskEntry>> resolveModuleTasks(@NonNull Module module) Resolves all module tasks in the main class of a module.Changes the lifecycle of this module toModuleLifeCycle.STARTEDif possible and fires all associated tasks.Changes the lifecycle of this module toModuleLifeCycle.STOPPEDif possible and fires all associated tasks.Changes the lifecycle of this module toModuleLifeCycle.UNLOADEDif possible and fires all associated tasks.uri()Get the uri from where the module was loaded.url()Get the url from where the module was loaded.
-
Field Details
-
LOGGER
protected static final eu.cloudnetservice.common.log.Logger LOGGER -
TASK_COMPARATOR
-
source
-
sourceUri
-
module
-
dataDirectory
-
provider
-
classLoader
-
dependingModules
-
moduleConfiguration
-
moduleInjectionLayer
-
moduleLifecycleUpdateLock
-
tasks
-
lifeCycle
-
-
Constructor Details
-
DefaultModuleWrapper
public DefaultModuleWrapper(@NonNull @NonNull URL source, @NonNull @NonNull Module module, @NonNull @NonNull Path dataDirectory, @NonNull @NonNull ModuleProvider provider, @NonNull @NonNull URLClassLoader classLoader, @NonNull @NonNull Set<ModuleDependency> dependingModules, @NonNull @NonNull ModuleConfiguration moduleConfiguration, @NonNull @NonNull InjectionLayer<dev.derklaro.aerogel.SpecifiedInjector> moduleInjectionLayer) throws URISyntaxException Creates a new instance of a default module wrapper.- Parameters:
source- the module file from which this module was loaded initially.module- the instance of the module main class constructed by the provider.dataDirectory- the data directory of this module relative to the module provider directory.provider- the provider which loaded this module.classLoader- the class loader which was used to load the main class from the file.dependingModules- the modules this module depends on and which need to get loaded first.moduleConfiguration- the parsed module configuration located in the module file.moduleInjectionLayer- the injection layer of the module.- Throws:
URISyntaxException- if the given module source is not formatted strictly according to RFC2396.NullPointerException- if one of the given arguments is null.
-
-
Method Details
-
moduleTasks
Get all module tasks which were detected in the main class of the module.- Specified by:
moduleTasksin interfaceModuleWrapper- Returns:
- an immutable map of all module tasks which were detected in the main class of the module.
-
dependingModules
Get all modules this module is depending on.- Specified by:
dependingModulesin interfaceModuleWrapper- Returns:
- an immutable set of all modules this module is depending on.
-
module
Get the wrapped module instance of this wrapper.- Specified by:
modulein interfaceModuleWrapper- Returns:
- the wrapped module instance of this wrapper.
-
moduleLifeCycle
Get the current lifecycle of this wrapper.- Specified by:
moduleLifeCyclein interfaceModuleWrapper- Returns:
- the current lifecycle of this wrapper.
-
moduleProvider
Get the module provider which loaded this module.- Specified by:
moduleProviderin interfaceModuleWrapper- Returns:
- the module provider which loaded this module.
-
moduleConfiguration
Get the module configuration on which base the module was created.- Specified by:
moduleConfigurationin interfaceModuleWrapper- Returns:
- the module configuration on which base the module was created.
-
classLoader
Get the class loader which is responsible for this module.- Specified by:
classLoaderin interfaceModuleWrapper- Returns:
- the class loader which is responsible for this module.
-
loadModule
Changes the lifecycle of this module toModuleLifeCycle.LOADEDif possible and fires all associated tasks.- Specified by:
loadModulein interfaceModuleWrapper- Returns:
- the same instance of this class, for chaining.
- See Also:
-
startModule
Changes the lifecycle of this module toModuleLifeCycle.STARTEDif possible and fires all associated tasks.- Specified by:
startModulein interfaceModuleWrapper- Returns:
- the same instance of this class, for chaining.
- See Also:
-
reloadModule
Changes the lifecycle of this module toModuleLifeCycle.RELOADINGif possible and fires all associated tasks.- Specified by:
reloadModulein interfaceModuleWrapper- Returns:
- the same instance of this class, for chaining.
- See Also:
-
stopModule
Changes the lifecycle of this module toModuleLifeCycle.STOPPEDif possible and fires all associated tasks.- Specified by:
stopModulein interfaceModuleWrapper- Returns:
- the same instance of this class, for chaining.
- See Also:
-
unloadModule
Changes the lifecycle of this module toModuleLifeCycle.UNLOADEDif possible and fires all associated tasks. The module will be unregistered from the provider, the class loader will be closed and the state of this module changes toModuleLifeCycle.UNUSABLE.- Specified by:
unloadModulein interfaceModuleWrapper- Returns:
- the same instance of this class, for chaining.
- See Also:
-
dataDirectory
Get the data directory of this module in which the module should store its configuration files.- Specified by:
dataDirectoryin interfaceModuleWrapper- Returns:
- the data directory of this module.
-
url
Get the url from where the module was loaded.- Specified by:
urlin interfaceModuleWrapper- Returns:
- the url from where the module was loaded.
-
uri
Get the uri from where the module was loaded.- Specified by:
uriin interfaceModuleWrapper- Returns:
- the uri from where the module was loaded.
-
injectionLayer
Get the injection layer which was used while creating this module instance and is used to inject module tasks.- Specified by:
injectionLayerin interfaceInjectionLayerHolder<dev.derklaro.aerogel.SpecifiedInjector>- Specified by:
injectionLayerin interfaceModuleWrapper- Returns:
- the injection layer of the module.
-
resolveModuleTasks
@NonNull protected @NonNull Map<ModuleLifeCycle,List<ModuleTaskEntry>> resolveModuleTasks(@NonNull @NonNull Module module) Resolves all module tasks in the main class of a module. Declared methods are working as well. The returned map should only contain the tasks sorted as there will be no later step to sort them. Not all module lifecycle states must be in the returned map, if a lifecycle is missing it will be assumed that there is no tasks for that lifecycle.- Parameters:
module- the module instance (better known as the module main class) to resolve the tasks of.- Returns:
- all sorted resolved tasks mapped to the lifecycle they will be called in.
-
pushLifecycleChange
protected void pushLifecycleChange(@NonNull @NonNull ModuleLifeCycle lifeCycle, boolean notifyProvider) Fires all handlers registered for the specified lifeCycle.- Parameters:
lifeCycle- the lifecycle to fire the tasks of.notifyProvider- if the module provider should be notified about the change or not.
-
fireModuleTaskEntry
Fires a specific module task entry.- Parameters:
entry- the entry to fire.- Returns:
- true if the entry couldn't be fired successfully, false otherwise.
-