mwomack 2003/02/02 23:50:09 Modified: src/java/org/apache/log4j/plugins Receiver.java PluginSkeleton.java PluginRegistry.java Plugin.java Log: Cleanup. Revision Changes Path 1.2 +3 -7 jakarta-log4j/src/java/org/apache/log4j/plugins/Receiver.java Index: Receiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/Receiver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Receiver.java 11 Dec 2002 07:25:14 -0000 1.1 +++ Receiver.java 3 Feb 2003 07:50:08 -0000 1.2 @@ -17,7 +17,7 @@ environment (to files, to smtp, to sockets, etc), Receivers bring logging events inside the log4j environment. - <p>Receivers are primarily meant to support the receiving of + <p>Receivers are meant to support the receiving of remote logging events from another process. For example, SocketAppender "appends" a logging event to a socket, configured for a specific host and port number. On the receiving side of @@ -32,9 +32,7 @@ logging packages into the log4j environment. <p>Receivers can be configured to post events to a given - LoggerRepository. If a repository is not specified, then the - default repository value returned by - LogManager.getLoggerRepository() should be used. + LoggerRepository. <p>Subclasses of Receiver must implement the isActive(), activateOptions(), and shutdown() methods. The doPost() method @@ -42,6 +40,7 @@ the repository. @author Mark Womack + @author Ceki Gülcü @since 1.3 */ public abstract class Receiver extends PluginSkeleton { @@ -57,9 +56,6 @@ // if the logger level is greater or equal to the level // of the event, use the logger to append the event. if(event.getLevel().isGreaterOrEqual(localLogger.getEffectiveLevel())) { - // set the logger for the event - // event.logger = localLogger; - // call the loggers appenders to process the event localLogger.callAppenders(event); } 1.3 +2 -4 jakarta-log4j/src/java/org/apache/log4j/plugins/PluginSkeleton.java Index: PluginSkeleton.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/PluginSkeleton.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PluginSkeleton.java 12 Dec 2002 07:50:05 -0000 1.2 +++ PluginSkeleton.java 3 Feb 2003 07:50:08 -0000 1.3 @@ -11,7 +11,7 @@ import org.apache.log4j.spi.LoggerRepository; /** - A convienent abstract class for receiver classes that implements + A convienent abstract class for plugin subclasses that implements the basic methods of the Plugin interface. Subclasses are required to implement the isActive(), activateOptions(), and shutdown() methods. @@ -43,9 +43,7 @@ } /** - Gets the logger repository for this plugin. If not - explicity set, returns the value of - LogManager.getLoggerRepository(). */ + Gets the logger repository for this plugin. */ public LoggerRepository getLoggerRepository() { return repository; } 1.3 +68 -29 jakarta-log4j/src/java/org/apache/log4j/plugins/PluginRegistry.java Index: PluginRegistry.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/PluginRegistry.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PluginRegistry.java 12 Dec 2002 07:52:41 -0000 1.2 +++ PluginRegistry.java 3 Feb 2003 07:50:08 -0000 1.3 @@ -22,11 +22,18 @@ @since 1.3 */ public class PluginRegistry { + /** stores the map of plugins for each repository. */ private static HashMap repositoryMap = new HashMap(); + + /** the listener used to listen for repository events. */ private static RepositoryListener listener = new RepositoryListener(); /** - Starts a Plugin with default logger repository. */ + Starts a Plugin with default logger repository. + + @param plugin the plugin to start. + @return Plugin the plugin parameter or a plugin that was already + active and was equal to the original plugin. */ public static Plugin startPlugin(Plugin plugin) { // if repository already set in plugin, use it LoggerRepository repository = plugin.getLoggerRepository(); @@ -40,18 +47,25 @@ } /** - Starts a plugin with a given logger repository. */ + Starts a plugin with a given logger repository. + + @param plugin the plugin to start. + @param repository the logger repository to attach the plugin to. + @return Plugin the plugin parameter or a plugin that was already + active and was equal to the original plugin. */ public static Plugin startPlugin(Plugin plugin, - LoggerRepository repository) { + LoggerRepository repository) + { // if the plugin is already active, just return it - if (plugin.isActive()) + if (plugin.isActive()) { return plugin; + } // put plugin into the repository's reciever map - synchronized(repositoryMap) { + synchronized (repositoryMap) { // get plugin map for repository - HashMap pluginMap = (HashMap)repositoryMap.get(repository); + HashMap pluginMap = (HashMap) repositoryMap.get(repository); String name = plugin.getName(); @@ -63,9 +77,8 @@ pluginMap = new HashMap(); repositoryMap.put(repository, pluginMap); repository.addLoggerRepositoryEventListener(listener); - } - else { - Plugin existingPlugin = (Plugin)pluginMap.get(name); + } else { + Plugin existingPlugin = (Plugin) pluginMap.get(name); if (existingPlugin != null) { boolean isEqual = existingPlugin.equals(plugin); @@ -90,34 +103,50 @@ } /** - Stops a plugin by plugin object. */ + Stops a plugin by plugin object. + + @param plugin the plugin to stop. + @return Plugin the plugin parameter, if stopped, or null if the + the plugin was not found in the registry. */ public static Plugin stopPlugin(Plugin plugin) { return stopPlugin(plugin.getName(), plugin.getLoggerRepository()); } /** - Stops a plugin by plugin name using default repository. */ + Stops a plugin by plugin name using default repository. + + @param pluginName name of the plugin to stop. + @return Plugin the plugin, if stopped, or null if the + the plugin was not found in the registry. */ public static Plugin stopPlugin(String pluginName) { return stopPlugin(pluginName, LogManager.getLoggerRepository()); } /** - Stops a plugin by plugin name and repository. */ - public static Plugin stopPlugin(String pluginName, - LoggerRepository repository) { + Stops a plugin by plugin name and repository. + + @param pluginName the name of the plugin to stop. + @param repository the repository the plugin should be attached to. + @return Plugin the plugin, if stopped, or null if the + the plugin was not found in the registry. */ + public static Plugin stopPlugin(String pluginName, + LoggerRepository repository) + { // if a null repository, exit now if (repository == null) { return null; } - synchronized(repositoryMap) { - HashMap pluginMap = (HashMap)repositoryMap.get(repository); - if (pluginMap == null) + synchronized (repositoryMap) { + HashMap pluginMap = (HashMap) repositoryMap.get(repository); + if (pluginMap == null) { return null; + } - Plugin plugin = (Plugin)pluginMap.get(pluginName); - if (plugin == null) + Plugin plugin = (Plugin) pluginMap.get(pluginName); + if (plugin == null) { return null; + } // shutdown the plugin plugin.shutdown(); @@ -144,19 +173,22 @@ } /** - Stops all plugins in the given logger repository. */ + Stops all plugins in the given logger repository. + + @param repository the logger repository to stop all plugins for. */ public static void stopAllPlugins(LoggerRepository repository) { - synchronized(repositoryMap) { - HashMap pluginMap = (HashMap)repositoryMap.get(repository); - if (pluginMap == null) + synchronized (repositoryMap) { + HashMap pluginMap = (HashMap) repositoryMap.get(repository); + if (pluginMap == null) { return; + } // remove the listener for this repository repository.removeLoggerRepositoryEventListener(listener); Iterator iter = pluginMap.values().iterator(); - while(iter.hasNext()) { - ((Plugin)iter.next()).shutdown(); + while (iter.hasNext()) { + ((Plugin) iter.next()).shutdown(); } // since no more plugins, remove plugin map from @@ -168,21 +200,28 @@ /** Internal class used to handle listener events from repositories. */ private static class RepositoryListener - implements LoggerRepositoryEventListener { + implements LoggerRepositoryEventListener + { /** - Stops all plugins associated with the repository being reset. */ + Stops all plugins associated with the repository being reset. + + @param repository the repository that was reset. */ public void configurationResetEvent(LoggerRepository repository) { PluginRegistry.stopAllPlugins(repository); } /** - Called when the repository configuration is changed. */ + Called when the repository configuration is changed. + + @param repository the repository that was changed. */ public void configurationChangedEvent(LoggerRepository repository) { // do nothing with this event } /** - Stops all plugins associated with the repository being shutdown. */ + Stops all plugins associated with the repository being shutdown. + + @param repository the repository being shutdown. */ public void shutdownEvent(LoggerRepository repository) { PluginRegistry.stopAllPlugins(repository); } 1.2 +20 -12 jakarta-log4j/src/java/org/apache/log4j/plugins/Plugin.java Index: Plugin.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/Plugin.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Plugin.java 11 Dec 2002 07:25:14 -0000 1.1 +++ Plugin.java 3 Feb 2003 07:50:08 -0000 1.2 @@ -15,9 +15,8 @@ <p>A plugin implements some specific functionality to extend the log4j framework. Each plugin is associated with a specific - LoggerRepository, which it then uses/acts upon. If no - repository is specified, the default repository from - LogManager.getLoggerRepository() is used. + LoggerRepository, which it then uses/acts upon. The functionality + of the plugin is up to the developer. <p>Examples of plugins are Receiver and Watchdog. Receiver plugins allow for remote logging events to be received and processed by @@ -32,26 +31,35 @@ public interface Plugin extends OptionHandler { /** - Gets the name of the plugin. */ + Gets the name of the plugin. + + @return String the name of the plugin. */ public String getName(); /** - Sets the name of the plugin. */ - public void setName(String _name); + Sets the name of the plugin. + + @param name the name of the plugin. */ + public void setName(String name); /** - Gets the logger repository for this plugin. If not - explicity set, returns the value of - LogManager.getLoggerRepository(). */ + Gets the logger repository for this plugin. + + @return LoggerRepository the logger repository this plugin is + attached to. */ public LoggerRepository getLoggerRepository(); /** Sets the logger repository used by this plugin. This - repository will be used by the plugin functionality. */ - public void setLoggerRepository(LoggerRepository _repository); + repository will be used by the plugin functionality. + + @param repository the logger repository to attach this plugin to. */ + public void setLoggerRepository(LoggerRepository repository); /** - True if the plugin is active and running. */ + True if the plugin is active and running. + + @return boolean true if the plugin is currently active. */ public boolean isActive(); /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]