public class ServerPluginManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ServerPluginManager.PluginLoadFailCause
Possible cause why a plugin was not loaded.
|
static class |
ServerPluginManager.ServerPluginManagerState
The state the plugin manager is in: whether before initialization, currently registering plugins, initialized, or
resetting
|
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG
Signals if we run a debug session in an IDE like Eclipse.
|
static boolean |
IS_SERVLET_API
signals if the servlet API is available
|
Modifier | Constructor and Description |
---|---|
protected |
ServerPluginManager()
Create a instance of ServerPluginManager.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<T> |
get(java.lang.Class<T> interfaceClass)
Get a list of instances of the given extension type.
|
java.lang.String[] |
getAvailablePlugins()
Get the list of all available plugins in the plugin directory.
|
java.lang.String |
getCorePluginId()
Returns the id of the product core plugin that was provided to initialize the ServerPluginManager.
|
com.inet.plugin.ServerPluginDescription |
getCoreServerPluginDescription(java.lang.String coreID)
Get the core server plugin for recovery and process starter.
|
static ServerPluginManager |
getInstance()
Gets the current instance of the ServerPluginManager.
|
java.lang.String[] |
getLoadedPlugins()
Get the list of all loaded/running plugins.
|
T |
getOptionalInstance(java.lang.Class<T> interfaceClass)
Get a optional instance of a specific type.
|
com.inet.plugin.fs.ResourceFile |
getPluginDir()
Get the base plugin directory.
|
java.util.List<com.inet.plugin.fs.ResourceFile> |
getPluginDirs()
Get the locations from which plugins are loaded.
|
com.inet.plugin.fs.ResourceFile |
getPluginFile(java.lang.String id,
java.lang.String path)
Returns a
ResourceFile for a file which is contained in a plugin. |
java.lang.Object |
getPluginLoadError(java.lang.String id)
Get the cause because a plugin was not loaded.
|
T |
getSingleInstance(java.lang.Class<T> interfaceClass)
Get a single instance of a specific type.
|
T |
getSingleInstanceByName(java.lang.Class<T> interfaceClass,
java.lang.String instanceKey,
boolean useDefault)
Get a single instance of a certain type.
|
java.util.Properties |
getStartProperties()
Get the start properties.
|
ServerPluginManager.ServerPluginManagerState |
getState()
Get the current state of the manager
|
java.lang.Throwable |
getThrowable()
Get a throwable that occur on init of the plugin manager.
|
com.inet.plugin.fs.ResourceFile |
getTranslationsDir()
Get the directory where additional translations can be saved.
|
boolean |
isInitFinish()
If the init phase is complete.
|
boolean |
isPluginLoaded(java.lang.String id)
Check if a plugin was loaded and can used in other plugins for access to API of optional dependencies.
|
void |
register(java.lang.Class<T> interfaceClass,
T instance)
Register a instance as extension in the ServerPluginManager.
|
void |
setActived(java.util.Map<java.lang.String,java.lang.Boolean> activated)
Set the activated plugins.
|
void |
setCorePluginId(java.lang.String corePluginId)
Set the name of the core plugin id.
|
void |
setPluginDir(java.lang.String pluginDir)
Set the relative or absolute path of plugin directory which is to be searched for plugins
|
void |
setPluginDir(com.inet.plugin.fs.ResourceFile pluginDir)
Set the relative or absolute plugin directory which is to be searched for plugins.
|
void |
setPluginFilter(PluginFilter filter)
Set a plugin filter which filter the available plugins
|
void |
uninstall(com.inet.plugin.ServerPluginDescription core,
boolean isFullUninstall)
Executes uninstall tasks of available plugins.
|
void |
waitOnInitState(int seconds)
Wait the given count that the plugin manager will receive the state init.
|
public static final boolean DEBUG
public static final boolean IS_SERVLET_API
protected ServerPluginManager()
public static ServerPluginManager getInstance()
public void register(java.lang.Class<T> interfaceClass, T instance)
interfaceClass
- a class of type T, can not be null
instance
- a instance which T implements or extendsjava.lang.IllegalStateException
- if the State of the ServerPluginManager is ServerPluginManager.ServerPluginManagerState.INIT
java.lang.IllegalArgumentException
- is thrown if the interfaceClasse implements NamedExtension
and there
already is an extension of the same name registered@Nonnull public java.util.List<T> get(@Nonnull java.lang.Class<T> interfaceClass)
register(Class, Object)
interfaceClass
- a class of type T, can not be null
null
java.lang.IllegalStateException
- if the State of the ServerPluginManager is differ from
ServerPluginManager.ServerPluginManagerState.INIT
@Nonnull public T getSingleInstance(java.lang.Class<T> interfaceClass) throws java.lang.IllegalStateException
interfaceClass
- a class of type T, can not be null
java.lang.IllegalStateException
- if the State of the ServerPluginManager is differ from
ServerPluginManager.ServerPluginManagerState.INIT
or no instance or more as one instance of the needed type is registered@Nonnull public T getSingleInstanceByName(@Nonnull java.lang.Class<T> interfaceClass, @Nullable java.lang.String instanceKey, boolean useDefault) throws java.lang.IllegalStateException
interfaceClass
- a class of type T, can not be null
instanceKey
- the name of the instance to be selected, if null
the default (aka. first instance) will be returneduseDefault
- if true
a fall back to the default instance is allowed, in case of false
the user requires a certain instance. If no such instance is registered a IllegalStateException
will be thrownjava.lang.IllegalStateException
- if the State of the ServerPluginManager is not ServerPluginManager.ServerPluginManagerState.INIT
or if the requested instance/default could not be found@Nullable public T getOptionalInstance(java.lang.Class<T> interfaceClass) throws java.lang.IllegalStateException
interfaceClass
- a class of type T, can not be null
java.lang.IllegalStateException
- if the state of ServerPluginManager is not either
ServerPluginManager.ServerPluginManagerState.INIT
or ServerPluginManager.ServerPluginManagerState.RESET
or more than one instance of the needed type is registeredpublic java.lang.String getCorePluginId()
null
if not core plugin was provided.public void setCorePluginId(java.lang.String corePluginId) throws java.lang.IllegalStateException
corePluginId
- the new IDjava.lang.IllegalStateException
- if the state is already initpublic com.inet.plugin.fs.ResourceFile getPluginFile(java.lang.String id, java.lang.String path) throws java.io.IOException
ResourceFile
for a file which is contained in a plugin. This may cover files in the jar files
of a plugin as wellid
- the ID of the plugin to get a file ofpath
- the path into the plugin ZIP file or one of the plugin JAR filesnull
if there is no such plugin or filejava.io.IOException
- thrown if the ZIP or JAR cannot be accessedpublic boolean isPluginLoaded(java.lang.String id)
if( spm.isPluginLoaded( "reporting" ) ) {
new Runnable() { // anonymous class to decouple class loading
public void run() {
...
}
}.run();
}
id
- the plugin IDpublic java.lang.Object getPluginLoadError(java.lang.String id)
id
- the plugin IDpublic java.lang.String[] getLoadedPlugins()
isPluginLoaded(String)
public java.lang.String[] getAvailablePlugins()
public void setPluginDir(java.lang.String pluginDir)
pluginDir
- the path of the plugin directory, can not be null
.java.lang.IllegalStateException
- if the state is already initpublic void setPluginDir(com.inet.plugin.fs.ResourceFile pluginDir)
pluginDir
- the path of the plugin directory, can not be null
.java.lang.IllegalStateException
- if the state is already initpublic com.inet.plugin.fs.ResourceFile getPluginDir()
@Nonnull public java.util.List<com.inet.plugin.fs.ResourceFile> getPluginDirs()
@Nonnull public com.inet.plugin.fs.ResourceFile getTranslationsDir()
public void setPluginFilter(PluginFilter filter)
filter
- the new filterpublic void setActived(java.util.Map<java.lang.String,java.lang.Boolean> activated)
activated
- a map of plugin id to a boolean flagpublic ServerPluginManager.ServerPluginManagerState getState()
public boolean isInitFinish()
public void waitOnInitState(int seconds)
seconds
- time in seconds to waitpublic java.lang.Throwable getThrowable()
@Nonnull public java.util.Properties getStartProperties()
public void uninstall(com.inet.plugin.ServerPluginDescription core, boolean isFullUninstall)
core
- description of a optional core plugin (may be null).isFullUninstall
- whether a full uninstall must be performed.java.lang.IllegalStateException
- if ServerPluginManager's state is not PRE_INIT
.@Nullable public com.inet.plugin.ServerPluginDescription getCoreServerPluginDescription(@Nullable java.lang.String coreID) throws java.lang.Exception
coreID
- optional/possible ID of a core plugin. This is only a hint.java.lang.Exception
- if any error occur on loading the pluginjava.lang.IllegalStateException
- if call after init the plugin managerCopyright © 1999-2020 by i-net software GmbH