This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 41012
Collapse All | Expand All

(-)src/org/netbeans/modules/vcscore/cache/CacheDir.java (-36 / +11 lines)
Lines 113-132 Link Here
113
    /** return all subdirectories in an array
113
    /** return all subdirectories in an array
114
     */
114
     */
115
    public CacheDir[] getSubDirs() {
115
    public CacheDir[] getSubDirs() {
116
        LinkedList col = new LinkedList();
116
        List col = new ArrayList(childDirs.keySet().size());
117
        CacheHandler handler = CacheHandler.getInstance();
118
        synchronized (CHILD_FILES_LOCK) {
117
        synchronized (CHILD_FILES_LOCK) {
119
            for (Iterator it = new ArrayList(childDirs.keySet()).iterator(); it.hasNext(); ) {
118
            for (Iterator it = new ArrayList(childDirs.keySet()).iterator(); it.hasNext(); ) {
120
                String name = (String) it.next();
119
                String name = (String) it.next();
121
                Reference rDir = (Reference) childDirs.get(name);
120
                Reference rDir = (Reference) childDirs.get(name);
122
                CacheDir cDir = (CacheDir) rDir.get();
121
                CacheDir cDir = (CacheDir) rDir.get();
123
                if (cDir == null) {
122
                if (cDir == null) {
124
                    CacheFile.PersistentData data = handler.getReferencedData(rDir);
123
                    cDir = readDirFromDisk(name);
125
                    if (data != null) {
126
                        cDir = (CacheDir) createChildFromData(data);
127
                    } else {
128
                        cDir = readDirFromDisk(name);
129
                    }
130
                    cDir.setParent(this);
124
                    cDir.setParent(this);
131
                    childDirs.put(name, createReference(cDir));
125
                    childDirs.put(name, createReference(cDir));
132
                }
126
                }
Lines 152-163 Link Here
152
            if (rDir == null) return null;
146
            if (rDir == null) return null;
153
            CacheDir cDir = (CacheDir) rDir.get();
147
            CacheDir cDir = (CacheDir) rDir.get();
154
            if (cDir == null) {
148
            if (cDir == null) {
155
                CacheFile.PersistentData data = CacheHandler.getInstance().getReferencedData(rDir);
149
                cDir = readDirFromDisk(name);
156
                if (data != null) {
157
                    cDir = (CacheDir) createChildFromData(data);
158
                } else {
159
                    cDir = readDirFromDisk(name);
160
                }
161
                cDir.setParent(this);
150
                cDir.setParent(this);
162
                childDirs.put(name, createReference(cDir));
151
                childDirs.put(name, createReference(cDir));
163
                getCacheObject().registerDir(cDir);
152
                getCacheObject().registerDir(cDir);
Lines 306-313 Link Here
306
    //----- file stuff -------------------------------------------------------
295
    //----- file stuff -------------------------------------------------------
307
296
308
    public CacheFile[] getFiles() {
297
    public CacheFile[] getFiles() {
309
        LinkedList col = new LinkedList();
298
        List col = new ArrayList(childFiles.keySet().size());
310
        CacheHandler handler = CacheHandler.getInstance();
311
        synchronized (CHILD_FILES_LOCK) {
299
        synchronized (CHILD_FILES_LOCK) {
312
            String cacheFilePath = getCacheFileName();
300
            String cacheFilePath = getCacheFileName();
313
            BufferedReader in = null;
301
            BufferedReader in = null;
Lines 326-342 Link Here
326
                    Reference rFile = (Reference) childFiles.get(name);
314
                    Reference rFile = (Reference) childFiles.get(name);
327
                    CacheFile cFile = (CacheFile) rFile.get();
315
                    CacheFile cFile = (CacheFile) rFile.get();
328
                    if (cFile == null) {
316
                    if (cFile == null) {
329
                        CacheFile.PersistentData data = handler.getReferencedData(rFile);
317
                        if (in != null) {
330
                        if (data != null) {
318
                            in.mark( (int)cacheFile.length());
331
                            cFile = (CacheFile) createChildFromData(data);
319
                        }
332
                        } else {
320
                        cFile = readFileFromDisk(name, in);
333
                            if (in != null) {
321
                        if (in != null) {
334
                                in.mark( (int)cacheFile.length());
322
                            in.reset();
335
                            }
336
                            cFile = readFileFromDisk(name, in);
337
                            if (in != null) {
338
                                in.reset();
339
                            }
340
                        }
323
                        }
341
                        cFile.setParent(this);
324
                        cFile.setParent(this);
342
                        childFiles.put(name, createReference(cFile));
325
                        childFiles.put(name, createReference(cFile));
Lines 380-391 Link Here
380
            if (rFile == null) return null;
363
            if (rFile == null) return null;
381
            CacheFile cFile = (CacheFile) rFile.get();
364
            CacheFile cFile = (CacheFile) rFile.get();
382
            if (cFile == null) {
365
            if (cFile == null) {
383
                CacheFile.PersistentData data = CacheHandler.getInstance().getReferencedData(rFile);
366
                cFile = readFileFromDisk(name);
384
                if (data != null) {
385
                    cFile = (CacheFile) createChildFromData(data);
386
                } else {
387
                    cFile = readFileFromDisk(name);
388
                }
389
                cFile.setParent(this);
367
                cFile.setParent(this);
390
                childFiles.put(name, createReference(cFile));
368
                childFiles.put(name, createReference(cFile));
391
            }
369
            }
Lines 470-477 Link Here
470
    }
448
    }
471
    
449
    
472
    
450
    
473
    protected abstract CacheFile createChildFromData(CacheFile.PersistentData data);
474
    
475
    /** sets the strategy level taht this directory resides at.
451
    /** sets the strategy level taht this directory resides at.
476
     */
452
     */
477
    public final void setAppliedLevel(int strat) {
453
    public final void setAppliedLevel(int strat) {
Lines 781-787 Link Here
781
        CacheHandler handler = CacheHandler.getInstance();
757
        CacheHandler handler = CacheHandler.getInstance();
782
        Reference ref = new CacheReference(cFile, handler.getCacheFileReferenceQueue());
758
        Reference ref = new CacheReference(cFile, handler.getCacheFileReferenceQueue());
783
                      //new WeakReference(cFile, handler.getCacheFileReferenceQueue());
759
                      //new WeakReference(cFile, handler.getCacheFileReferenceQueue());
784
        if (cFile != null) handler.addReferencedData(ref, cFile.getPersistentData());
785
        return ref;
760
        return ref;
786
        //return new /*java.lang.ref.WeakReference(cFile);//*/CacheFileReference(cFile);
761
        //return new /*java.lang.ref.WeakReference(cFile);//*/CacheFileReference(cFile);
787
    }
762
    }
(-)src/org/netbeans/modules/vcscore/cache/CacheHandler.java (-10 lines)
Lines 94-100 Link Here
94
    private ArrayList listeners = new ArrayList ();
94
    private ArrayList listeners = new ArrayList ();
95
    
95
    
96
    private Map cacheMap;
96
    private Map cacheMap;
97
    private final Map persistentData;
98
    private final ReferenceQueue cacheQueue;
97
    private final ReferenceQueue cacheQueue;
99
    
98
    
100
    /** Holds cache files and direcories to permit their garbage collection only after
99
    /** Holds cache files and direcories to permit their garbage collection only after
Lines 105-111 Link Here
105
    /** Creates new CacheHandler */
104
    /** Creates new CacheHandler */
106
    private CacheHandler() {
105
    private CacheHandler() {
107
        cacheMap = new Hashtable(); // to have synchronized access
106
        cacheMap = new Hashtable(); // to have synchronized access
108
        persistentData = Collections.synchronizedMap(new WeakHashMap(4037)); // to have synchronized access
109
        cacheFilesHolder = Collections.synchronizedMap(new WeakHashMap());
107
        cacheFilesHolder = Collections.synchronizedMap(new WeakHashMap());
110
        cacheQueue = org.openide.util.Utilities.activeReferenceQueue();
108
        cacheQueue = org.openide.util.Utilities.activeReferenceQueue();
111
    }
109
    }
Lines 121-134 Link Here
121
    
119
    
122
    ReferenceQueue getCacheFileReferenceQueue() {
120
    ReferenceQueue getCacheFileReferenceQueue() {
123
        return cacheQueue;
121
        return cacheQueue;
124
    }
125
    
126
    void addReferencedData(Reference ref, CacheFile.PersistentData data) {
127
        persistentData.put(ref, data);
128
    }
129
    
130
    CacheFile.PersistentData getReferencedData(Reference ref) {
131
        return (CacheFile.PersistentData) persistentData.get(ref);
132
    }
122
    }
133
123
134
    /** Creates a reference object. To be used in the Filesystem's createReference method to ensure
124
    /** Creates a reference object. To be used in the Filesystem's createReference method to ensure
(-)src/org/netbeans/modules/vcscore/caching/VcsCacheDir.java (-13 lines)
Lines 184-202 Link Here
184
        return file;
184
        return file;
185
    }
185
    }
186
    
186
    
187
    protected CacheFile createChildFromData(CacheFile.PersistentData data) {
188
        CacheFile file;
189
        if (data.isDirectory()) {
190
            file = new VcsCacheDir(getCacheName(), new File(getFile(), data.getName()), data);
191
            ((VcsCacheDir) file).readChildNamesFromDisk();
192
            //((CacheDir) file).readFromDisk(null); // It's necessary to initialize the directory content!
193
        } else {
194
            file = new VcsCacheFile(getCacheName(), data);
195
        }
196
        //file.setParent(this);
197
        return file;
198
    }
199
    
200
    /** Path string to the netbeans.cache file of this directory
187
    /** Path string to the netbeans.cache file of this directory
201
     */
188
     */
202
    protected String getCacheFileName() {
189
    protected String getCacheFileName() {

Return to bug 41012