mwomack     2003/02/19 23:18:32

  Modified:    src/java/org/apache/log4j/plugins Receiver.java
                        PluginSkeleton.java PluginRegistry.java Plugin.java
  Log:
  Jalopy-ized and checkstyle-d versions of the plugin files.
  
  Revision  Changes    Path
  1.3       +24 -23    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Receiver.java     3 Feb 2003 07:50:08 -0000       1.2
  +++ Receiver.java     20 Feb 2003 07:18:32 -0000      1.3
  @@ -4,41 +4,41 @@
    * This software is published under the terms of the Apache Software
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
  -
   package org.apache.log4j.plugins;
   
   import org.apache.log4j.Logger;
   import org.apache.log4j.spi.LoggingEvent;
   
  +
   /**
     Defines the base class for Receiver plugins.
  -  
  +
     <p>Just as Appenders send logging events outside of the log4j
     environment (to files, to smtp, to sockets, etc), Receivers bring
     logging events inside the log4j environment.
  -  
  +
     <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 
  -  the socket can be a SocketReceiver object.  The SocketReceiver 
  +  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
  +  the socket can be a SocketReceiver object.  The SocketReceiver
     object receives the logging event, and then "posts" it to the
  -  log4j environment (LoggerRepository) on the receiving machine, to 
  -  be handled by the configured appenders, etc.  The various 
  -  settings in this environment (Logger levels, Appender filters & 
  +  log4j environment (LoggerRepository) on the receiving machine, to
  +  be handled by the configured appenders, etc.  The various
  +  settings in this environment (Logger levels, Appender filters &
     thresholds) are applied to the received logging event.
  -  
  +
     <p>Receivers can also be used to "import" log messages from other
     logging packages into the log4j environment.
  -  
  +
     <p>Receivers can be configured to post events to a given
     LoggerRepository.
  -  
  +
     <p>Subclasses of Receiver must implement the isActive(),
     activateOptions(), and shutdown() methods. The doPost() method
     is provided to standardize the "import" of remote events into
     the repository.
  -  
  +
     @author Mark Womack
     @author Ceki G&uuml;lc&uuml;
     @since 1.3
  @@ -46,19 +46,20 @@
   public abstract class Receiver extends PluginSkeleton {
     /**
       Posts the logging event to a logger in the configured logger
  -    repository. */    
  +    repository. 
  +    
  +    @param event the log event to post to the local log4j environment. */
     public void doPost(LoggingEvent event) {
       // get the "local" logger for this event from the
       // configured repository.
  -     Logger localLogger = 
  +    Logger localLogger =
         getLoggerRepository().getLogger(event.getLoggerName());
  -     
  -     // 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())) {
  +
  +    // 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())) {
         // call the loggers appenders to process the event
  -       localLogger.callAppenders(event);
  -     }
  +      localLogger.callAppenders(event);
  +    }
     }
   }
  -
  
  
  
  1.4       +26 -17    
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginSkeleton.java       3 Feb 2003 07:50:08 -0000       1.3
  +++ PluginSkeleton.java       20 Feb 2003 07:18:32 -0000      1.4
  @@ -4,55 +4,64 @@
    * This software is published under the terms of the Apache Software
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
  -
   package org.apache.log4j.plugins;
   
  -import org.apache.log4j.LogManager;
   import org.apache.log4j.spi.LoggerRepository;
   
  +
   /**
     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.
  -  
  +
     <p>Developers are not required to subclass PluginSkeleton to
     develop their own plugins (they are only required to implement the
     Plugin interface), but it provides a convienent base class to start
     from.
  -  
  +
     Contributors: Nicko Cadell
  -  
  +
     @author Mark Womack
     @since 1.3
   */
   public abstract class PluginSkeleton implements Plugin {
  +  /** Name of this plugin. */
     protected String name = "";
  -  protected LoggerRepository repository;
     
  +  /** Repository this plugin is attached to. */
  +  protected LoggerRepository repository;
  +
     /**
  -    Gets the name of the plugin. */
  +    Gets the name of the plugin. 
  +    
  +    @return String the name of the plugin. */
     public String getName() {
       return name;
     }
  -  
  +
     /**
  -    Sets the name of the plugin. */
  -  public void setName(String _name) {
  -    name = _name;
  +    Sets the name of the plugin. 
  +    
  +    @param name the name of the plugin to set. */
  +  public void setName(String name) {
  +    this.name = name;
     }
  -      
  +
     /**
  -    Gets the logger repository for this plugin. */
  +    Gets the logger repository for this plugin. 
  +    
  +    @return LoggerRepository the logger repository this plugin will affect. */
     public LoggerRepository getLoggerRepository() {
       return repository;
     }
   
     /**
       Sets the logger repository used by this plugin. This
  -    repository will be used by the plugin functionality. */
  -  public void setLoggerRepository(LoggerRepository _repository) {
  -    repository = _repository;
  +    repository will be used by the plugin functionality. 
  +    
  +    @param repository the logger repository that this plugin should affect. */
  +  public void setLoggerRepository(LoggerRepository repository) {
  +    this.repository = repository;
     }
   }
  -
  
  
  
  1.4       +59 -58    
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginRegistry.java       3 Feb 2003 07:50:08 -0000       1.3
  +++ PluginRegistry.java       20 Feb 2003 07:18:32 -0000      1.4
  @@ -4,69 +4,67 @@
    * This software is published under the terms of the Apache Software
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
  -
   package org.apache.log4j.plugins;
   
  -import java.util.HashMap;
  -import java.util.Iterator;
   import org.apache.log4j.LogManager;
   import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.LoggerRepositoryEventListener;
   
  +import java.util.HashMap;
  +import java.util.Iterator;
  +
  +
   /**
  -  This is a registry for Plugin instances. It provides methods to 
  +  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.
  -  
  +
     @author Mark Womack
     @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. 
  -    
  -    @param plugin the plugin to start. 
  +    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();
  -    
  +
       // else use the default one
       if (repository == null) {
         repository = LogManager.getLoggerRepository();
       }
  -    
  +
       return startPlugin(plugin, repository);
     }
   
     /**
  -    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)
  -  {
  -    
  +  public static Plugin startPlugin(Plugin plugin, LoggerRepository repository) {
       // if the plugin is already active, just return it
       if (plugin.isActive()) {
         return plugin;
       }
  -      
  +
       // put plugin into the repository's reciever map
       synchronized (repositoryMap) {
         // get plugin map for repository
         HashMap pluginMap = (HashMap) repositoryMap.get(repository);
  -      
  +
         String name = plugin.getName();
   
         // make sure the plugin has reference to repository
  @@ -79,9 +77,10 @@
           repository.addLoggerRepositoryEventListener(listener);
         } else {
           Plugin existingPlugin = (Plugin) pluginMap.get(name);
  +
           if (existingPlugin != null) {
             boolean isEqual = existingPlugin.equals(plugin);
  -          
  +
             // if the plugins are equivalent and the existing one
             // is still active, just return the existing one now
             if (isEqual && existingPlugin.isActive()) {
  @@ -91,30 +90,30 @@
             }
           }
         }
  -      
  +
         // put the new plugin into the map
         pluginMap.put(name, plugin);
  -      
  +
         // start the new plugin
         plugin.activateOptions();
  -      
  +
         return plugin;
       }
     }
  -  
  +
     /**
  -    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.
  -    
  +
       @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. */
  @@ -123,15 +122,14 @@
     }
   
     /**
  -    Stops a plugin by plugin name and 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) 
  -  {
  +  public static Plugin stopPlugin(
  +    String pluginName, LoggerRepository repository) {
       // if a null repository, exit now
       if (repository == null) {
         return null;
  @@ -139,91 +137,94 @@
   
       synchronized (repositoryMap) {
         HashMap pluginMap = (HashMap) repositoryMap.get(repository);
  +
         if (pluginMap == null) {
           return null;
         }
  -        
  +
         Plugin plugin = (Plugin) pluginMap.get(pluginName);
  +
         if (plugin == null) {
           return null;
         }
  -      
  +
         // shutdown the plugin
         plugin.shutdown();
  -      
  +
         // remove it from the plugin map
         pluginMap.remove(pluginName);
  -      
  +
         // if no more plugins, remove the plugin map from
         // repository map
         if (pluginMap.isEmpty()) {
           repository.removeLoggerRepositoryEventListener(listener);
           repositoryMap.remove(repository);
         }
  -      
  +
         // return it for future use
         return plugin;
       }
     }
  -  
  +
     /**
       Stops all plugins in the default logger repository. */
     public static void stopAllPlugins() {
       stopAllPlugins(LogManager.getLoggerRepository());
     }
  -  
  +
     /**
  -    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) {    
  +  public static void stopAllPlugins(LoggerRepository repository) {
       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();
         }
  -      
  +
         // since no more plugins, remove plugin map from
         // the repository
         repositoryMap.remove(repository);
       }
     }
  -  
  +
     /**
       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);
       }
     }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.3       +19 -20    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Plugin.java       3 Feb 2003 07:50:08 -0000       1.2
  +++ Plugin.java       20 Feb 2003 07:18:32 -0000      1.3
  @@ -4,65 +4,64 @@
    * This software is published under the terms of the Apache Software
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
  -
   package org.apache.log4j.plugins;
   
   import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.OptionHandler;
   
  +
   /**
     Defines the required interface for all Plugin objects.
  -  
  +
     <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.  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
     a repository as if the event was sent locally. Watchdog plugins
     allow for a repository to be reconfigured when some "watched"
     configuration data changes.
  -    
  +
     @author Mark Womack
     @author Nicko Cadell
     @since 1.3
   */
   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. 
  -    
  +    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. 
  -    
  +    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. 
  -    
  +    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();
  -    
  +
     /**
       Call when the plugin should be stopped. */
     public void shutdown();
  -}
  \ No newline at end of file
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to