Class PluginRegistry
- java.lang.Object
-
- org.apache.log4j.component.plugins.PluginRegistry
-
public final class PluginRegistry extends java.lang.ObjectThis is a registry for Plugin instances. It provides methods to start and stop plugin objects individually and to stop all plugins for a repository.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPluginRegistry.RepositoryListenerInternal class used to handle listener events from repositories.
-
Field Summary
Fields Modifier and Type Field Description private PluginRegistry.RepositoryListenerlistenerthe listener used to listen for repository events.private java.util.ListlistenerListList of listeners.private LoggerRepositoryExloggerRepositoryLogger repository.private java.util.MappluginMapThe pluginMap is keyed by plugin name and contains plugins as values.
-
Constructor Summary
Constructors Constructor Description PluginRegistry(LoggerRepositoryEx repository)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPlugin(Plugin plugin)Adds a plugin to the plugin registry.voidaddPluginListener(PluginListener l)Adds a PluginListener to this registry to be notified of PluginEvents.private voidfirePluginStarted(Plugin plugin)Calls the pluginStarted method on every registered PluginListener.private voidfirePluginStopped(Plugin plugin)Calls the pluginStopped method for every registered PluginListner.LoggerRepositoryExgetLoggerRepository()Get logger repository.java.util.ListgetPlugins()Returns all the plugins for a given repository.java.util.ListgetPlugins(java.lang.Class pluginClass)Returns all the plugins for a given repository that are instances of a certain class.booleanpluginNameExists(java.lang.String name)Returns true if the specified name is already taken by an existing Plugin registered within the scope of the specified LoggerRepository.voidremovePluginListener(PluginListener l)Removes a particular PluginListener from this registry such that it will no longer be notified of PluginEvents.voidstopAllPlugins()Stops all plugins in the given logger repository.PluginstopPlugin(java.lang.String pluginName)Stops a plugin by plugin name and repository.
-
-
-
Field Detail
-
pluginMap
private final java.util.Map pluginMap
The pluginMap is keyed by plugin name and contains plugins as values. key=plugin.getName, value=plugin
-
loggerRepository
private final LoggerRepositoryEx loggerRepository
Logger repository.
-
listener
private final PluginRegistry.RepositoryListener listener
the listener used to listen for repository events.
-
listenerList
private final java.util.List listenerList
List of listeners.
-
-
Constructor Detail
-
PluginRegistry
public PluginRegistry(LoggerRepositoryEx repository)
Creates a new instance.- Parameters:
repository- logger repository.
-
-
Method Detail
-
getLoggerRepository
public LoggerRepositoryEx getLoggerRepository()
Get logger repository.- Returns:
- logger repository.
-
pluginNameExists
public boolean pluginNameExists(java.lang.String name)
Returns true if the specified name is already taken by an existing Plugin registered within the scope of the specified LoggerRepository.- Parameters:
name- The name to check the repository for- Returns:
- true if the name is already in use, otherwise false
-
addPlugin
public void addPlugin(Plugin plugin)
Adds a plugin to the plugin registry. If a plugin with the same name exists already, it is shutdown and removed.- Parameters:
plugin- the plugin to add.
-
firePluginStarted
private void firePluginStarted(Plugin plugin)
Calls the pluginStarted method on every registered PluginListener.- Parameters:
plugin- The plugin that has been started.
-
firePluginStopped
private void firePluginStopped(Plugin plugin)
Calls the pluginStopped method for every registered PluginListner.- Parameters:
plugin- The plugin that has been stopped.
-
getPlugins
public java.util.List getPlugins()
Returns all the plugins for a given repository.- Returns:
- List list of plugins from the repository.
-
getPlugins
public java.util.List getPlugins(java.lang.Class pluginClass)
Returns all the plugins for a given repository that are instances of a certain class.- Parameters:
pluginClass- the class the plugin must implement to be selected.- Returns:
- List list of plugins from the repository.
-
stopPlugin
public Plugin stopPlugin(java.lang.String pluginName)
Stops a plugin by plugin name and repository.- Parameters:
pluginName- the name of the plugin to stop.- Returns:
- Plugin the plugin, if stopped, or null if the the plugin was not found in the registry.
-
stopAllPlugins
public void stopAllPlugins()
Stops all plugins in the given logger repository.
-
addPluginListener
public void addPluginListener(PluginListener l)
Adds a PluginListener to this registry to be notified of PluginEvents.- Parameters:
l- PluginListener to add to this registry
-
removePluginListener
public void removePluginListener(PluginListener l)
Removes a particular PluginListener from this registry such that it will no longer be notified of PluginEvents.- Parameters:
l- PluginListener to remove
-
-