Class InitializersPluginLoader<T>
- Type Parameters:
T- the type of objects that this initializer will create or manage
- All Implemented Interfaces:
PluginLoader<Initializer<T>>
- Direct Known Subclasses:
LabyrinthPanelsPluginLoader
Initializer plugins of a specific type T.
This class uses the ServiceLoader mechanism to load plugins of type Initializer
for a specified type T, both from the system's service provider and from additional plugins
specified via the AddTo annotation. It ensures that plugins are loaded for a specific core type
provided during initialization.
The loader is capable of filtering plugins that are compatible with the type T and ensures
that plugins with the matching type are loaded into the system. The loader also logs information about
the loaded plugins using the SLF4J logging framework.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.LoggerLogger instance for logging plugin loading operations, errors, and status updates. -
Constructor Summary
ConstructorsConstructorDescriptionInitializersPluginLoader(@NotNull Class<T> initializerType, @NotNull Class<? extends Core> coreType) Constructs a newInitializersPluginLoaderfor the given initializer type and core type. -
Method Summary
Modifier and TypeMethodDescription@Nullable Initializer<T>Retrieves a specific initializer plugin by its unique class name.List<Initializer<T>>Returns the list of all currently loadedInitializerplugins.void
-
Field Details
-
log
public static final org.slf4j.Logger logLogger instance for logging plugin loading operations, errors, and status updates.This logger is used to record key events in the plugin loading lifecycle, including:
- The successful loading of
Initializerplugins, with their class names being logged as informational messages. - Errors related to plugin loading, such as when no plugins are available or when a specific plugin cannot be found by its class name.
The logger uses the SLF4J logging framework, allowing for flexible logging configurations, such as different logging levels (INFO, ERROR, etc.), output destinations, and formats. This makes it suitable for both development and production environments.
Example log outputs:
- Informational log when a plugin is successfully loaded: "Loaded class:
plugin-class-name" - Error log when no plugins are available: "No available plugins."
- Error log when a plugin is not found by its class name: "Plugin \"
plugin-class-name\" not found."
Using this log, developers can track which plugins are loaded, debug issues with missing plugins, and ensure that the plugin system operates as expected during runtime.
- The successful loading of
-
-
Constructor Details
-
InitializersPluginLoader
public InitializersPluginLoader(@NotNull @NotNull Class<T> initializerType, @NotNull @NotNull Class<? extends Core> coreType) Constructs a newInitializersPluginLoaderfor the given initializer type and core type.This constructor initializes the loader and automatically loads the plugins using the
loadPlugins()method.- Parameters:
initializerType- the type of initializer to loadcoreType- the core type to associate with the loader
-
-
Method Details
-
loadPlugins
public void loadPlugins()Loads all availableInitializerplugins 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>
-
getPlugins
Returns the list of all currently loadedInitializerplugins.- Specified by:
getPluginsin interfacePluginLoader<T>- Returns:
- a list of plugins of type
Initializer<T>
-
getPlugin
Retrieves a specific initializer 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>- Parameters:
id- the fully qualified class name of the initializer plugin to retrieve- Returns:
- the initializer plugin associated with the given class name, or
nullif not found
-