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 ca...@apache.org on 2007/04/11 21:29:41 UTC

svn commit: r527629 - in /logging/log4j/trunk/src/java/org/apache/log4j/plugins: Pauseable.java Plugin.java PluginEvent.java PluginListener.java PluginRegistry.java PluginSkeleton.java Receiver.java

Author: carnold
Date: Wed Apr 11 12:29:39 2007
New Revision: 527629

URL: http://svn.apache.org/viewvc?view=rev&rev=527629
Log:
Bug 42092: Checkstyle fixes in org.apache.log4j.plugins

Modified:
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/Pauseable.java
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/Plugin.java
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginEvent.java
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginListener.java
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginRegistry.java
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginSkeleton.java
    logging/log4j/trunk/src/java/org/apache/log4j/plugins/Receiver.java

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/Pauseable.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/Pauseable.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/Pauseable.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/Pauseable.java Wed Apr 11 12:29:39 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,12 +20,20 @@
 
 /**
  * Instances of this interface can be paused, and resumed.
- * 
- * @author Paul Smith <ps...@apache.org>
+ *
+ * @author Paul Smith (psmith@apache.org)
  *
  */
 public interface Pauseable {
-  public void setPaused(boolean paused);
+    /**
+     * Set paused state.
+     * @param paused new value
+     */
+  void setPaused(boolean paused);
 
-  public boolean isPaused();
+    /**
+     * Get paused state.
+     * @return paused state.
+     */
+  boolean isPaused();
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/Plugin.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/Plugin.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/Plugin.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/Plugin.java Wed Apr 11 12:29:39 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,118 +24,122 @@
 
 
 /**
-  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 <mw...@apache.org>
-  @author Nicko Cadell
-  @author Paul Smith <ps...@apache.org>
-  @since 1.3
-*/
+ * Defines the required interface for all Plugin objects.
+ * <p/>
+ * <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/>
+ * <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 (mwomack@apache.org)
+ * @author Nicko Cadell
+ * @author Paul Smith (psmith@apache.org)
+ * @since 1.3
+ */
 public interface Plugin extends OptionHandler {
-  /**
-   * 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.
-   */
-  public void setName(String name);
-
-  /**
-   * 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.
-   */
-  public void setLoggerRepository(LoggerRepository repository);
-
-  /**
-   * Adds a PropertyChangeListener to this instance which is
-   * notified only by changes of the property with name propertyName
-   * @param propertyName the name of the property in standard JavaBean syntax (e.g. for setName(), property="name")
-   * @param l
-   */
-  public void addPropertyChangeListener(
-    String propertyName, PropertyChangeListener l);
-
-  /**
-   * Adds a PropertyChangeListener that will be notified of all property
-   * changes.
-   * 
-   * @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 The listener to remove.
-   */
-  public void removePropertyChangeListener(PropertyChangeListener l);
-
-  /**
-   * Removes a specific PropertyChangeListener from this instance's
-   * registry which has been previously registered to be notified
-   * of only a specific property change.
-   * @param propertyName
-   * @param l
-   */
-  public void removePropertyChangeListener(
-    String propertyName, PropertyChangeListener l);
-
-  /**
-   * True if the plugin is active and running.
-   * 
-   * @return boolean true if the plugin is currently active.
-   */
-  public boolean isActive();
-
-  /**
-   * 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();
+    /**
+     * Gets the name of the plugin.
+     *
+     * @return String the name of the plugin.
+     */
+    String getName();
+
+    /**
+     * Sets the name of the plugin.
+     *
+     * @param name the name of the plugin.
+     */
+    void setName(String name);
+
+    /**
+     * Gets the logger repository for this plugin.
+     *
+     * @return the logger repository to which this plugin is attached.
+     */
+    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.
+     */
+    void setLoggerRepository(LoggerRepository repository);
+
+    /**
+     * Adds a PropertyChangeListener to this instance which is
+     * notified only by changes of the property with name propertyName.
+     *
+     * @param propertyName
+     *    the name of the property in standard JavaBean syntax
+     *    (e.g. for setName(), property="name")
+     * @param l listener
+     */
+    void addPropertyChangeListener(
+            String propertyName, PropertyChangeListener l);
+
+    /**
+     * Adds a PropertyChangeListener that will be notified of all property
+     * changes.
+     *
+     * @param l The listener to add.
+     */
+    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 The listener to remove.
+     */
+    void removePropertyChangeListener(PropertyChangeListener l);
+
+    /**
+     * Removes a specific PropertyChangeListener from this instance's
+     * registry which has been previously registered to be notified
+     * of only a specific property change.
+     *
+     * @param propertyName property name, may not be null.
+     * @param l listener to be removed.
+     */
+    void removePropertyChangeListener(
+            String propertyName, PropertyChangeListener l);
+
+    /**
+     * True if the plugin is active and running.
+     *
+     * @return boolean true if the plugin is currently active.
+     */
+    boolean isActive();
+
+    /**
+     * 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.
+     * <p/>
+     * 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.
+     */
+    boolean isEquivalent(Plugin testPlugin);
+
+    /**
+     * Call when the plugin should be stopped.
+     */
+    void shutdown();
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginEvent.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginEvent.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginEvent.java Wed Apr 11 12:29:39 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,19 +28,20 @@
  * @author Paul Smith
  */
 public class PluginEvent extends EventObject {
-  /**
-   * @param source The source plugin of the event
-   */
-  PluginEvent(Plugin source) {
-    super(source);
-  }
+    /**
+     * @param source The source plugin of the event
+     */
+    PluginEvent(final Plugin source) {
+        super(source);
+    }
 
-	/**
-	 * Returns the source Plugin of this event, which is simple
-	 * the getSource() method casted to Plugin for convenience.
-	 * @return Plugin source of this event
-	 */
-  public Plugin getPlugin() {
-    return (Plugin) getSource();
+    /**
+     * Returns the source Plugin of this event, which is simple
+     * the getSource() method casted to Plugin for convenience.
+     *
+     * @return Plugin source of this event
+     */
+    public Plugin getPlugin() {
+        return (Plugin) getSource();
   }
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginListener.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginListener.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginListener.java Wed Apr 11 12:29:39 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,11 +25,19 @@
 /**
  * PluginListeners are notified when plugins are started or stopped
  * by the PluginRegistry.
- * 
- * @author Paul Smith <ps...@apache.org>
+ *
+ * @author Paul Smith (psmith@apache.org)
  */
 public interface PluginListener extends EventListener {
-  public void pluginStarted(PluginEvent e);
+    /**
+     * Notification that plugin has started.
+     * @param e event
+     */
+  void pluginStarted(PluginEvent e);
 
-  public void pluginStopped(PluginEvent e);
+    /**
+     * Notification that plugin has stopped.
+     * @param e event
+     */
+  void pluginStopped(PluginEvent e);
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginRegistry.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginRegistry.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginRegistry.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginRegistry.java Wed Apr 11 12:29:39 2007
@@ -29,253 +29,276 @@
 
 
 /**
-  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
-  @author Paul Smith
-  @since 1.3
-*/
+ * 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
+ * @author Paul Smith
+ * @since 1.3
+ */
 public final class PluginRegistry {
-  /**
-   * The pluginMap is keyed by plugin name and contains plugins as values.
-   * key=plugin.getName, value=plugin
-   */
-  private final Map pluginMap;
-  private final LoggerRepositoryEx loggerRepository;
-
-  /**
-   * the listener used to listen for repository events.
-   */
-  private final RepositoryListener listener = new RepositoryListener();
-  private final List listenerList = Collections.synchronizedList(new ArrayList());
-
-  public PluginRegistry(LoggerRepositoryEx loggerRepository) {
-    pluginMap = new HashMap();
-    this.loggerRepository = loggerRepository;
-    this.loggerRepository.addLoggerRepositoryEventListener(listener);
-  }
-
-  public LoggerRepositoryEx getLoggerRepository() {
-    return loggerRepository;
-  }
-
-
-  /**
-   * Returns true if the specified name is already taken by
-   * an existing Plugin registered within the scope of the specified
-   * LoggerRepository.
-   * @param name The name to check the repository for
-   * @return true if the name is already in use, otherwise false
-   */
-  public boolean pluginNameExists(String name) {
-    synchronized (pluginMap) {
-      return pluginMap.containsKey(name);
-    }
-  }
-
-
-  /**
-   * Adds a plugin to the plugin registry. If a plugin with the same name exists
-   * already, it is shutdown and removed.
-   *
-   * @param plugin the plugin to add.
-   * */
-  public void addPlugin(Plugin plugin) {
-    // put plugin into the repository's reciever map
-    synchronized (pluginMap) {
-      String name = plugin.getName();
-
-      // make sure the plugin has reference to repository
-      plugin.setLoggerRepository(getLoggerRepository());
-
-      Plugin existingPlugin = (Plugin)pluginMap.get(name);
-      if (existingPlugin != null) {
-        existingPlugin.shutdown();
-      }
-
-      // put the new plugin into the map
-      pluginMap.put(name, plugin);
-      firePluginStarted(plugin);
-    }
-  }
-
-
-  /**
-   * Calls the pluginStarted method on every registered PluginListener.
-   *
-   * @param plugin The plugin that has been started.
-   */
-  private void firePluginStarted(Plugin plugin) {
-  	PluginEvent e = null;
-  	synchronized(listenerList){
-  		for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
-  			PluginListener listener = (PluginListener) iter.next();
-  			if (e == null) {
-  				e = new PluginEvent(plugin);
-  			}
-  			listener.pluginStarted(e);
-  		}
-  	}
-  }
-
-
-  /**
-   * Calls the pluginStopped method for every registered PluginListner.
-   *
-   * @param plugin The plugin that has been stopped.
-   */
-  private void firePluginStopped(Plugin plugin) {
-  	PluginEvent e = null;
-  	synchronized(listenerList){
-  		for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
-  			PluginListener listener = (PluginListener) iter.next();
-  			if (e == null) {
-  				e = new PluginEvent(plugin);
-  			}
-  			listener.pluginStopped(e);
-  		}
-  	}
-  }
-
-
-  /**
-   * Returns all the plugins for a given repository.
-   *
-   * @return List list of plugins from the repository.
-   */
-  public List getPlugins() {
-    synchronized (pluginMap) {
-      List pluginList = new ArrayList(pluginMap.size());
-      Iterator iter = pluginMap.values().iterator();
-
-      while (iter.hasNext()) {
-        pluginList.add(iter.next());
-      }
-      return pluginList;
-    }
-  }
-
-
-  /**
-    Returns all the plugins for a given repository that are instances
-    of a certain class.
-
-    @param pluginClass the class the plugin must implement to be selected.
-    @return List list of plugins from the repository. */
-  public List getPlugins(Class pluginClass) {
-    synchronized (pluginMap) {
-      List pluginList = new ArrayList(pluginMap.size());
-      Iterator iter = pluginMap.values().iterator();
-
-      while (iter.hasNext()) {
-        Object plugin = iter.next();
-
-        if (pluginClass.isInstance(plugin)) {
-          pluginList.add(plugin);
-        }
-      }
-      return pluginList;
-    }
-  }
-
-
-  /**
-    Stops a plugin by plugin name and repository.
-
-    @param pluginName the 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 Plugin stopPlugin(String pluginName) {
-    synchronized (pluginMap) {
-      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);
-      firePluginStopped(plugin);
-
-      // return it for future use
-      return plugin;
-    }
-  }
-
-  /**
-    Stops all plugins in the given logger repository.
-
-
-   */
-  public void stopAllPlugins() {
-    synchronized (pluginMap) {
-      // remove the listener for this repository
-      loggerRepository.removeLoggerRepositoryEventListener(listener);
-
-      Iterator iter = pluginMap.values().iterator();
-
-      while (iter.hasNext()) {
-        Plugin plugin = (Plugin)iter.next();
-        plugin.shutdown();
-        firePluginStopped(plugin);
-      }
-    }
-  }
-
-
-  /**
-   * Adds a PluginListener to this registry to be notified
-   * of PluginEvents
-   *
-   * @param l PluginListener to add to this registry
-   */
-  public final void addPluginListener(PluginListener l) {
-    listenerList.add(l);
-  }
-
-
-  /**
-   * Removes a particular PluginListener from this registry
-   * such that it will no longer be notified of PluginEvents
-   *
-   * @param l PluginListener to remove
-   */
-  public final void removePluginListener(PluginListener l) {
-    listenerList.remove(l);
-  }
-
-  /**
-    Internal class used to handle listener events from repositories. */
-  private class RepositoryListener implements LoggerRepositoryEventListener {
-    /**
-      Stops all plugins associated with the repository being reset.
-
-      @param repository the repository that was reset. */
-    public void configurationResetEvent(LoggerRepository repository) {
-      PluginRegistry.this.stopAllPlugins();
-    }
-
-
-    /**
-      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.
-
-      @param repository the repository being shutdown. */
-    public void shutdownEvent(LoggerRepository repository) {
-      PluginRegistry.this.stopAllPlugins();
+    /**
+     * The pluginMap is keyed by plugin name and contains plugins as values.
+     * key=plugin.getName, value=plugin
+     */
+    private final Map pluginMap;
+    /**
+     * Logger repository.
+     */
+    private final LoggerRepositoryEx loggerRepository;
+
+    /**
+     * the listener used to listen for repository events.
+     */
+    private final RepositoryListener listener = new RepositoryListener();
+    /**
+     * List of listeners.
+     */
+    private final List listenerList =
+            Collections.synchronizedList(new ArrayList());
+
+    /**
+     * Creates a new instance.
+     * @param repository logger repository.
+     */
+    public PluginRegistry(final LoggerRepositoryEx repository) {
+        super();
+        pluginMap = new HashMap();
+        this.loggerRepository = repository;
+        this.loggerRepository.addLoggerRepositoryEventListener(listener);
+    }
+
+    /**
+     * Get logger repository.
+     * @return logger repository.
+     */
+    public LoggerRepositoryEx getLoggerRepository() {
+        return loggerRepository;
+    }
+
+
+    /**
+     * Returns true if the specified name is already taken by
+     * an existing Plugin registered within the scope of the specified
+     * LoggerRepository.
+     *
+     * @param name The name to check the repository for
+     * @return true if the name is already in use, otherwise false
+     */
+    public boolean pluginNameExists(final String name) {
+        synchronized (pluginMap) {
+            return pluginMap.containsKey(name);
+        }
+    }
+
+
+    /**
+     * Adds a plugin to the plugin registry.
+     * If a plugin with the same name exists
+     * already, it is shutdown and removed.
+     *
+     * @param plugin the plugin to add.
+     */
+    public void addPlugin(final Plugin plugin) {
+        // put plugin into the repository's reciever map
+        synchronized (pluginMap) {
+            String name = plugin.getName();
+
+            // make sure the plugin has reference to repository
+            plugin.setLoggerRepository(getLoggerRepository());
+
+            Plugin existingPlugin = (Plugin) pluginMap.get(name);
+            if (existingPlugin != null) {
+                existingPlugin.shutdown();
+            }
+
+            // put the new plugin into the map
+            pluginMap.put(name, plugin);
+            firePluginStarted(plugin);
+        }
+    }
+
+
+    /**
+     * Calls the pluginStarted method on every registered PluginListener.
+     *
+     * @param plugin The plugin that has been started.
+     */
+    private void firePluginStarted(final Plugin plugin) {
+        PluginEvent e = null;
+        synchronized (listenerList) {
+            for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
+                PluginListener l = (PluginListener) iter.next();
+                if (e == null) {
+                    e = new PluginEvent(plugin);
+                }
+                l.pluginStarted(e);
+            }
+        }
+    }
+
+
+    /**
+     * Calls the pluginStopped method for every registered PluginListner.
+     *
+     * @param plugin The plugin that has been stopped.
+     */
+    private void firePluginStopped(final Plugin plugin) {
+        PluginEvent e = null;
+        synchronized (listenerList) {
+            for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
+                PluginListener l = (PluginListener) iter.next();
+                if (e == null) {
+                    e = new PluginEvent(plugin);
+                }
+                l.pluginStopped(e);
+            }
+        }
+    }
+
+
+    /**
+     * Returns all the plugins for a given repository.
+     *
+     * @return List list of plugins from the repository.
+     */
+    public List getPlugins() {
+        synchronized (pluginMap) {
+            List pluginList = new ArrayList(pluginMap.size());
+            Iterator iter = pluginMap.values().iterator();
+
+            while (iter.hasNext()) {
+                pluginList.add(iter.next());
+            }
+            return pluginList;
+        }
+    }
+
+
+    /**
+     * Returns all the plugins for a given repository that are instances
+     * of a certain class.
+     *
+     * @param pluginClass the class the plugin must implement to be selected.
+     * @return List list of plugins from the repository.
+     */
+    public List getPlugins(final Class pluginClass) {
+        synchronized (pluginMap) {
+            List pluginList = new ArrayList(pluginMap.size());
+            Iterator iter = pluginMap.values().iterator();
+
+            while (iter.hasNext()) {
+                Object plugin = iter.next();
+
+                if (pluginClass.isInstance(plugin)) {
+                    pluginList.add(plugin);
+                }
+            }
+            return pluginList;
+        }
+    }
+
+
+    /**
+     * Stops a plugin by plugin name and repository.
+     *
+     * @param pluginName the 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 Plugin stopPlugin(final String pluginName) {
+        synchronized (pluginMap) {
+            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);
+            firePluginStopped(plugin);
+
+            // return it for future use
+            return plugin;
+        }
+    }
+
+    /**
+     * Stops all plugins in the given logger repository.
+     */
+    public void stopAllPlugins() {
+        synchronized (pluginMap) {
+            // remove the listener for this repository
+            loggerRepository.removeLoggerRepositoryEventListener(listener);
+
+            Iterator iter = pluginMap.values().iterator();
+
+            while (iter.hasNext()) {
+                Plugin plugin = (Plugin) iter.next();
+                plugin.shutdown();
+                firePluginStopped(plugin);
+            }
+        }
+    }
+
+
+    /**
+     * Adds a PluginListener to this registry to be notified
+     * of PluginEvents.
+     *
+     * @param l PluginListener to add to this registry
+     */
+    public void addPluginListener(final PluginListener l) {
+        listenerList.add(l);
+    }
+
+
+    /**
+     * Removes a particular PluginListener from this registry
+     * such that it will no longer be notified of PluginEvents.
+     *
+     * @param l PluginListener to remove
+     */
+    public void removePluginListener(final PluginListener l) {
+        listenerList.remove(l);
+    }
+
+    /**
+     * Internal class used to handle listener events from repositories.
+     */
+    private class RepositoryListener implements LoggerRepositoryEventListener {
+        /**
+         * Stops all plugins associated with the repository being reset.
+         *
+         * @param repository the repository that was reset.
+         */
+        public void configurationResetEvent(final LoggerRepository repository) {
+            PluginRegistry.this.stopAllPlugins();
+        }
+
+
+        /**
+         * Called when the repository configuration is changed.
+         *
+         * @param repository the repository that was changed.
+         */
+        public void configurationChangedEvent(
+                final LoggerRepository repository) {
+            // do nothing with this event
+        }
+
+
+        /**
+         * Stops all plugins associated with the repository being shutdown.
+         *
+         * @param repository the repository being shutdown.
+         */
+        public void shutdownEvent(final LoggerRepository repository) {
+            PluginRegistry.this.stopAllPlugins();
+        }
     }
-  }
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginSkeleton.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginSkeleton.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginSkeleton.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/PluginSkeleton.java Wed Apr 11 12:29:39 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,160 +26,198 @@
 
 
 /**
-  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 convenient base class to start
-  from.
-
-  Contributors: Nicko Cadell
-
-  @author Mark Womack <mw...@apache.org>
-  @author Paul Smith <ps...@apache.org>
-  @since 1.3
-*/
+ * 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/>
+ * <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 convenient base class to start
+ * from.
+ * <p/>
+ * Contributors: Nicko Cadell
+ *
+ * @author Mark Womack (mwomack@apache.org)
+ * @author Paul Smith (psmith@apache.org)
+ * @since 1.3
+ */
 public abstract class PluginSkeleton extends ComponentBase implements Plugin {
-  /** Name of this plugin. */
-  protected String name = "";
-
-  protected boolean active;
-
-  /**
-   * This is a delegate that does all the PropertyChangeListener
-   * support.
-   */
-  private PropertyChangeSupport propertySupport =
-    new PropertyChangeSupport(this);
-
-  /**
-    Gets the name of the plugin.
-
-    @return String the name of the plugin. */
-  public String getName() {
-    return name;
-  }
-
-  /**
-    Sets the name of the plugin and notifies PropertyChangeListeners of the change
-
-    @param name the name of the plugin to set. */
-  public void setName(String name) {
-    String oldName = this.name;
-    this.name = name;
-    propertySupport.firePropertyChange("name", oldName, this.name);
-  }
-
-  /**
-    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 and notifies an relevant PropertyChangeListeners registered. This
-    repository will be used by the plugin functionality.
-
-    @param repository the logger repository that this plugin should affect. */
-  public void setLoggerRepository(LoggerRepository repository) {
-    Object oldValue = this.repository;
-    this.repository = repository;
-    firePropertyChange("loggerRepository", oldValue, this.repository);
-  }
-
-  /**
-   * Returns whether this plugin is Active or not
-   * @return true/false
-   */
-  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()))) && this.getClass().equals(testPlugin.getClass());
-  }
-
-  /**
-   * @param listener
-   */
-  public final void addPropertyChangeListener(PropertyChangeListener listener) {
-    propertySupport.addPropertyChangeListener(listener);
-  }
-
-  /**
-   * @param propertyName
-   * @param listener
-   */
-  public final void addPropertyChangeListener(
-    String propertyName, PropertyChangeListener listener) {
-    propertySupport.addPropertyChangeListener(propertyName, listener);
-  }
-
-  /**
-   * @param listener
-   */
-  public final void removePropertyChangeListener(
-    PropertyChangeListener listener) {
-    propertySupport.removePropertyChangeListener(listener);
-  }
-
-  /**
-   * @param propertyName
-   * @param listener
-   */
-  public final void removePropertyChangeListener(
-    String propertyName, PropertyChangeListener listener) {
-    propertySupport.removePropertyChangeListener(propertyName, listener);
-  }
-
-  /**
-   * @param evt
-   */
-  protected final void firePropertyChange(PropertyChangeEvent evt) {
-    propertySupport.firePropertyChange(evt);
-  }
-
-  /**
-   * @param propertyName
-   * @param oldValue
-   * @param newValue
-   */
-  protected final void firePropertyChange(
-    String propertyName, boolean oldValue, boolean newValue) {
-    propertySupport.firePropertyChange(propertyName, oldValue, newValue);
-  }
-
-  /**
-   * @param propertyName
-   * @param oldValue
-   * @param newValue
-   */
-  protected final void firePropertyChange(
-    String propertyName, int oldValue, int newValue) {
-    propertySupport.firePropertyChange(propertyName, oldValue, newValue);
-  }
-
-  /**
-   * @param propertyName
-   * @param oldValue
-   * @param newValue
-   */
-  protected final void firePropertyChange(
-    String propertyName, Object oldValue, Object newValue) {
-    propertySupport.firePropertyChange(propertyName, oldValue, newValue);
-  }
+    /**
+     * Name of this plugin.
+     */
+    protected String name = "";
+
+    /**
+     * Active state of plugin.
+     */
+    protected boolean active;
+
+    /**
+     * This is a delegate that does all the PropertyChangeListener
+     * support.
+     */
+    private PropertyChangeSupport propertySupport =
+            new PropertyChangeSupport(this);
+
+    /**
+     * Construct new instance.
+     */
+    protected PluginSkeleton() {
+        super();
+    }
+
+    /**
+     * Gets the name of the plugin.
+     *
+     * @return String the name of the plugin.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Sets the name of the plugin and notifies
+     * PropertyChangeListeners of the change.
+     *
+     * @param newName the name of the plugin to set.
+     */
+    public void setName(final String newName) {
+        String oldName = this.name;
+        this.name = newName;
+        propertySupport.firePropertyChange("name", oldName, this.name);
+    }
+
+    /**
+     * 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 and notifies a
+     * relevant PropertyChangeListeners registered. This
+     * repository will be used by the plugin functionality.
+     *
+     * @param repository the logger repository that this plugin should affect.
+     */
+    public void setLoggerRepository(final LoggerRepository repository) {
+        Object oldValue = this.repository;
+        this.repository = repository;
+        firePropertyChange("loggerRepository", oldValue, this.repository);
+    }
+
+    /**
+     * Returns whether this plugin is Active or not.
+     *
+     * @return true/false
+     */
+    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(final Plugin testPlugin) {
+        return (repository == testPlugin.getLoggerRepository())
+                && ((this.name == null && testPlugin.getName() == null)
+                || (this.name != null
+                           && name.equals(testPlugin.getName())))
+                && this.getClass().equals(testPlugin.getClass());
+    }
+
+    /**
+     * Add property change listener.
+     * @param listener listener.
+     */
+    public final void addPropertyChangeListener(
+            final PropertyChangeListener listener) {
+        propertySupport.addPropertyChangeListener(listener);
+    }
+
+    /**
+     * Add property change listener for one property only.
+     * @param propertyName property name.
+     * @param listener listener.
+     */
+    public final void addPropertyChangeListener(
+            final String propertyName,
+            final PropertyChangeListener listener) {
+        propertySupport.addPropertyChangeListener(propertyName, listener);
+    }
+
+    /**
+     * Remove property change listener.
+     * @param listener listener.
+     */
+    public final void removePropertyChangeListener(
+            final PropertyChangeListener listener) {
+        propertySupport.removePropertyChangeListener(listener);
+    }
+
+    /**
+     * Remove property change listener on a specific property.
+     * @param propertyName property name.
+     * @param listener listener.
+     */
+    public final void removePropertyChangeListener(
+            final String propertyName,
+            final PropertyChangeListener listener) {
+        propertySupport.removePropertyChangeListener(propertyName, listener);
+    }
+
+    /**
+     * Fire a property change event to appropriate listeners.
+     * @param evt change event.
+     */
+    protected final void firePropertyChange(
+            final PropertyChangeEvent evt) {
+        propertySupport.firePropertyChange(evt);
+    }
+
+    /**
+     * Fire property change event to appropriate listeners.
+     * @param propertyName property name.
+     * @param oldValue old value.
+     * @param newValue new value.
+     */
+    protected final void firePropertyChange(
+            final String propertyName,
+            final boolean oldValue,
+            final boolean newValue) {
+        propertySupport.firePropertyChange(propertyName, oldValue, newValue);
+    }
+
+    /**
+     * Fire property change event to appropriate listeners.
+     * @param propertyName property name.
+     * @param oldValue old value.
+     * @param newValue new value.
+     */
+    protected final void firePropertyChange(
+            final String propertyName,
+            final int oldValue, final int newValue) {
+        propertySupport.firePropertyChange(propertyName, oldValue, newValue);
+    }
+
+    /**
+     * Fire property change event to appropriate listeners.
+     * @param propertyName property name.
+     * @param oldValue old value.
+     * @param newValue new value.
+     */
+    protected final void firePropertyChange(
+            final String propertyName,
+            final Object oldValue,
+            final Object newValue) {
+        propertySupport.firePropertyChange(propertyName, oldValue, newValue);
+    }
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/plugins/Receiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/plugins/Receiver.java?view=diff&rev=527629&r1=527628&r2=527629
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/plugins/Receiver.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/plugins/Receiver.java Wed Apr 11 12:29:39 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,96 +24,109 @@
 
 
 /**
-  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
-  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 &
-  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;
-  @author Paul Smith <ps...@apache.org>
-  @since 1.3
-*/
+ * Defines the base class for Receiver plugins.
+ * <p/>
+ * <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/>
+ * <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
+ * 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 &
+ * thresholds) are applied to the received logging event.
+ * <p/>
+ * <p>Receivers can also be used to "import" log messages from other
+ * logging packages into the log4j environment.
+ * <p/>
+ * <p>Receivers can be configured to post events to a given
+ * LoggerRepository.
+ * <p/>
+ * <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;
+ * @author Paul Smith (psmith@apache.org)
+ * @since 1.3
+ */
 public abstract class Receiver extends PluginSkeleton implements Thresholdable {
-	protected Level thresholdLevel;
-  
-  
-  
-  
-  /**
-    Sets the receiver theshold to the given level.
-    
-    @param level The threshold level events must equal or be greater
-    	than before further processing can be done. */
-  public void setThreshold(Level level) {
-    Level oldValue = this.thresholdLevel;
-    thresholdLevel = level;
-    firePropertyChange("threshold", oldValue, this.thresholdLevel);
-  }
-  
-  /**
-    Gets the current threshold setting of the receiver.
-    
-    @return Level The current threshold level of the receiver. */
-  public Level getThreshold() {
-    return thresholdLevel;
-  }
-
-  /**
-    Returns true if the given level is equals or greater than the current
-    threshold value of the receiver.
-    
-    @param level The level to test against the receiver threshold.
-    @return boolean True if level is equal or greater than the
-      receiver threshold. */
-	public boolean isAsSevereAsThreshold(Level level) {
-    return ((thresholdLevel == null) || level.isGreaterOrEqual(thresholdLevel));
-  }
-
-  /**
-    Posts the logging event to a logger in the configured logger
-    repository.
-
-    @param event the log event to post to the local log4j environment. */
-  public void doPost(LoggingEvent event) {
-    // if event does not meet threshold, exit now
-    if (!isAsSevereAsThreshold(event.getLevel())) {
-      return;
+    /**
+     * Threshold level.
+     */
+    protected Level thresholdLevel;
+
+    /**
+     * Create new instance.
+     */
+    protected Receiver() {
+        super();
+    }
+
+    /**
+     * Sets the receiver theshold to the given level.
+     *
+     * @param level The threshold level events must equal or be greater
+     *              than before further processing can be done.
+     */
+    public void setThreshold(final Level level) {
+        Level oldValue = this.thresholdLevel;
+        thresholdLevel = level;
+        firePropertyChange("threshold", oldValue, this.thresholdLevel);
     }
-      
-    // get the "local" logger for this event from the
-    // configured repository.
-    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())) {
-      // call the loggers appenders to process the event
-      localLogger.callAppenders(event);
+
+    /**
+     * Gets the current threshold setting of the receiver.
+     *
+     * @return Level The current threshold level of the receiver.
+     */
+    public Level getThreshold() {
+        return thresholdLevel;
+    }
+
+    /**
+     * Returns true if the given level is equals or greater than the current
+     * threshold value of the receiver.
+     *
+     * @param level The level to test against the receiver threshold.
+     * @return boolean True if level is equal or greater than the
+     *         receiver threshold.
+     */
+    public boolean isAsSevereAsThreshold(final Level level) {
+        return ((thresholdLevel == null)
+                || level.isGreaterOrEqual(thresholdLevel));
     }
+
+    /**
+     * Posts the logging event to a logger in the configured logger
+     * repository.
+     *
+     * @param event the log event to post to the local log4j environment.
+     */
+    public void doPost(final LoggingEvent event) {
+        // if event does not meet threshold, exit now
+        if (!isAsSevereAsThreshold(event.getLevel())) {
+            return;
+        }
+
+        // get the "local" logger for this event from the
+        // configured repository.
+        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())) {
+            // call the loggers appenders to process the event
+            localLogger.callAppenders(event);
+        }
   }
 }



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