logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject cvs commit: jakarta-log4j/src/java/org/apache/log4j/chainsaw LogUI.java
Date Thu, 18 Sep 2003 04:03:38 GMT
psmith      2003/09/17 21:03:38

  Modified:    src/java/org/apache/log4j/chainsaw LogUI.java
  Log:
  Things that like to react when new Plugins are started/stopped
  are now decoupled from the things that actually
  create/stop them.  Much cleaner.
  
  Revision  Changes    Path
  1.31      +107 -89   jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- LogUI.java	17 Sep 2003 01:25:23 -0000	1.30
  +++ LogUI.java	18 Sep 2003 04:03:38 -0000	1.31
  @@ -49,22 +49,6 @@
   
   package org.apache.log4j.chainsaw;
   
  -import org.apache.log4j.Level;
  -import org.apache.log4j.LogManager;
  -import org.apache.log4j.Priority;
  -import org.apache.log4j.UtilLoggingLevel;
  -import org.apache.log4j.chainsaw.icons.ChainsawIcons;
  -import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
  -import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
  -import org.apache.log4j.chainsaw.prefs.SettingsListener;
  -import org.apache.log4j.chainsaw.prefs.SettingsManager;
  -import org.apache.log4j.helpers.LogLog;
  -import org.apache.log4j.helpers.OptionConverter;
  -import org.apache.log4j.net.SocketNodeEventListener;
  -import org.apache.log4j.net.SocketReceiver;
  -import org.apache.log4j.plugins.PluginRegistry;
  -import org.apache.log4j.plugins.Receiver;
  -
   import java.awt.BorderLayout;
   import java.awt.Component;
   import java.awt.Dimension;
  @@ -79,20 +63,15 @@
   import java.awt.event.MouseEvent;
   import java.awt.event.WindowAdapter;
   import java.awt.event.WindowEvent;
  -
   import java.beans.PropertyChangeEvent;
   import java.beans.PropertyChangeListener;
  -
   import java.io.BufferedInputStream;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.ObjectInputStream;
  -
   import java.lang.reflect.Method;
  -
   import java.net.URL;
  -
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -118,6 +97,24 @@
   import javax.swing.event.ChangeListener;
   import javax.swing.event.EventListenerList;
   
  +import org.apache.log4j.Level;
  +import org.apache.log4j.LogManager;
  +import org.apache.log4j.Priority;
  +import org.apache.log4j.UtilLoggingLevel;
  +import org.apache.log4j.chainsaw.icons.ChainsawIcons;
  +import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
  +import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
  +import org.apache.log4j.chainsaw.prefs.SettingsListener;
  +import org.apache.log4j.chainsaw.prefs.SettingsManager;
  +import org.apache.log4j.helpers.LogLog;
  +import org.apache.log4j.helpers.OptionConverter;
  +import org.apache.log4j.net.SocketNodeEventListener;
  +import org.apache.log4j.plugins.Plugin;
  +import org.apache.log4j.plugins.PluginEvent;
  +import org.apache.log4j.plugins.PluginListener;
  +import org.apache.log4j.plugins.PluginRegistry;
  +import org.apache.log4j.plugins.Receiver;
  +
   
   /**
    * The main entry point for Chainsaw, this class represents the first frame
  @@ -345,6 +342,49 @@
      * layout, table columns, and sets itself viewable.
      */
     public void activateViewer() {
  +    final SocketNodeEventListener socketListener =
  +      new SocketNodeEventListener() {
  +        public void socketOpened(String remoteInfo) {
  +          statusBar.remoteConnectionReceived(remoteInfo);
  +        }
  +
  +        public void socketClosedEvent(Exception e) {
  +          statusBar.setMessage("Collection lost! :: " + e.getMessage());
  +        }
  +      };
  +
  +    PluginListener pluginListener =
  +      new PluginListener() {
  +        public void pluginStarted(PluginEvent e) {
  +          statusBar.setMessage(e.getPlugin().getName() + " started!");
  +        }
  +
  +        Method getSocketNodeEventListenerMethod(Plugin p) {
  +          try {
  +            return p.getClass().getMethod(
  +              "removeSocketNodeEventListener",
  +              new Class[] { SocketNodeEventListener.class });
  +          } catch (Exception e) {
  +            return null;
  +          }
  +        }
  +
  +        public void pluginStopped(PluginEvent e) {
  +          Method method = getSocketNodeEventListenerMethod(e.getPlugin());
  +
  +          if (method != null) {
  +            try {
  +              method.invoke(e.getPlugin(), new Object[] { socketListener });
  +            } catch (Exception ex) {
  +              LogLog.error("Failed to remove SocketNodeEventListener", ex);
  +            }
  +          }
  +		  statusBar.setMessage(e.getPlugin().getName() + " stopped!");
  +        }
  +      };
  +
  +    PluginRegistry.addPluginListener(pluginListener);
  +
       getSettingsManager().configure(
         new SettingsListener() {
           public void loadSettings(LoadSettingsEvent event) {
  @@ -400,30 +440,6 @@
   
       initGUI();
   
  -    /**
  -     * Get all the SocketReceivers and configure a new SocketNodeEventListener
  -     * so we can get notified of new Sockets
  -     */
  -    List list =
  -      PluginRegistry.getPlugins(
  -        LogManager.getLoggerRepository(), SocketReceiver.class);
  -    final SocketNodeEventListener socketListener =
  -      new SocketNodeEventListener() {
  -        public void socketOpened(String remoteInfo) {
  -          statusBar.remoteConnectionReceived(remoteInfo);
  -        }
  -
  -        public void socketClosedEvent(Exception e) {
  -          statusBar.setMessage("Collection lost! :: " + e.getMessage());
  -        }
  -      };
  -
  -    for (Iterator iter = list.iterator(); iter.hasNext();) {
  -      SocketReceiver item = (SocketReceiver) iter.next();
  -      LogLog.debug("Adding listener for " + item.getName());
  -      item.addSocketNodeEventListener(socketListener);
  -    }
  -
       List utilList = UtilLoggingLevel.getAllPossibleLevels();
   
       // TODO: Replace the array list creating with the standard way of retreiving the Level
set. (TBD)
  @@ -553,14 +569,15 @@
         });
   
       pack();
  -    
  -    this.handler.addPropertyChangeListener("dataRate", new PropertyChangeListener(){
   
  -		public void propertyChange(PropertyChangeEvent evt) {
  -			double dataRate = ((Double)evt.getNewValue()).doubleValue();
  -			statusBar.setDataRate(dataRate);
  -			
  -		}});
  +    this.handler.addPropertyChangeListener(
  +      "dataRate",
  +      new PropertyChangeListener() {
  +        public void propertyChange(PropertyChangeEvent evt) {
  +          double dataRate = ((Double) evt.getNewValue()).doubleValue();
  +          statusBar.setDataRate(dataRate);
  +        }
  +      });
   
       getSettingsManager().addSettingsListener(this);
       getSettingsManager().addSettingsListener(getToolBarAndMenus());
  @@ -581,41 +598,43 @@
     }
   
     /**
  -   * Displays a warning dialog about having no Receivers defined
  -   * and allows the user to choose some options for configuration
  -   */
  +    * Displays a warning dialog about having no Receivers defined
  +    * and allows the user to choose some options for configuration
  +    */
     private void showNoReceiversWarningPanel() {
  -	final NoReceiversWarningPanel noReceiversWarningPanel =
  -	 new NoReceiversWarningPanel();
  +    final NoReceiversWarningPanel noReceiversWarningPanel =
  +      new NoReceiversWarningPanel();
  +
  +    final SettingsListener sl =
  +      new SettingsListener() {
  +        public void loadSettings(LoadSettingsEvent event) {
  +          int size = event.asInt("SavedConfigs.Size");
  +          Object[] configs = new Object[size];
   
  -	final SettingsListener sl = new SettingsListener() {
  -	  public void loadSettings(LoadSettingsEvent event) {
  -		int size = event.asInt("SavedConfigs.Size");
  -		Object[] configs = new Object[size];
  -
  -		for (int i = 0; i < size; i++) {
  -		  configs[i] = event.getSetting("SavedConfigs." + i);
  -		}
  -
  -		noReceiversWarningPanel.getModel().setRememberedConfigs(configs);
  -	  }
  -
  -	  public void saveSettings(SaveSettingsEvent event) {
  -		Object[] configs =
  -		  noReceiversWarningPanel.getModel().getRememberedConfigs();
  -		event.saveSetting("SavedConfigs.Size", configs.length);
  -
  -		for (int i = 0; i < configs.length; i++) {
  -		  event.saveSetting("SavedConfigs." + i, configs[i].toString());
  -		}
  -	  }
  -	};
  -   /**
  -	* This listener sets up the NoReciversWarningPanel and
  -	* loads saves the configs/logfiles
  -	*/
  -   getSettingsManager().addSettingsListener(sl);
  -   getSettingsManager().configure(sl);
  +          for (int i = 0; i < size; i++) {
  +            configs[i] = event.getSetting("SavedConfigs." + i);
  +          }
  +
  +          noReceiversWarningPanel.getModel().setRememberedConfigs(configs);
  +        }
  +
  +        public void saveSettings(SaveSettingsEvent event) {
  +          Object[] configs =
  +            noReceiversWarningPanel.getModel().getRememberedConfigs();
  +          event.saveSetting("SavedConfigs.Size", configs.length);
  +
  +          for (int i = 0; i < configs.length; i++) {
  +            event.saveSetting("SavedConfigs." + i, configs[i].toString());
  +          }
  +        }
  +      };
  +
  +    /**
  +         * This listener sets up the NoReciversWarningPanel and
  +         * loads saves the configs/logfiles
  +         */
  +    getSettingsManager().addSettingsListener(sl);
  +    getSettingsManager().configure(sl);
   
       SwingUtilities.invokeLater(
         new Runnable() {
  @@ -666,9 +685,6 @@
   
                 PluginRegistry.startPlugin(simpleReceiver);
                 receiversPanel.updateReceiverTreeInDispatchThread();
  -              getStatusBar().setMessage(
  -                "Simple Receiver created, started, and listening on port  "
  -                + port + " (using " + receiverClass.getName() + ")");
               } catch (Exception e) {
                 LogLog.error("Error creating Receiver", e);
                 getStatusBar().setMessage(
  @@ -690,7 +706,9 @@
                       } catch (Exception e) {
                         LogLog.error("Error initializing Log4j", e);
                       }
  -                    LogManager.getLoggerRepository().getRootLogger().addAppender(handler);
  +
  +                    LogManager.getLoggerRepository().getRootLogger()
  +                              .addAppender(handler);
   
                       receiversPanel.updateReceiverTreeInDispatchThread();
                     }
  
  
  

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


Mime
View raw message