Class ModuleService

java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.ModuleService
All Implemented Interfaces:
IService

public class ModuleService extends BaseService
This service is in charge of managing BoxLang modules
  • Field Details

  • Constructor Details

    • ModuleService

      public ModuleService(BoxRuntime runtime)
      Constructor
      Parameters:
      runtime - The runtime instance
  • Method Details

    • getModulePaths

      public List<Path> getModulePaths()
      Get the list of module paths registered in the module service
      Returns:
      the modulePaths
    • onConfigurationLoad

      public void onConfigurationLoad()
      The configuration load event is fired when the runtime loads the configuration
      Specified by:
      onConfigurationLoad in interface IService
      Specified by:
      onConfigurationLoad in class BaseService
    • onStartup

      public void onStartup()
      The startup event is fired when the runtime starts up
      Specified by:
      onStartup in interface IService
      Specified by:
      onStartup in class BaseService
    • onShutdown

      public void onShutdown(Boolean force)
      The shutdown event is fired when the runtime shuts down
      Specified by:
      onShutdown in interface IService
      Specified by:
      onShutdown in class BaseService
      Parameters:
      force - Whether the shutdown is forced
    • registerAll

      public void registerAll()
      Scans all possible module locations and registers all modules found This method doesn't activate the modules, it just registers them
    • register

      public void register(Key name)
      Register a module. This method doesn't activate the module, it just registers it. Duplicate modules are not allowed, first one wins. The module must be in the module registry or it will throw an exception.
      Parameters:
      name - The name of the module to register
      Throws:
      BoxRuntimeException - If the module is not in the module registry
    • activateAll

      public void activateAll()
      Activate all modules that are not disabled
    • activate

      public void activate(Key name)
      Activate a module
      Parameters:
      name - The name of the module to activate
      Throws:
      BoxRuntimeException - If the module is not in the module registry
    • unloadAll

      public void unloadAll()
      Unload all modules
    • unload

      public void unload(Key name, Boolean removeFromRegistry)
      Unload a module if it exists, else it's ignored
      Parameters:
      name - The name of the module to unload
    • reloadAll

      public void reloadAll()
      Reload all modules
    • reload

      public void reload(Key name)
      Helper to reload a module
      Parameters:
      name - The name of the module to reload
    • getRegistry

      public Map<Key,ModuleRecord> getRegistry()
      Get the module registry
    • getModuleNames

      public List<Key> getModuleNames()
      Get a list of module names in the registry
      Returns:
      The list of module names
    • getModuleRecord

      public ModuleRecord getModuleRecord(Key name)
      Get a module record from the registry
      Parameters:
      name - The name of the module to get
      Returns:
      The module record or null if not found
    • getModuleSettings

      public IStruct getModuleSettings(Key name)
      Retrieves the module settings for a requested module
      Parameters:
      name - The name of the module to get settings for
      Returns:
      The settings for the module as a struct
    • hasModule

      public boolean hasModule(Key name)
      Verify if we have a module in the registry
      Parameters:
      name - The name of the module to verify
      Returns:
      True if the module is in the registry, false otherwise
    • addModulePath

      public ModuleService addModulePath(String path)
      Add a module path to the list of paths to search for modules. This has to be an absolute path on disk or a relative path to the runtime resources using forward slashes.
      Parameters:
      path - The string path to add, package resources path or absolute path using forward slashes.
      Returns:
      The ModuleService instance
    • addModulePath

      public ModuleService addModulePath(Path path)
      Add a module Path to the list of paths to search for modules.
      Parameters:
      path - The Path to add. It can be relative or absolute, but it must exist or it is ignored.
      Returns:
      The ModuleService instance
    • verifyModuleAndBoxLangVersion

      public void verifyModuleAndBoxLangVersion(String moduleVersion, Path directoryPath)
      Verify a module version and the BoxLang version are compatible.

      Rules: - If the major version is different, then we are not compatible, so throw an exception - If the minor/path version is different, then we are compatible, but we will log a warning

      Parameters:
      moduleVersion - The version of the module
      directoryPath - The directory path of the module
      Throws:
      BoxRuntimeException - If the module requires a different major version of BoxLang
    • buildRegistry

      public void buildRegistry()
      This method scans all possible module locations and builds the module registry of all modules found. This method doesn't activate the modules, it just registers them. Duplicate modules are not allowed, first one wins.
    • buildRegistryFromPath

      public void buildRegistryFromPath(Path modulePath)
      This method scans a single module path and builds the module registry
      Parameters:
      modulePath - The path to scan for modules