Class DefaultPluginLoader<T extends Loadable>
- Type Parameters:
T- the type of plugin that this loader manages, extendingLoadable
- All Implemented Interfaces:
PluginLoader<T>
- Direct Known Subclasses:
ExecutablesPluginLoader,WallStatesPluginLoader
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
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.LoggerLogger instance for logging plugin loading operations and errors. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultPluginLoader(@NotNull Class<T> type, @NotNull Class<? extends Core> core) Constructs a newDefaultPluginLoaderfor the given plugin type and core type. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves a specific plugin by its unique class name.Returns the list of all currently loaded plugins.voidLoads all available plugins of typeTusing theServiceLoadermechanism.
-
Field Details
-
log
public static final org.slf4j.Logger logLogger 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 newDefaultPluginLoaderfor 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 loadcore- the core type to associate with the loader
-
-
Method Details
-
loadPlugins
public void loadPlugins()Loads all available plugins of typeTusing theServiceLoadermechanism.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
AddToannotation 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:
loadPluginsin interfacePluginLoader<T extends Loadable>
-
getPlugins
Returns the list of all currently loaded plugins.- Specified by:
getPluginsin interfacePluginLoader<T extends Loadable>- Returns:
- a list of plugins of type
T
-
getPlugin
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:
getPluginin interfacePluginLoader<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
nullif not found
-