psmith      2003/06/17 18:35:25

  Modified:    src/java/org/apache/log4j/chainsaw LogUI.java
  Log:
  During the exiting of the application, there was no effort expended
  to letting Log4j shutdown correctly.
  
  Modified to shutdown the PluginRepository and LogManager (I assume
  I need to explicit call both?).
  
  Also placed a simple progress bar to indicate that something IS actually
  happening, as sometimes shutting down some receivers could take
  a little while if there is any network related things going on.
  
  Revision  Changes    Path
  1.102     +74 -28    
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- LogUI.java        17 Jun 2003 17:26:56 -0000      1.101
  +++ LogUI.java        18 Jun 2003 01:35:25 -0000      1.102
  @@ -132,6 +132,7 @@
   import javax.swing.JTable;
   import javax.swing.JTextField;
   import javax.swing.JToolBar;
  +import javax.swing.JWindow;
   import javax.swing.KeyStroke;
   import javax.swing.ListSelectionModel;
   import javax.swing.SwingUtilities;
  @@ -517,7 +518,7 @@
         }
       }
   
  -    System.exit(0);
  +    shutdown();
     }
   
     void addWelcomePanel() {
  @@ -547,7 +548,40 @@
      * Shutsdown by ensuring the Appender gets a chance to close.
      */
     private void shutdown() {
  -    handler.close();
  +    JWindow progress = new JWindow();
  +    final ProgressPanel panel = new ProgressPanel(1, 3, "Shutting down");
  +    progress.getContentPane().add(panel);
  +    progress.pack();
  +    progress.setLocationRelativeTo(this);
  +    progress.setVisible(true);
  +
  +    Runnable runnable =
  +      new Runnable() {
  +        public void run() {
  +          try {
  +            int progress = 1;
  +            handler.close();
  +            panel.setProgress(progress++);
  +
  +            Thread.sleep(250);
  +
  +            PluginRegistry.stopAllPlugins();
  +            panel.setProgress(progress++);
  +
  +            Thread.sleep(250);
  +
  +            LogManager.shutdown();
  +            panel.setProgress(progress++);
  +            Thread.sleep(250);
  +          } catch (Exception e) {
  +            e.printStackTrace();
  +          }
  +
  +          System.exit(0);
  +        }
  +      };
  +
  +    new Thread(runnable).start();
     }
   
     /**
  @@ -756,23 +790,26 @@
         new File(
           SettingsManager.getInstance().getSettingsDirectory() + File.separator
           + ident + ChainsawConstants.SETTINGS_EXTENSION);
  -      if (f.exists()) {
  -        try {
  -          s = new ObjectInputStream(
  -              new BufferedInputStream(new FileInputStream(f)));
  -          d = (DisplayFilter) s.readObject();
  -          } catch (IOException ioe) {ioe.printStackTrace();
  -          } catch (ClassNotFoundException cnfe) {
  -              cnfe.printStackTrace();
  -          }
  -        finally {
  -          if (s != null) {
  -            try {
  -              s.close();
  -            } catch (IOException ioe) {ioe.printStackTrace();}
  +
  +    if (f.exists()) {
  +      try {
  +        s = new ObjectInputStream(
  +            new BufferedInputStream(new FileInputStream(f)));
  +        d = (DisplayFilter) s.readObject();
  +      } catch (IOException ioe) {
  +        ioe.printStackTrace();
  +      } catch (ClassNotFoundException cnfe) {
  +        cnfe.printStackTrace();
  +      } finally {
  +        if (s != null) {
  +          try {
  +            s.close();
  +          } catch (IOException ioe) {
  +            ioe.printStackTrace();
             }
           }
         }
  +    }
   
       if (d == null) {
         d = new DisplayFilter(ident);
  @@ -967,6 +1004,7 @@
         UIManager.setLookAndFeel(lookAndFeelClassName);
         SwingUtilities.updateComponentTreeUI(this);
         tbms.lookAndFeelUpdated();
  +
         if (tbms != null) {
           tbms.stateChange();
         }
  @@ -1858,15 +1896,18 @@
           }
   
           o.flush();
  -      } catch (FileNotFoundException fnfe) {fnfe.printStackTrace();
  -      } catch (IOException ioe) {ioe.printStackTrace();
  -      }
  -      finally {
  +      } catch (FileNotFoundException fnfe) {
  +        fnfe.printStackTrace();
  +      } catch (IOException ioe) {
  +        ioe.printStackTrace();
  +      } finally {
           try {
             if (o != null) {
               o.close();
             }
  -        } catch (IOException ioe) {ioe.printStackTrace();}
  +        } catch (IOException ioe) {
  +          ioe.printStackTrace();
  +        }
         }
       }
   
  @@ -1965,7 +2006,7 @@
             + File.separator + ident + COLUMNS_EXTENSION);
   
         if (f.exists()) {
  -        ArrayList newColumns = new ArrayList(); 
  +        ArrayList newColumns = new ArrayList();
   
           TableColumnData temp = null;
           ObjectInputStream s = null;
  @@ -1981,17 +2022,21 @@
               tc.setHeaderValue(temp.getColName());
               newColumns.add(tc);
             }
  -        } catch (EOFException eof) {//end of file - ignore..
  -        } catch (IOException ioe) {ioe.printStackTrace();
  -        } catch (ClassNotFoundException cnfe) {cnfe.printStackTrace();
  +        } catch (EOFException eof) { //end of file - ignore..
  +        }catch (IOException ioe) {
  +          ioe.printStackTrace();
  +        } catch (ClassNotFoundException cnfe) {
  +          cnfe.printStackTrace();
           } finally {
             if (s != null) {
               try {
                 s.close();
  -            } catch (IOException ioe) {ioe.printStackTrace();
  +            } catch (IOException ioe) {
  +              ioe.printStackTrace();
               }
             }
           }
  +
           //only remove columns and add serialized columns if 
           //at least one column was read from the file
           if (newColumns.size() > 0) {
  @@ -1999,8 +2044,9 @@
             for (int i = model.getColumnCount() - 1; i > -1; i--) {
               model.removeColumn(model.getColumn(i));
             }
  -          for (Iterator iter=newColumns.iterator();iter.hasNext();) {
  -            model.addColumn((TableColumn)iter.next());
  +
  +          for (Iterator iter = newColumns.iterator(); iter.hasNext();) {
  +            model.addColumn((TableColumn) iter.next());
             }
           }
         }
  
  
  

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

Reply via email to