Class DriverModule

java.lang.Object
eu.cloudnetservice.driver.module.DefaultModule
eu.cloudnetservice.driver.module.driver.DriverModule
All Implemented Interfaces:
Named, Module

public class DriverModule extends DefaultModule
Represents a cloudnet driver specific implementation for the module. Usually this should be used as entry point of a module.
Since:
4.0
See Also:
  • Field Details

    • CONFIG_BINDING_KEY

      private static final dev.derklaro.aerogel.binding.key.BindingKey<Path> CONFIG_BINDING_KEY
  • Constructor Details

    • DriverModule

      public DriverModule()
  • Method Details

    • readConfig

      Reads the configuration file of this module from the default or overridden configuration path (via module.json) into a json document, throwing an exception when the document is invalid.
      Parameters:
      factory - the config factory to use when parsing the configuration.
      Returns:
      the config at the default path.
      Throws:
      DocumentParseException - if the document cannot be parsed from the given path.
    • writeConfig

      public void writeConfig(@NonNull @NonNull Document config)
      Writes the given configuration document to the default configuration path configPath().
      Parameters:
      config - the config to write.
    • readConfig

      @NonNull public <T> T readConfig(@NonNull @NonNull Class<T> configModelType, @NonNull @NonNull Supplier<T> defaultConfigFactory, @NonNull @NonNull DocumentFactory documentFactory)
      Reads the config of this module to the given model type, creating a new configuration if necessary. This method rethrows the parsing exception wrapped if the reader was unable to read the config model (for example an exception happens during the model instantiation with the supplied arguments by the user in the configuration).

      The config factory is allowed to return null, an empty json object will be written to the file in that case.

      Type Parameters:
      T - the type of the configuration model.
      Parameters:
      configModelType - the modeling class of the configuration.
      defaultConfigFactory - a factory constructing a default config instance if needed.
      documentFactory - the document factory to use when reading the configuration file.
      Returns:
      a newly created default config instance or the read config instance from the config path.
      Throws:
      NullPointerException - if either the given config model or config factory is null.
      ModuleConfigurationInvalidException - if the reader is unable to read the configuration model from the file.
    • readConfigAndInstantiate

      @NonNull public <C,T> T readConfigAndInstantiate(@NonNull @NonNull InjectionLayer<?> injectionLayer, @NonNull @NonNull Class<C> configModelType, @NonNull @NonNull Supplier<C> defaultConfigFactory, @NonNull @NonNull Class<T> classToInstantiate, @NonNull @NonNull DocumentFactory documentFactory)
      Reads the module configuration file and converts the type of the configuration to the given model type, creating the configuration if necessary. Any exceptions thrown when reading the configuration are forwarded to the caller.

      Then the given class type is instantiated with the loaded config and config path being known while creating the class instance. Bindings are respected by this method.

      If further customization of the injection context which is taking over the injection process is needed, the method readConfigAndInstantiate(InjectionLayer, Class, Supplier, Class, UnaryOperator, DocumentFactory) is able to allow for further customization of the class injection context (for example needed if other non-constructable types are required to instantiate the binding of the given type).

      Type Parameters:
      C - the type of the configuration model.
      T - the type modeling the class which should be instantiated.
      Parameters:
      injectionLayer - the injection layer to use when instantiating the given type to instantiate.
      configModelType - the modeling class of the configuration.
      defaultConfigFactory - a factory constructing a default config instance if needed.
      classToInstantiate - the class to instantiate after successfully loading the configuration.
      documentFactory - the document factory to use when reading the configuration file.
      Returns:
      the constructed instance of the given type, constructed with the configuration known to the context.
      Throws:
      NullPointerException - if one of the given parameters is null.
      ModuleConfigurationInvalidException - if the reader is unable to read the configuration from the file.
    • readConfigAndInstantiate

      @NonNull public <C,T> T readConfigAndInstantiate(@NonNull @NonNull InjectionLayer<?> injectionLayer, @NonNull @NonNull Class<C> configModelType, @NonNull @NonNull Supplier<C> defaultConfigFactory, @NonNull @NonNull Class<T> classToInstantiate, @NonNull @NonNull UnaryOperator<dev.derklaro.aerogel.InjectionRequest<T>> decorator, @NonNull @NonNull DocumentFactory documentFactory)
      Reads the module configuration file and converts the type of the configuration to the given model type, creating the configuration if necessary. Any exceptions thrown when reading the configuration are forwarded to the caller.

      Afterwards the given class type is instantiated with the loaded config and config path being known while creating the class instance. Bindings are respected by this method.

      If further customization of the injection context which is taking over the injection process is needed, the builder consumer passed to this method will be called after the overrides for the config type and config path were installed to it. This means that the decorator is able to override the previously installed overrides in the given builder.

      Type Parameters:
      C - the type of the configuration model.
      T - the type modeling the class which should be instantiated.
      Parameters:
      injectionLayer - the injection layer to use when instantiating the given type to instantiate.
      configModelType - the modeling class of the configuration.
      defaultConfigFactory - a factory constructing a default config instance if needed.
      classToInstantiate - the class to instantiate after successfully loading the configuration.
      decorator - the decorator to apply to the injection context builder, for further customization.
      documentFactory - the document factory to use when reading the configuration file.
      Returns:
      the constructed instance of the given type, constructed with the configuration known to the context.
      Throws:
      NullPointerException - if one of the given parameters is null.
      ModuleConfigurationInvalidException - if the reader is unable to read the configuration from the file.
    • configPath

      @NonNull public @NonNull Path configPath()
      The default configuration path located in the directory for this module. By default, this is "Module-Name/config.json".
      Returns:
      the path of the config.
      See Also: