You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by mw...@apache.org on 2003/10/20 07:29:15 UTC

cvs commit: jakarta-log4j/src/java/org/apache/log4j/plugins PluginSkeleton.java PluginRegistry.java Plugin.java

mwomack     2003/10/19 22:29:15

  Modified:    src/java/org/apache/log4j/plugins PluginSkeleton.java
                        PluginRegistry.java Plugin.java
  Log:
  Various cleanup.
  Defined new method in Plugin, isEquivalent().  Used by PluginRegistry to see if 2 plugins are equivalent.  Using this instead of overriding the equals() method which has too many implications to deal with normally.
  
  Revision  Changes    Path
  1.8       +14 -1     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PluginSkeleton.java	17 Sep 2003 23:30:14 -0000	1.7
  +++ PluginSkeleton.java	20 Oct 2003 05:29:15 -0000	1.8
  @@ -69,7 +69,7 @@
   
     Contributors: Nicko Cadell
   
  -  @author Mark Womack
  +  @author Mark Womack <mw...@apache.org>
     @author Paul Smith <ps...@apache.org>
     @since 1.3
   */
  @@ -131,6 +131,19 @@
      */
     public synchronized boolean isActive() {
       return active;
  +  }
  +
  +  /**
  +   * Returns true if the plugin has the same name and logger repository as the
  +   * testPlugin passed in.
  +   * 
  +   * @param testPlugin The plugin to test equivalency against.
  +   * @return Returns true if testPlugin is considered to be equivalent.
  +   */
  +  public boolean isEquivalent(Plugin testPlugin) {
  +    return (repository == testPlugin.getLoggerRepository()) &&
  +      ((this.name == null && testPlugin.getName() == null) ||
  +       (this.name != null && name.equals(testPlugin.getName())));
     }
   
     /**
  
  
  
  1.9       +36 -16    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PluginRegistry.java	18 Sep 2003 03:08:45 -0000	1.8
  +++ PluginRegistry.java	20 Oct 2003 05:29:15 -0000	1.9
  @@ -72,16 +72,28 @@
     @author Paul Smith
     @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();
  -  private static final EventListenerList listenerList =
  +public final class PluginRegistry {
  +  
  +  /**
  +   * stores the map of plugins for each repository.
  +   */
  +  private final static HashMap repositoryMap = new HashMap();
  +
  +  /**
  +   * the listener used to listen for repository events.
  +   */
  +  private final static RepositoryListener listener = new RepositoryListener();
  +  
  +  private final static EventListenerList listenerList =
       new EventListenerList();
   
     /**
  +   * Private constructor.  No instances of this class are meant
  +   * to be instantiated.
  +   */
  +  private PluginRegistry() { };
  +  
  +  /**
       Starts a Plugin with default logger repository.
   
       @param plugin the plugin to start.
  @@ -164,11 +176,11 @@
           Plugin existingPlugin = (Plugin) pluginMap.get(name);
   
           if (existingPlugin != null) {
  -          boolean isEqual = existingPlugin.equals(plugin);
  +          boolean isEquivalent = existingPlugin.isEquivalent(plugin);
   
             // if the plugins are equivalent and the existing one
             // is still active, just return the existing one now
  -          if (isEqual && existingPlugin.isActive()) {
  +          if (isEquivalent && existingPlugin.isActive()) {
               return existingPlugin;
             } else {
               existingPlugin.shutdown();
  @@ -188,8 +200,10 @@
     }
   
     /**
  -  * @param plugin
  -  */
  +   * Calls the pluginStarted method on every registered PluginListener.
  +   * 
  +   * @param plugin The plugin that has been started.
  +   */
     private static void firePluginStarted(Plugin plugin) {
       PluginListener[] listeners =
         (PluginListener[]) listenerList.getListeners(PluginListener.class);
  @@ -205,6 +219,11 @@
       }
     }
   
  +  /**
  +   * Calls the pluginStopped method for every registered PluginListner.
  +   * 
  +   * @param plugin The plugin that has been stopped.
  +   */
     private static void firePluginStopped(Plugin plugin) {
       PluginListener[] listeners =
         (PluginListener[]) listenerList.getListeners(PluginListener.class);
  @@ -221,10 +240,11 @@
     }
   
     /**
  -      Returns all the plugins for a given repository.
  -
  -      @param repository the logger repository to get the plugins from.
  -      @return List list of plugins from the repository. */
  +   * Returns all the plugins for a given repository.
  +   * 
  +   * @param repository the logger repository to get the plugins from.
  +   * @return List list of plugins from the repository.
  +   */
     public static List getPlugins(LoggerRepository repository) {
       synchronized (repositoryMap) {
         // get plugin map for repository
  @@ -367,7 +387,7 @@
         Iterator iter = pluginMap.values().iterator();
   
         while (iter.hasNext()) {
  -		Plugin plugin = (Plugin) iter.next();
  +		    Plugin plugin = (Plugin) iter.next();
           plugin.shutdown();
           firePluginStopped(plugin);
         }
  
  
  
  1.7       +48 -22    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Plugin.java	17 Sep 2003 23:30:14 -0000	1.6
  +++ Plugin.java	20 Oct 2003 05:29:15 -0000	1.7
  @@ -69,36 +69,39 @@
     allow for a repository to be reconfigured when some "watched"
     configuration data changes.
   
  -  @author Mark Womack
  +  @author Mark Womack <mw...@apache.org>
     @author Nicko Cadell
     @author Paul Smith <ps...@apache.org>
     @since 1.3
   */
   public interface Plugin extends OptionHandler {
     /**
  -    Gets the name of the plugin.
  -
  -    @return String 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.
  -
  -    @param name 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.
  -
  -    @return LoggerRepository the logger repository this plugin is
  -      attached to. */
  +   * 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.
  -
  -    @param repository the logger repository to attach this plugin to. */
  +   * Sets the logger repository used by this plugin. This
  +   * repository will be used by the plugin functionality.
  +   * 
  +   * @param repository the logger repository to attach this plugin to.
  +   */
     public void setLoggerRepository(LoggerRepository repository);
   
     /**
  @@ -113,15 +116,17 @@
     /**
      * Adds a PropertyChangeListener that will be notified of all property
      * changes.
  -   * @param l
  +   * 
  +   * @param l The listener to add.
      */
     public void addPropertyChangeListener(PropertyChangeListener l);
   
     /**
      * Removes a specific PropertyChangeListener from this instances
      * registry that has been mapped to be notified of all property
  -   * changes..
  -   * @param l
  +   * changes.
  +   * 
  +   * @param l The listener to remove.
      */
     public void removePropertyChangeListener(PropertyChangeListener l);
   
  @@ -136,12 +141,33 @@
       String propertyName, PropertyChangeListener l);
   
     /**
  -    True if the plugin is active and running.
  -
  -    @return boolean true if the plugin is currently active. */
  +   * 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. */
  +   * Returns true if the testPlugin is considered to be "equivalent" to the
  +   * this plugin.  The equivalency test is at the discretion of the plugin
  +   * implementation.  The PluginRegistry will use this method when starting
  +   * new plugins to see if a given plugin is considered equivalent to an
  +   * already running plugin with the same name.  If they are considered to
  +   * be equivalent, the currently running plugin will be left in place, and
  +   * the new plugin will not be started.
  +   * 
  +   * It is possible to override the equals() method, however this has
  +   * more meaning than is required for this simple test and would also
  +   * require the overriding of the hashCode() method as well.  All of this
  +   * is more work than is needed, so this simple method is used instead.
  +   * 
  +   * @param testPlugin The plugin to test equivalency against.
  +   * @return Returns true if testPlugin is considered to be equivelent.
  +   */
  +  public boolean isEquivalent(Plugin testPlugin);
  +  
  +  /**
  +   * Call when the plugin should be stopped.
  +   */
     public void shutdown();
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org