psmith      2004/05/21 03:13:30

  Modified:    src/java/org/apache/log4j/chainsaw/vfs VFSPlugin.java
  Log:
  Looks like there was a race condition between the child directory locator thread

  that updates the Tree and the child file locator thread that populates the table.

  

  Properly synchronizing on the FileObject class is a must, and makes a lot of

  sense when you think about it.  Thanks to Mario for creating a test

  case that showed all was well with VFS.
  
  Revision  Changes    Path
  1.7       +24 -12    
logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSPlugin.java
  
  Index: VFSPlugin.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSPlugin.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- VFSPlugin.java    21 May 2004 04:22:09 -0000      1.6
  +++ VFSPlugin.java    21 May 2004 10:13:30 -0000      1.7
  @@ -252,13 +252,19 @@
   
                                public void run() {
                       try {
  -                        FileObject[] fos = vfsNode.getFileObject().getChildren();
  +                        FileObject fileObject = vfsNode.getFileObject();
  +                        FileObject[] fos = null;
  +                        synchronized(fileObject) {
  +                          fos = fileObject.getChildren();
  +                        }
                           Collection objects = new ArrayList(Arrays.asList(fos));
                           for (Iterator iter = objects.iterator(); iter.hasNext();) {
                                                        FileObject fo = (FileObject) 
iter.next();
  -                                                     if(fo.isReadable() && 
fo.getType().hasChildren()) {
  -                                                             iter.remove();
  -                            }
  +                                                     synchronized(fo) {
  +                                                       if(fo.isReadable() && 
fo.getType().hasChildren()) {
  +                                                         iter.remove();
  +                                                       }
  +                                                     }
                                                }
                           tableModel.setFiles(objects);
                       } catch (FileSystemException ex) {
  @@ -318,23 +324,29 @@
                   }
               });
               try {
  -                List children = new ArrayList(Arrays.asList(this.vfsNode
  -                        .getFileObject().getChildren()));
  +                FileObject fileObject = this.vfsNode
  +                        .getFileObject();
  +                List children = null;
  +                synchronized(fileObject) {
  +                  children = new ArrayList(Arrays.asList(fileObject.getChildren()));
  +                }
                   Collections.sort(children, VFSUtils.FILE_OBJECT_COMPARATOR);
                   USER_MESSAGE_LOGGER.debug("Found " + children.size() + " children");
                   for (Iterator iter = children.iterator(); iter.hasNext();) {
                       FileObject child = (FileObject) iter.next();
                       // we only add non-leaf nodes, as the leaf nodes get
                       // displayed in the table
  -                    if (child.getType().hasChildren()) {
  +                    synchronized(child) {
  +                      if (child.getType().hasChildren()) {
                           final DefaultMutableTreeNode childNode = new 
DefaultMutableTreeNode(
  -                                new VFSNode(child.getName().getBaseName(),
  -                                        child));
  +                            new VFSNode(child.getName().getBaseName(),
  +                                child));
                           SwingUtilities.invokeLater(new Runnable() {
  -                            public void run() {
  -                                node.add(childNode);
  -                            }
  +                          public void run() {
  +                            node.add(childNode);
  +                          }
                           });
  +                      }
                       }
                   }
               } catch (Exception e) {
  
  
  

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

Reply via email to