psmith      2004/05/04 15:45:04

  Modified:    src/java/org/apache/log4j/chainsaw/receivers
                        ReceiversPanel.java
               src/java/org/apache/log4j/chainsaw LogUI.java
                        ChainsawAppenderHandler.java
               src/java/org/apache/log4j/chainsaw/help Tutorial.java
  Log:
  Changes to Chainsaw so that it can support how the PluginRegistry is now located.
  
  Code compiles, Chainsaw can run, and tested Tutorial receivers etc, seems to work 
pretty well.
  
  HOWEVER, found 2 issues during this still to be resolved.
  
  1) Any Receiver started by the automatic external configuration file APPEAR in the 
Receiver Tree,
  and can be stopped, but the GUI does not remove the visual node from the tree, which 
is confusing.
  I have left that as a TODO.
  
  2) Stopping the Tutorial causes an ArrayIndexOutOfBoundsException within Swing, 
possibly
  because the removal of the tree node is not being done in the correct thread, or 
something. Not sure yet.
  
  This is all I could do at this time.  Sorry.
  
  Revision  Changes    Path
  1.14      +17 -10    
logging-log4j/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
  
  Index: ReceiversPanel.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ReceiversPanel.java       1 May 2004 09:18:48 -0000       1.13
  +++ ReceiversPanel.java       4 May 2004 22:45:04 -0000       1.14
  @@ -99,12 +99,21 @@
     private final PluginPropertyEditorPanel pluginEditorPanel =
       new PluginPropertyEditorPanel();
     
  +  private final PluginRegistry pluginRegistry;
  +  
   
     public ReceiversPanel() {
       super(new BorderLayout());
  -
  +    pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();
       final ReceiversTreeModel model = new ReceiversTreeModel();
  -    PluginRegistry.addPluginListener(model);
  +    
  +    /**
  +     * TODO Ccurrently the model will not have a correctly populated
  +     * internal plugin map, because some plugins will already have started, so
  +     * when you stop a plugin, it DOES stop, but the Tree seems to keep displaying
  +     * it because it can't find the TreeNode for it within it's internal map.
  +     */
  +    pluginRegistry.addPluginListener(model);
       receiversTree.setModel(model);
   
       receiversTree.setExpandsSelectedPaths(true);
  @@ -272,14 +281,13 @@
                   new Runnable() {
                     public void run() {
                       Collection allReceivers =
  -                      PluginRegistry.getPlugins(
  -                        LogManager.getLoggerRepository(), Receiver.class);
  +                        pluginRegistry.getPlugins(Receiver.class);
   
                       for (Iterator iter = allReceivers.iterator();
                           iter.hasNext();) {
                         Receiver item = (Receiver) iter.next();
  -                      PluginRegistry.stopPlugin(item);
  -                      PluginRegistry.startPlugin(item);
  +                      pluginRegistry.stopPlugin(item.getName());
  +                      pluginRegistry.startPlugin(item);
                       }
   
                       updateReceiverTreeInDispatchThread();
  @@ -336,8 +344,7 @@
        * add this listener to all SocketReceivers
        */
       List socketReceivers =
  -      PluginRegistry.getPlugins(
  -        LogManager.getLoggerRepository(), SocketReceiver.class);
  +      pluginRegistry.getPlugins(SocketReceiver.class);
   
       for (Iterator iter = socketReceivers.iterator(); iter.hasNext();) {
         SocketReceiver element = (SocketReceiver) iter.next();
  @@ -490,7 +497,7 @@
   
               if (receivers != null) {
                 for (int i = 0; i < receivers.length; i++) {
  -                PluginRegistry.stopPlugin(receivers[i]);
  +                pluginRegistry.stopPlugin(receivers[i].getName());
                 }
               }
             }
  @@ -615,7 +622,7 @@
                         public void actionPerformed(ActionEvent e2) {
                           dialog.dispose();
                           Plugin plugin = panel.getPlugin();
  -                        PluginRegistry.startPlugin(plugin);
  +                        pluginRegistry.startPlugin(plugin);
                           MessageCenter.getInstance().addMessage("Plugin '" + 
plugin.getName() + "' started");
                         }
                       });
  
  
  
  1.88      +38 -34    logging-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- LogUI.java        4 May 2004 19:04:38 -0000       1.87
  +++ LogUI.java        4 May 2004 22:45:04 -0000       1.88
  @@ -181,6 +181,7 @@
      */
     private EventListenerList shutdownListenerList = new EventListenerList();
     private WelcomePanel welcomePanel;
  +  private PluginRegistry pluginRegistry;
   
     /**
      * Constructor which builds up all the visual elements of the frame including
  @@ -468,6 +469,42 @@
      * table columns, and sets itself viewable.
      */
     public void activateViewer() {
  +    
  +      getSettingsManager().configure(
  +              new SettingsListener() {
  +                public void loadSettings(LoadSettingsEvent event) {
  +                  String configFile = event.getSetting(LogUI.CONFIG_FILE_TO_USE);
  +
  +                  //if both a config file are defined and a log4j.configuration 
property
  +                  // are set,
  +                  //don't use configFile's configuration
  +                  if (
  +                    (configFile != null) && !configFile.trim().equals("")
  +                      && (System.getProperty("log4j.configuration") == null)) {
  +                    try {
  +                      URL url = new URL(configFile);
  +                      OptionConverter.selectAndConfigure(
  +                        url, null, LogManager.getLoggerRepository());
  +
  +                      if (LogUI.this.getStatusBar() != null) {
  +                        MessageCenter.getInstance().getLogger().info(
  +                          "Configured Log4j using remembered URL :: " + url);
  +                      }
  +
  +                      LogUI.this.configURLToUse = url;
  +                    } catch (Exception e) {
  +                      MessageCenter.getInstance().getLogger().error(
  +                        "error occurred initializing log4j", e);
  +                    }
  +                  }
  +                }
  +
  +                public void saveSettings(SaveSettingsEvent event) {
  +                  //required because of SettingsListener interface..not used during 
load
  +                }
  +              });
  +
  +    this.pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();  
       initGUI();
   
       initPrefModelListeners();
  @@ -490,43 +527,10 @@
           }
         });
   
  -    initSocketConnectionListener();
   
  -    getSettingsManager().configure(
  -      new SettingsListener() {
  -        public void loadSettings(LoadSettingsEvent event) {
  -          String configFile = event.getSetting(LogUI.CONFIG_FILE_TO_USE);
  -
  -          //if both a config file are defined and a log4j.configuration property
  -          // are set,
  -          //don't use configFile's configuration
  -          if (
  -            (configFile != null) && !configFile.trim().equals("")
  -              && (System.getProperty("log4j.configuration") == null)) {
  -            try {
  -              URL url = new URL(configFile);
  -              OptionConverter.selectAndConfigure(
  -                url, null, LogManager.getLoggerRepository());
  -
  -              if (LogUI.this.getStatusBar() != null) {
  -                MessageCenter.getInstance().getLogger().info(
  -                  "Configured Log4j using remembered URL :: " + url);
  -              }
  -
  -              LogUI.this.configURLToUse = url;
  -            } catch (Exception e) {
  -              MessageCenter.getInstance().getLogger().error(
  -                "error occurred initializing log4j", e);
  -            }
  -          }
  -        }
   
  -        public void saveSettings(SaveSettingsEvent event) {
  -          //required because of SettingsListener interface..not used during load
  -        }
  -      });
  +    initSocketConnectionListener();
   
  -    final PluginRegistry pluginRegistry = 
