Package org.apache.log4j.plugins
Class PluginRegistry
java.lang.Object
org.apache.log4j.plugins.PluginRegistry
This 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 ClassesModifier and TypeClassDescriptionprivate classInternal class used to handle listener events from repositories. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PluginRegistry.RepositoryListenerthe listener used to listen for repository events.private final ListList of listeners.private final LoggerRepositoryExLogger repository.The pluginMap is keyed by plugin name and contains plugins as values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a plugin to the plugin registry.voidAdds 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.Get logger repository.Returns all the plugins for a given repository.getPlugins(Class pluginClass) Returns all the plugins for a given repository that are instances of a certain class.booleanpluginNameExists(String name) Returns true if the specified name is already taken by an existing Plugin registered within the scope of the specified LoggerRepository.voidRemoves a particular PluginListener from this registry such that it will no longer be notified of PluginEvents.voidStops all plugins in the given logger repository.stopPlugin(String pluginName) Stops a plugin by plugin name and repository.
-
Field Details
-
pluginMap
The pluginMap is keyed by plugin name and contains plugins as values. key=plugin.getName, value=plugin -
loggerRepository
Logger repository. -
listener
the listener used to listen for repository events. -
listenerList
List of listeners.
-
-
Constructor Details
-
PluginRegistry
Creates a new instance.- Parameters:
repository- logger repository.
-
-
Method Details
-
getLoggerRepository
Get logger repository.- Returns:
- logger repository.
-
pluginNameExists
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
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
Calls the pluginStarted method on every registered PluginListener.- Parameters:
plugin- The plugin that has been started.
-
firePluginStopped
Calls the pluginStopped method for every registered PluginListner.- Parameters:
plugin- The plugin that has been stopped.
-
getPlugins
Returns all the plugins for a given repository.- Returns:
- List list of plugins from the repository.
-
getPlugins
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
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
Adds a PluginListener to this registry to be notified of PluginEvents.- Parameters:
l- PluginListener to add to this registry
-
removePluginListener
Removes a particular PluginListener from this registry such that it will no longer be notified of PluginEvents.- Parameters:
l- PluginListener to remove
-