Class DefaultPluginLoader<T extends Loadable>

java.lang.Object
net.regsirius06.engine.plugins.loaders.DefaultPluginLoader<T>
Type Parameters:
T - the type of plugin that this loader manages, extending Loadable
All Implemented Interfaces:
PluginLoader<T>
Direct Known Subclasses:
ExecutablesPluginLoader, WallStatesPluginLoader

public abstract class DefaultPluginLoader<T extends Loadable> extends Object implements PluginLoader<T>
A default implementation of the PluginLoader interface that provides basic plugin loading functionality for plugins of type Loadable.

This class loads plugins of a specific type using the ServiceLoader mechanism, both from the system's service provider and from additional plugins specified via the AddTo annotation. It also manages the list of loaded plugins and provides access to them by their unique class name.

The loader ensures that plugins are loaded for a specific core type, which is provided as a parameter during initialization. This class also logs relevant information during the plugin loading process using the SLF4J logging framework.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.slf4j.Logger
    Logger instance for logging plugin loading operations and errors.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultPluginLoader(@NotNull Class<T> type, @NotNull Class<? extends Core> core)
    Constructs a new DefaultPluginLoader for the given plugin type and core type.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves a specific plugin by its unique class name.
    Returns the list of all currently loaded plugins.
    void
    Loads all available plugins of type T using the ServiceLoader mechanism.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      public static final org.slf4j.Logger log
      Logger instance for logging plugin loading operations and errors.

      This field uses the SLF4J logging framework to record important events during the plugin loading process. It logs information about successfully loaded plugins as well as error messages when something goes wrong, such as when no plugins are found or a specific plugin cannot be retrieved.

      The log is used throughout the plugin loading lifecycle to provide visibility into which plugins were successfully loaded and whether any issues occurred.

      The log messages can be accessed for debugging or monitoring purposes and can be configured with different logging levels (e.g., INFO, ERROR, WARN) depending on the situation.

  • Constructor Details

    • DefaultPluginLoader

      public DefaultPluginLoader(@NotNull @NotNull Class<T> type, @NotNull @NotNull Class<? extends Core> core)
      Constructs a new DefaultPluginLoader for the given plugin type and core type.

      This constructor initializes the loader and automatically loads the plugins using the loadPlugins() method.

      Parameters:
      type - the type of plugin to load
      core - the core type to associate with the loader
  • Method Details

    • loadPlugins

      public void loadPlugins()
      Loads all available plugins of type T using the ServiceLoader mechanism.

      This method first clears any previously loaded plugins, then loads plugins from the service provider configured for the core type. It also loads plugins that are marked with the AddTo annotation and belong to the same core as the current plugin type.

      After loading, the method logs the names of the loaded plugin classes using SLF4J.

      Specified by:
      loadPlugins in interface PluginLoader<T extends Loadable>
    • getPlugins

      public List<T> getPlugins()
      Returns the list of all currently loaded plugins.
      Specified by:
      getPlugins in interface PluginLoader<T extends Loadable>
      Returns:
      a list of plugins of type T
    • getPlugin

      @Nullable public T getPlugin(String id)
      Retrieves a specific plugin by its unique class name.

      The plugin is identified by its fully qualified class name, which is usually obtained via Class.getName().

      Specified by:
      getPlugin in interface PluginLoader<T extends Loadable>
      Parameters:
      id - the fully qualified class name of the plugin to retrieve
      Returns:
      the plugin associated with the given class name, or null if not found