Category's SourceRoots are used as keys to a map, hold them in the Category. Hold classpath via SoftReference.
authorJan Lahoda <jlahoda@netbeans.org>
Sat, 29 Dec 2012 12:34:23 +0100
changeset 917f17fbf567e39
parent 916 f50f893daa88
child 918 d15da9d366a5
Category's SourceRoots are used as keys to a map, hold them in the Category. Hold classpath via SoftReference.
remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/CategoryStorage.java
remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/SourceRoot.java
     1.1 --- a/remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/CategoryStorage.java	Tue Dec 11 15:10:16 2012 +0100
     1.2 +++ b/remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/CategoryStorage.java	Sat Dec 29 12:34:23 2012 +0100
     1.3 @@ -163,7 +163,7 @@
     1.4              Logger.getLogger(CategoryStorage.class.getName()).log(Level.SEVERE, null, ex);
     1.5          }
     1.6  
     1.7 -        return result;
     1.8 +        return sourceRoots = result;
     1.9      }
    1.10  
    1.11      private final Map<String, Reference<FileSystem>> embeddedJar2FileSystem = new HashMap<String, Reference<FileSystem>>();
     2.1 --- a/remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/SourceRoot.java	Tue Dec 11 15:10:16 2012 +0100
     2.2 +++ b/remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/SourceRoot.java	Sat Dec 29 12:34:23 2012 +0100
     2.3 @@ -44,6 +44,8 @@
     2.4  import java.io.File;
     2.5  import java.io.IOException;
     2.6  import java.io.InputStream;
     2.7 +import java.lang.ref.Reference;
     2.8 +import java.lang.ref.SoftReference;
     2.9  import java.util.ArrayList;
    2.10  import java.util.Collection;
    2.11  import java.util.Properties;
    2.12 @@ -59,7 +61,7 @@
    2.13  public class SourceRoot {
    2.14      
    2.15      private static final Logger LOG = Logger.getLogger(SourceRoot.class.getName());
    2.16 - private final CategoryStorage category;
    2.17 +    private final CategoryStorage category;
    2.18      private final String relativePath;
    2.19      private final String code;
    2.20  
    2.21 @@ -77,14 +79,15 @@
    2.22          return relativePath;
    2.23      }
    2.24  
    2.25 -    private Collection<FileObject> classPath; //XXX: soft reference?
    2.26 +    private Reference<Collection<FileObject>> classPath;
    2.27  
    2.28      public synchronized Collection<FileObject> getClassPath() {
    2.29 -        if (classPath == null) {
    2.30 -            classPath = computeClassPath();
    2.31 +        Collection<FileObject> cp = classPath != null ? classPath.get() : null;
    2.32 +        if (cp == null) {
    2.33 +            classPath = new SoftReference<Collection<FileObject>>(cp = computeClassPath());
    2.34          }
    2.35  
    2.36 -        return classPath;
    2.37 +        return cp;
    2.38      }
    2.39  
    2.40      public String getCode() {