Klasse ServerPluginManager
java.lang.Object
com.inet.plugin.ServerPluginManager
The ServerPluginManager is the central point in the server for the plugin framework. It detects the installed plugins
and initializes them. Additionally, there are methods for registering and querying extensions.
- Seit:
- inetcore 1.0
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifikator und TypKlasseBeschreibungstatic enumPossible cause why a plugin was not loaded.static enumThe state the plugin manager is in: whether before initialization, currently registering plugins, initialized, or resetting -
Feldübersicht
FelderModifikator und TypFeldBeschreibungstatic final booleanSignals if we run a debug session in an IDE like Eclipse.static final booleansignals if the servlet API is available -
Konstruktorübersicht
KonstruktorenModifikatorKonstruktorBeschreibungprotectedCreate a instance of ServerPluginManager. -
Methodenübersicht
Modifikator und TypMethodeBeschreibungbooleanaddExtractedPlugin(@Nonnull String className) Add an extracted plugin that can be load from system/base classloader.protected @Nullable com.inet.plugin.ServerPluginDescriptionfindCoreServerPluginDescriptionWithoutLoadingForServerStart(@Nullable String coreID, @Nonnull com.inet.logging.Logger logger) FOR INTERNAL USE ONLY Get the core server plugin description without loading for the testing framework.<T> @Nonnull List<T> Get a new modifiable list of instances of the given extension type.String[]Get the list of all available plugins in the plugin directory.Returns the id of the product core plugin that was provided to initialize the ServerPluginManager.static @Nonnull StringFOR INTERNAL USE ONLY Get additional diagnostic information for the case of fatal error:static ServerPluginManagerGets the current instance of the ServerPluginManager.String[]Get the list of all loaded/running plugins.<T> @Nullable TgetOptionalInstance(Class<T> interfaceClass) Get a optional instance of a specific type.com.inet.plugin.ServerPluginDescriptionFOR INTERNAL USE ONLY Get the description of a plugin or nullcom.inet.plugin.fs.ResourceFileGet the base plugin directory.@Nonnull List<com.inet.plugin.fs.ResourceFile> Get the locations from which plugins are loaded.com.inet.plugin.fs.ResourceFilegetPluginFile(String id, String path) Returns aResourceFilefor a file which is contained in a plugin.@Nullable PluginFilterReturn a plugin filter which filter the available pluginsGet the cause because a plugin was not loaded.<T> @Nonnull TgetSingleInstance(Class<T> interfaceClass) Get a single instance of a specific type.<T extends NamedExtension>
@Nonnull TgetSingleInstanceByName(@Nonnull Class<? super T> interfaceClass, @Nullable String instanceKey, boolean useDefault) Get a single instance of a certain type.@Nonnull PropertiesGet the start properties.getState()Get the current state of the managerFOR INTERNAL USE ONLY Get the temp directory and clear it from old files.Get a throwable that occur on init of the plugin manager.@Nonnull com.inet.plugin.fs.ResourceFileGet the directory where additional translations can be saved.voidinit(@Nullable com.inet.plugin.ServerPluginDescription core) Veraltet.voidinit(@Nullable com.inet.plugin.ServerPluginDescription... plugins) FOR INTERNAL USE ONLY Initialize the ServerPluginManager and start the live cycle of the plugins. there is no check.voidVeraltet.booleanIf the init phase is complete.booleanisPluginLoaded(String id) Check if a plugin was loaded and can used in other plugins for access to API of optional dependencies.@Nullable com.inet.plugin.ServerPluginDescriptionloadCoreServerPluginDescriptionForServerStart(@Nullable String coreID) Get the core server plugin for recovery and process starter.loadDirectory(com.inet.plugin.fs.ResourceFile pluginsDir) FOR INTERNAL USE ONLY Durchgang #1 : plugins erst mal initial einlesenreadPluginsFromDirectory(com.inet.plugin.fs.ResourceFile[] archives) FOR INTERNAL USE ONLY Extrahiert die Plugin-Archive und erzeugt die Plugin-Beschreibungen.<T> voidRegister a instance as extension in the ServerPluginManager.voidreset()FOR INTERNAL USE ONLY Reset the ServerPluginManager after a server stop.voidrunIfPluginLoaded(String id, Supplier<com.inet.plugin.Executable> pluginRegisterSupplier) Runs the plugin register supplier when the plugin with the given id is loaded
and the caller was load from the DependencyClassLoader.
This code can be used in the register phase of a plugin to ensure that code of
optional plugins is only used executed, if available.voidsetActived(Map<String, Boolean> activated) Set the activated plugins.voidsetCorePluginId(String corePluginId) Set the name of the core plugin id.voidsetPluginDir(com.inet.plugin.fs.ResourceFile pluginDir) Set the relative or absolute plugin directory which is to be searched for plugins.voidsetPluginDir(String pluginDir) Set the relative or absolute path of plugin directory which is to be searched for pluginsvoidsetPluginFilter(PluginFilter filter) Set a plugin filter which filter the available pluginsvoidsetPluginLoadError(String id, Throwable th) Set the cause because a plugin was not loaded.voiduninstall(com.inet.plugin.ServerPluginDescription core, boolean isFullUninstall) Executes uninstall tasks of available plugins.voidwaitOnInitState(int seconds) Wait the given count that the plugin manager will receive the state init.
-
Felddetails
-
DEBUG
public static final boolean DEBUGSignals if we run a debug session in an IDE like Eclipse. -
IS_SERVLET_API
public static final boolean IS_SERVLET_APIsignals if the servlet API is available
-
-
Konstruktordetails
-
ServerPluginManager
protected ServerPluginManager()Create a instance of ServerPluginManager.- Seit:
- inetcore 1.0
-
-
Methodendetails
-
getInstance
Gets the current instance of the ServerPluginManager. If one does not exist then it will be created.- Gibt zurück:
- Singleton instance of the manager
- Seit:
- inetcore 1.0
-
reset
public void reset()FOR INTERNAL USE ONLY Reset the ServerPluginManager after a server stop. All loaded plugins are reset.- Seit:
- inetcore 1.0
-
register
Register a instance as extension in the ServerPluginManager.- Typparameter:
T- a interface or a class (preferred abstract)- Parameter:
interfaceClass- a class of type T, can not benullinstance- a instance which T implements or extends- Löst aus:
IllegalStateException- if the State of the ServerPluginManager isServerPluginManager.ServerPluginManagerState.INITIllegalArgumentException- is thrown if the interfaceClasse implementsNamedExtensionand there already is an extension of the same name registered- Seit:
- inetcore 1.0
-
get
Get a new modifiable list of instances of the given extension type. The extensions need to be registered before withregister(Class, Object)- Typparameter:
T- a interface or a class (preferred abstract)- Parameter:
interfaceClass- a class of type T, can not benull- Gibt zurück:
- a list of instances. can be empty but not
null - Löst aus:
IllegalStateException- if the State of the ServerPluginManager is differ fromServerPluginManager.ServerPluginManagerState.INIT- Seit:
- inetcore 1.0
-
getSingleInstance
Get a single instance of a specific type.- Typparameter:
T- a interface or a class (preferred abstract)- Parameter:
interfaceClass- a class of type T, can not benull- Gibt zurück:
- a single instance of type T
- Löst aus:
IllegalStateException- if the State of the ServerPluginManager is differ fromServerPluginManager.ServerPluginManagerState.INITor no instance or more as one instance of the needed type is registered- Seit:
- inetcore 1.0
-
getSingleInstanceByName
public <T extends NamedExtension> @Nonnull T getSingleInstanceByName(@Nonnull Class<? super T> interfaceClass, @Nullable String instanceKey, boolean useDefault) throws IllegalStateException Get a single instance of a certain type. The instance can be selected using it's extension name. If no name is set or there is no instance of such name, the default instance may be returned. The default is defined as the first instance that was registered for the a type.- Typparameter:
T- a interface or a class (preferably abstract)- Parameter:
interfaceClass- a class of type T, can not benullinstanceKey- the name of the instance to be selected, ifnullthe default (aka. first instance) will be returneduseDefault- iftruea fall back to the default instance is allowed, in case offalsethe user requires a certain instance. If no such instance is registered aIllegalStateExceptionwill be thrown- Gibt zurück:
- a single instance of type T
- Löst aus:
IllegalStateException- if the State of the ServerPluginManager is notServerPluginManager.ServerPluginManagerState.INITor if the requested instance/default could not be found- Seit:
- inetcore 3.0
-
getOptionalInstance
Get a optional instance of a specific type.- Typparameter:
T- a interface or a class (preferred abstract)- Parameter:
interfaceClass- a class of type T, can not benull- Gibt zurück:
- a optional instance of type T or null
- Löst aus:
IllegalStateException- if the state of ServerPluginManager is not eitherServerPluginManager.ServerPluginManagerState.INITorServerPluginManager.ServerPluginManagerState.RESETor more than one instance of the needed type is registered- Seit:
- inetcore 2.0
-
addExtractedPlugin
Add an extracted plugin that can be load from system/base classloader. It is loaded with:
The plugin must have anClass.forName( className );PluginInfoannotation as replacement for the plugin.properties. This method must be called before the initialize phase of the manager. The register and and init phase of the plugin will be invoked and own extensions can be registered. This method is not thread safe.- Parameter:
className- the class name of the plugin- Gibt zurück:
- true, if the plugin was added; false, if any error occurred, see the log for details
- Seit:
- 23.10
-
init
Veraltet.FOR INTERNAL USE ONLY Initialize the ServerPluginManager and start the live cycle of the plugins. there is no check.- Parameter:
core- description of an optional core plugin- Löst aus:
IllegalStateException- if the State of the ServerPluginManager isServerPluginManager.ServerPluginManagerState.INIT- Seit:
- inetcore 3.1
-
init
public void init(@Nullable com.inet.plugin.ServerPluginDescription... plugins) FOR INTERNAL USE ONLY Initialize the ServerPluginManager and start the live cycle of the plugins. there is no check.- Parameter:
plugins- optional descriptions of plugins, the first is used as core plugin- Löst aus:
IllegalStateException- if the State of the ServerPluginManager isServerPluginManager.ServerPluginManagerState.INIT- Seit:
- inetcore 24.4
-
init
Veraltet.FOR INTERNAL USE ONLY Initialize the ServerPluginManager and start the live cycle of the plugins. there is no check.- Parameter:
corePluginId- the ID of an optional core plugin- Löst aus:
IllegalStateException- if the State of the ServerPluginManager isServerPluginManager.ServerPluginManagerState.INIT- Seit:
- inetcore 5.1
-
getCorePluginId
Returns the id of the product core plugin that was provided to initialize the ServerPluginManager.- Gibt zurück:
- the id of the plugin. Can be
nullif not core plugin was provided. - Seit:
- inetcore 1.1
-
setCorePluginId
Set the name of the core plugin id. This can be set only once.- Parameter:
corePluginId- the new ID- Löst aus:
IllegalStateException- if the state is already init- Seit:
- inetcore 5.1
-
getTempDir
FOR INTERNAL USE ONLY Get the temp directory and clear it from old files.- Gibt zurück:
- the directory
-
readPluginsFromDirectory
protected Map<String, com.inet.plugin.ServerPluginDescription> readPluginsFromDirectory(com.inet.plugin.fs.ResourceFile[] archives) FOR INTERNAL USE ONLY Extrahiert die Plugin-Archive und erzeugt die Plugin-Beschreibungen.- Parameter:
archives- eine Liste mit den gefundenen Plugin-Archiven- Gibt zurück:
- Map mit Plugin-ID und Plugin-Beschreibung aller gefundenen Plugins
-
loadDirectory
protected Map<String, com.inet.plugin.ServerPluginDescription> loadDirectory(com.inet.plugin.fs.ResourceFile pluginsDir) FOR INTERNAL USE ONLY Durchgang #1 : plugins erst mal initial einlesen- Parameter:
pluginsDir- Verzeichnis der Plugins- Gibt zurück:
- eine Map mit allen gefundenen Plugins, Key ist deren ID, nie
null
-
getPluginFile
Returns aResourceFilefor a file which is contained in a plugin. This may cover files in the jar files of a plugin as well. Note: you can not use it for directories!- Parameter:
id- the ID of the plugin to get a file ofpath- the path into the plugin ZIP file or one of the plugin JAR files- Gibt zurück:
- the requested file, may be
nullif there is no such plugin or file - Löst aus:
IOException- thrown if the ZIP or JAR cannot be accessed- Seit:
- inetcore 1.0
-
isPluginLoaded
Check if a plugin was loaded and can used in other plugins for access to API of optional dependencies. Do not access to the API of an optional plugin in an IF block or inside a lambda expression. Use an extra class or anonymous class to decouple class loading. For example:if( spm.isPluginLoaded( "reporting" ) ) { new Runnable() { // anonymous class to decouple class loading public void run() { ... } }.run(); }- Parameter:
id- the plugin ID- Gibt zurück:
- true, if the plugin is available and loaded.
- Seit:
- inetcore 1.1
-
runIfPluginLoaded
public void runIfPluginLoaded(String id, Supplier<com.inet.plugin.Executable> pluginRegisterSupplier) Runs the plugin register supplier when the plugin with the given id is loaded
and the caller was load from the DependencyClassLoader.
This code can be used in the register phase of a plugin to ensure that code of
optional plugins is only used executed, if available. It ensures the decoupling
of class loading.spm.runIfPluginLoaded( "reporting", () -> new Executable() { public void execute() { ... } } );- Parameter:
id- the plugin IDpluginRegisterSupplier- the subblier to return a PluginRegister instance, the run method will be called of.- Seit:
- inetcore 21.10
-
getPluginLoadError
-
setPluginLoadError
-
getLoadedPlugins
Get the list of all loaded/running plugins. This method can be called in the register and init phase (and later). In the pre_init phase it will return only an empty result.- Gibt zurück:
- a list of IDs from loaded plugins
- Seit:
- inetcore 1.0
- Siehe auch:
-
getAvailablePlugins
Get the list of all available plugins in the plugin directory.- Gibt zurück:
- a list of IDs from all plugins
- Seit:
- inetcore 1.0
-
setPluginDir
Set the relative or absolute path of plugin directory which is to be searched for plugins- Parameter:
pluginDir- the path of the plugin directory, can not benull.- Löst aus:
IllegalStateException- if the state is already init- Seit:
- inetcore 1.0
-
setPluginDir
public void setPluginDir(com.inet.plugin.fs.ResourceFile pluginDir) Set the relative or absolute plugin directory which is to be searched for plugins. Can be set only once.- Parameter:
pluginDir- the path of the plugin directory, can not benull.- Löst aus:
IllegalStateException- if the state is already init- Seit:
- inetcore 1.0
-
getPluginDir
public com.inet.plugin.fs.ResourceFile getPluginDir()Get the base plugin directory. If not set then it returns the "plugins" path relative to the application base.- Gibt zurück:
- the plugin dir
- Seit:
- inetcore 5.2
-
getPluginDirs
Get the locations from which plugins are loaded. The list returns at minimum one element. If the core plugin is set and this is a file persistence there can be an additional directory.- Gibt zurück:
- the directories
- Seit:
- inetcore 5.2
-
getTranslationsDir
public @Nonnull com.inet.plugin.fs.ResourceFile getTranslationsDir()Get the directory where additional translations can be saved.- Gibt zurück:
- the custom translation directory
- Seit:
- inetcore 5.2
-
setPluginFilter
Set a plugin filter which filter the available plugins- Parameter:
filter- the new filter- Seit:
- inetcore 2.0
-
getPluginFilter
Return a plugin filter which filter the available plugins- Gibt zurück:
- the new filter, null for no filter
- Seit:
- inetcore 21.10
-
setActived
-
getState
Get the current state of the manager- Gibt zurück:
- the state
- Seit:
- inetcore 1.0
-
isInitFinish
public boolean isInitFinish()If the init phase is complete.- Gibt zurück:
- return true
- Seit:
- 20.4
-
waitOnInitState
public void waitOnInitState(int seconds) Wait the given count that the plugin manager will receive the state init. This can only called from asynchrony background threads.- Parameter:
seconds- time in seconds to wait- Seit:
- inetcore 5.1
-
getThrowable
Get a throwable that occur on init of the plugin manager.- Gibt zurück:
- a throwable or null if no fatal error occur.
- Seit:
- inetcore 2.0
-
getPluginDescription
FOR INTERNAL USE ONLY Get the description of a plugin or null- Parameter:
id- of the plugin- Gibt zurück:
- description of the plugin or null
- Seit:
- inetcore 1.1
-
getStartProperties
Get the start properties. A plugin can vary its behavier depending on this properties.- Gibt zurück:
- the start properties.
- Seit:
- inetcore 2.0
-
uninstall
public void uninstall(com.inet.plugin.ServerPluginDescription core, boolean isFullUninstall) Executes uninstall tasks of available plugins. In case of problems with loading plugin, its task execution will be skipped and process will continue.- Parameter:
core- description of a optional core plugin (may be null).isFullUninstall- whether a full uninstall must be performed.- Löst aus:
IllegalStateException- if ServerPluginManager's state is notPRE_INIT.- Seit:
- inetcore 2.2
-
findCoreServerPluginDescriptionWithoutLoadingForServerStart
protected @Nullable com.inet.plugin.ServerPluginDescription findCoreServerPluginDescriptionWithoutLoadingForServerStart(@Nullable String coreID, @Nonnull com.inet.logging.Logger logger) throws Exception FOR INTERNAL USE ONLY Get the core server plugin description without loading for the testing framework.- Parameter:
coreID- optional/possible ID of a core plugin. This is only a hint.logger- the logger- Gibt zurück:
- the plugin or null if not found.
- Löst aus:
Exception- if any error occur on loading the pluginIllegalStateException- if call after init the plugin manager- Seit:
- 20.4
-
loadCoreServerPluginDescriptionForServerStart
public @Nullable com.inet.plugin.ServerPluginDescription loadCoreServerPluginDescriptionForServerStart(@Nullable String coreID) throws Exception Get the core server plugin for recovery and process starter. If find then this plugin is used for the launcher.- Parameter:
coreID- optional/possible ID of a core plugin. This is only a hint.- Gibt zurück:
- the plugin or null if not found.
- Löst aus:
Exception- if any error occur on loading the pluginIllegalStateException- if call after init the plugin manager- Seit:
- 20.4
-
getDiagnostic
FOR INTERNAL USE ONLY Get additional diagnostic information for the case of fatal error:- Gibt zurück:
- a string starting with newline
- Seit:
- 21.4
-