LogManager.getLoggerRepository().getPluginRegistry();
       if (pluginRegistry.getPlugins(Receiver.class).size() == 0) {
         noReceiversDefined = true;
       }
  
  
  
  1.18      +1 -1      
logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java
  
  Index: ChainsawAppenderHandler.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ChainsawAppenderHandler.java      5 Apr 2004 07:22:12 -0000       1.17
  +++ ChainsawAppenderHandler.java      4 May 2004 22:45:04 -0000       1.18
  @@ -165,7 +165,7 @@
       LogManager.getRootLogger().addAppender(handler);
   
       SocketReceiver receiver = new SocketReceiver(4445);
  -    PluginRegistry.startPlugin(receiver);
  +    LogManager.getLoggerRepository().getPluginRegistry().startPlugin(receiver);
   
       Thread.sleep(60000);
     }
  
  
  
  1.5       +6 -3      
logging-log4j/src/java/org/apache/log4j/chainsaw/help/Tutorial.java
  
  Index: Tutorial.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/help/Tutorial.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Tutorial.java     27 Feb 2004 16:47:31 -0000      1.4
  +++ Tutorial.java     4 May 2004 22:45:04 -0000       1.5
  @@ -16,6 +16,7 @@
   
   package org.apache.log4j.chainsaw.help;
   
  +import org.apache.log4j.LogManager;
   import org.apache.log4j.chainsaw.Generator;
   import org.apache.log4j.plugins.Plugin;
   import org.apache.log4j.plugins.PluginRegistry;
  @@ -35,8 +36,10 @@
         Plugin p1 = new Generator("Generator 1");
         Plugin p2 = new Generator("Generator 2");
         Plugin p3 = new Generator("Generator 3");
  -      PluginRegistry.startPlugin(p1);
  -      PluginRegistry.startPlugin(p2);
  -      PluginRegistry.startPlugin(p3);
  +      
  +      PluginRegistry pluginRegistry = 
LogManager.getLoggerRepository().getPluginRegistry();
  +      pluginRegistry.startPlugin(p1);
  +      pluginRegistry.startPlugin(p2);
  +      pluginRegistry.startPlugin(p3);
     }
   }
  
  
  

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

Reply via email to