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 257013
Collapse All | Expand All

(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformSources.java (-4 / +3 lines)
Lines 45-51 Link Here
45
package org.netbeans.modules.ant.freeform;
45
package org.netbeans.modules.ant.freeform;
46
46
47
import java.io.File;
47
import java.io.File;
48
import java.lang.ref.WeakReference;
49
import java.util.ArrayList;
48
import java.util.ArrayList;
50
import java.util.Collections;
49
import java.util.Collections;
51
import java.util.HashMap;
50
import java.util.HashMap;
Lines 67-75 Link Here
67
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileObject;
68
import org.openide.filesystems.FileRenameEvent;
67
import org.openide.filesystems.FileRenameEvent;
69
import org.openide.filesystems.FileUtil;
68
import org.openide.filesystems.FileUtil;
69
import org.openide.util.CallbackReferences;
70
import org.openide.util.ChangeSupport;
70
import org.openide.util.ChangeSupport;
71
import org.openide.util.Mutex;
71
import org.openide.util.Mutex;
72
import org.openide.util.Utilities;
73
import org.openide.xml.XMLUtil;
72
import org.openide.xml.XMLUtil;
74
import org.w3c.dom.Element;
73
import org.w3c.dom.Element;
75
74
Lines 209-222 Link Here
209
        cs.fireChange();
208
        cs.fireChange();
210
    }
209
    }
211
210
212
    private class WeakFileListener extends WeakReference<FreeformSources> implements Runnable, FileChangeListener {
211
    private class WeakFileListener extends CallbackReferences.WeakCallback<FreeformSources> implements FileChangeListener {
213
212
214
        private final File file;
213
        private final File file;
215
214
216
        private WeakFileListener (
215
        private WeakFileListener (
217
                final FreeformSources source,
216
                final FreeformSources source,
218
                final File file) {
217
                final File file) {
219
            super (source, Utilities.activeReferenceQueue());
218
            super (source);
220
            this.file = file;
219
            this.file = file;
221
        }
220
        }
222
221
(-)a/bugtracking/src/org/netbeans/modules/bugtracking/RepositoryImpl.java (-4 / +3 lines)
Lines 45-51 Link Here
45
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeListener;
47
import java.beans.PropertyChangeSupport;
47
import java.beans.PropertyChangeSupport;
48
import java.lang.ref.ReferenceQueue;
49
import java.lang.ref.WeakReference;
48
import java.lang.ref.WeakReference;
50
import java.util.*;
49
import java.util.*;
51
import java.util.Map.Entry;
50
import java.util.Map.Entry;
Lines 57-63 Link Here
57
import org.netbeans.modules.team.spi.NBRepositoryProvider;
56
import org.netbeans.modules.team.spi.NBRepositoryProvider;
58
import org.netbeans.modules.team.spi.OwnerInfo;
57
import org.netbeans.modules.team.spi.OwnerInfo;
59
import org.netbeans.modules.team.spi.TeamBugtrackingConnector;
58
import org.netbeans.modules.team.spi.TeamBugtrackingConnector;
60
import org.openide.util.Utilities;
59
import org.openide.util.CallbackReferences;
61
60
62
61
63
/**
62
/**
Lines 502-511 Link Here
502
        
501
        
503
        abstract WRAPPER createWrapper(DATA d);
502
        abstract WRAPPER createWrapper(DATA d);
504
        
503
        
505
        private class MapReference extends WeakReference<WRAPPER> implements Runnable {
504
        private class MapReference extends CallbackReferences.WeakCallback<WRAPPER> {
506
            private final DATA key;
505
            private final DATA key;
507
            public MapReference(DATA d, WRAPPER w) {
506
            public MapReference(DATA d, WRAPPER w) {
508
                super(w, Utilities.activeReferenceQueue());
507
                super(w);
509
                this.key = d;
508
                this.key = d;
510
            }
509
            }
511
            @Override
510
            @Override
(-)a/core.windows/src/org/netbeans/core/windows/persistence/PersistenceManager.java (-4 / +3 lines)
Lines 80-90 Link Here
80
import org.openide.loaders.InstanceDataObject;
80
import org.openide.loaders.InstanceDataObject;
81
import org.openide.modules.ModuleInfo;
81
import org.openide.modules.ModuleInfo;
82
import org.openide.modules.SpecificationVersion;
82
import org.openide.modules.SpecificationVersion;
83
import org.openide.util.CallbackReferences;
83
import org.openide.util.Exceptions;
84
import org.openide.util.Exceptions;
84
import org.openide.util.Lookup;
85
import org.openide.util.Lookup;
85
import org.openide.util.NbBundle;
86
import org.openide.util.NbBundle;
86
import org.openide.util.Utilities;
87
import org.openide.util.io.SafeException;
88
import org.openide.windows.TopComponent;
87
import org.openide.windows.TopComponent;
89
import org.openide.xml.XMLUtil;
88
import org.openide.xml.XMLUtil;
90
import org.xml.sax.EntityResolver;
89
import org.xml.sax.EntityResolver;
Lines 1394-1404 Link Here
1394
     * This class is used to clean internal maps containing <String,WeakReference<TopComponent>>
1393
     * This class is used to clean internal maps containing <String,WeakReference<TopComponent>>
1395
     * after TopComponent instanced was gc'ed.
1394
     * after TopComponent instanced was gc'ed.
1396
     */
1395
     */
1397
    private class TopComponentReference extends WeakReference<TopComponent> implements Runnable {
1396
    private class TopComponentReference extends CallbackReferences.WeakCallback<TopComponent> {
1398
        private final String tcID;
1397
        private final String tcID;
1399
        
1398
        
1400
        public TopComponentReference (TopComponent ref, String tcID) {
1399
        public TopComponentReference (TopComponent ref, String tcID) {
1401
           super(ref, Utilities.activeReferenceQueue());
1400
           super(ref);
1402
           this.tcID = tcID;
1401
           this.tcID = tcID;
1403
        }
1402
        }
1404
        
1403
        
(-)a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/WeakHashMapActive.java (-11 / +15 lines)
Lines 41-53 Link Here
41
 */
41
 */
42
package org.netbeans.modules.debugger.jpda.projects;
42
package org.netbeans.modules.debugger.jpda.projects;
43
43
44
import java.lang.ref.ReferenceQueue;
45
import java.lang.ref.WeakReference;
46
import java.util.AbstractMap;
44
import java.util.AbstractMap;
47
import java.util.HashMap;
45
import java.util.HashMap;
48
import java.util.Map;
46
import java.util.Map;
49
import java.util.Set;
47
import java.util.Set;
50
import org.openide.util.BaseUtilities;
48
import org.openide.util.CallbackReferences;
51
49
52
/**
50
/**
53
 * A weak hash map, that automatically release entries as soon as they are freed by GC.
51
 * A weak hash map, that automatically release entries as soon as they are freed by GC.
Lines 57-74 Link Here
57
// TODO: Make it a public API. There's another copy of this class in debugger.jpda module.
55
// TODO: Make it a public API. There's another copy of this class in debugger.jpda module.
58
public final class WeakHashMapActive<K,V> extends AbstractMap<K,V> {
56
public final class WeakHashMapActive<K,V> extends AbstractMap<K,V> {
59
    
57
    
60
    private final ReferenceQueue<Object> queue;
61
    private final Map<KeyReference<K>, V> map;
58
    private final Map<KeyReference<K>, V> map;
62
    
59
    
63
    public WeakHashMapActive() {
60
    public WeakHashMapActive() {
64
        super();
61
        super();
65
        map = new HashMap<>();
62
        map = new HashMap<>();
66
        queue = BaseUtilities.activeReferenceQueue();
67
    }
63
    }
68
    
64
    
69
    @Override
65
    @Override
70
    public V put(K key, V value) {
66
    public V put(K key, V value) {
71
        KeyReference<K> rk = new KeyReference<>(key, queue);
67
        KeyReference<K> rk = new KeyReference<>(key);
72
        synchronized (map) {
68
        synchronized (map) {
73
            return map.put(rk, value);
69
            return map.put(rk, value);
74
        }
70
        }
Lines 76-82 Link Here
76
72
77
    @Override
73
    @Override
78
    public V get(Object key) {
74
    public V get(Object key) {
79
        KeyReference<Object> rk = new KeyReference<>(key, null);
75
        KeyReference<Object> rk = new KeyReference<>(key, true);
80
        synchronized (map) {
76
        synchronized (map) {
81
            return map.get(rk);
77
            return map.get(rk);
82
        }
78
        }
Lines 84-90 Link Here
84
80
85
    @Override
81
    @Override
86
    public V remove(Object key) {
82
    public V remove(Object key) {
87
        KeyReference<Object> rk = new KeyReference<>(key, null);
83
        KeyReference<Object> rk = new KeyReference<>(key, true);
88
        synchronized (map) {
84
        synchronized (map) {
89
            return map.remove(rk);
85
            return map.remove(rk);
90
        }
86
        }
Lines 109-121 Link Here
109
        throw new UnsupportedOperationException("Not supported.");
105
        throw new UnsupportedOperationException("Not supported.");
110
    }
106
    }
111
    
107
    
112
    private class KeyReference<K> extends WeakReference<K> implements Runnable {
108
    private class KeyReference<K> extends CallbackReferences.WeakCallback<K> {
113
        
109
        
114
        private final int hash;
110
        private final int hash;
111
        private final boolean test;
115
        
112
        
116
        KeyReference(K r, ReferenceQueue<? super K> queue) {
113
        KeyReference(K r) {
117
            super(r, queue);
114
            this(r, false);
115
        }
116
        KeyReference(K r, boolean test) {
117
            super(r);
118
            hash = r.hashCode();
118
            hash = r.hashCode();
119
            this.test = test;
119
        }
120
        }
120
121
121
        @Override
122
        @Override
Lines 140-145 Link Here
140
        @Override
141
        @Override
141
        public void run() {
142
        public void run() {
142
            // Collected
143
            // Collected
144
            if (test) {
145
                return ;
146
            }
143
            synchronized (map) {
147
            synchronized (map) {
144
                map.remove(this);
148
                map.remove(this);
145
            }
149
            }
(-)a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/util/WeakHashMapActive.java (-11 / +16 lines)
Lines 41-53 Link Here
41
 */
41
 */
42
package org.netbeans.modules.debugger.jpda.util;
42
package org.netbeans.modules.debugger.jpda.util;
43
43
44
import java.lang.ref.ReferenceQueue;
45
import java.lang.ref.WeakReference;
46
import java.util.AbstractMap;
44
import java.util.AbstractMap;
47
import java.util.HashMap;
45
import java.util.HashMap;
48
import java.util.Map;
46
import java.util.Map;
49
import java.util.Set;
47
import java.util.Set;
50
import org.openide.util.BaseUtilities;
48
import org.openide.util.CallbackReferences;
51
49
52
/**
50
/**
53
 * A weak hash map, that automatically release entries as soon as they are freed by GC.
51
 * A weak hash map, that automatically release entries as soon as they are freed by GC.
Lines 57-74 Link Here
57
// TODO: Make it a public API. There's another copy of this class in debugger.jpda.projects module.
55
// TODO: Make it a public API. There's another copy of this class in debugger.jpda.projects module.
58
public final class WeakHashMapActive<K,V> extends AbstractMap<K,V> {
56
public final class WeakHashMapActive<K,V> extends AbstractMap<K,V> {
59
    
57
    
60
    private final ReferenceQueue<Object> queue;
61
    private final Map<KeyReference<K>, V> map;
58
    private final Map<KeyReference<K>, V> map;
62
    
59
    
63
    public WeakHashMapActive() {
60
    public WeakHashMapActive() {
64
        super();
61
        super();
65
        map = new HashMap<>();
62
        map = new HashMap<>();
66
        queue = BaseUtilities.activeReferenceQueue();
67
    }
63
    }
68
    
64
    
69
    @Override
65
    @Override
70
    public V put(K key, V value) {
66
    public V put(K key, V value) {
71
        KeyReference<K> rk = new KeyReference<>(key, queue);
67
        KeyReference<K> rk = new KeyReference<>(key);
72
        synchronized (map) {
68
        synchronized (map) {
73
            return map.put(rk, value);
69
            return map.put(rk, value);
74
        }
70
        }
Lines 76-82 Link Here
76
72
77
    @Override
73
    @Override
78
    public V get(Object key) {
74
    public V get(Object key) {
79
        KeyReference<Object> rk = new KeyReference<>(key, null);
75
        KeyReference<Object> rk = new KeyReference<>(key, true);
80
        synchronized (map) {
76
        synchronized (map) {
81
            return map.get(rk);
77
            return map.get(rk);
82
        }
78
        }
Lines 84-90 Link Here
84
80
85
    @Override
81
    @Override
86
    public V remove(Object key) {
82
    public V remove(Object key) {
87
        KeyReference<Object> rk = new KeyReference<>(key, null);
83
        KeyReference<Object> rk = new KeyReference<>(key, true);
88
        synchronized (map) {
84
        synchronized (map) {
89
            return map.remove(rk);
85
            return map.remove(rk);
90
        }
86
        }
Lines 109-121 Link Here
109
        throw new UnsupportedOperationException("Not supported.");
105
        throw new UnsupportedOperationException("Not supported.");
110
    }
106
    }
111
    
107
    
112
    private class KeyReference<K> extends WeakReference<K> implements Runnable {
108
    private class KeyReference<K> extends CallbackReferences.WeakCallback<K> {
113
        
109
        
114
        private final int hash;
110
        private final int hash;
111
        private final boolean test;
115
        
112
        
116
        KeyReference(K r, ReferenceQueue<? super K> queue) {
113
        KeyReference(K r) {
117
            super(r, queue);
114
            this(r, false);
115
        }
116
        
117
        KeyReference(K r, boolean test) {
118
            super(r);
118
            hash = r.hashCode();
119
            hash = r.hashCode();
120
            this.test = test;
119
        }
121
        }
120
122
121
        @Override
123
        @Override
Lines 140-145 Link Here
140
        @Override
142
        @Override
141
        public void run() {
143
        public void run() {
142
            // Collected
144
            // Collected
145
            if (test) {
146
                return ;
147
            }
143
            synchronized (map) {
148
            synchronized (map) {
144
                map.remove(this);
149
                map.remove(this);
145
            }
150
            }
(-)a/editor.document/src/org/netbeans/modules/editor/lib2/document/Mark.java (-4 / +4 lines)
Lines 42-48 Link Here
42
42
43
package org.netbeans.modules.editor.lib2.document;
43
package org.netbeans.modules.editor.lib2.document;
44
44
45
import java.lang.ref.WeakReference;
45
import org.openide.util.CallbackReferences;
46
46
47
/**
47
/**
48
 * Mark is an element of the {@link MarkVector}.
48
 * Mark is an element of the {@link MarkVector}.
Lines 60-66 Link Here
60
 * @since 1.46
60
 * @since 1.46
61
 */
61
 */
62
62
63
final class Mark extends WeakReference<EditorPosition> implements Runnable {
63
final class Mark extends CallbackReferences.WeakCallback<EditorPosition> {
64
64
65
    /**
65
    /**
66
     * Offset at which the mark is located in the document.
66
     * Offset at which the mark is located in the document.
Lines 81-87 Link Here
81
     * Construct mark instance.
81
     * Construct mark instance.
82
     */
82
     */
83
    Mark(MarkVector markVector, int rawOffset, EditorPosition pos) {
83
    Mark(MarkVector markVector, int rawOffset, EditorPosition pos) {
84
        super(pos, org.openide.util.BaseUtilities.activeReferenceQueue()); // The queue calls run() when unreachable
84
        super(pos); // Calls run() when unreachable
85
        this.markVector = markVector;
85
        this.markVector = markVector;
86
        this.rawOffset = rawOffset;
86
        this.rawOffset = rawOffset;
87
        pos.initMark(this);
87
        pos.initMark(this);
Lines 104-110 Link Here
104
    }
104
    }
105
    
105
    
106
    public void run() {
106
    public void run() {
107
        // Called by Utilities.activeReferenceQueue() once the EditorPosition
107
        // Called by CallbackReferences once the EditorPosition
108
        // is no longer reachable
108
        // is no longer reachable
109
        MarkVector lMarkVector = markVector;
109
        MarkVector lMarkVector = markVector;
110
        if (lMarkVector != null) {
110
        if (lMarkVector != null) {
(-)a/editor.indent.project/src/org/netbeans/modules/editor/indent/project/ProjectAwareCodeStylePreferences.java (-17 / +12 lines)
Lines 44-50 Link Here
44
44
45
import java.lang.ref.Reference;
45
import java.lang.ref.Reference;
46
import java.lang.ref.SoftReference;
46
import java.lang.ref.SoftReference;
47
import java.lang.ref.WeakReference;
48
import java.util.HashMap;
47
import java.util.HashMap;
49
import java.util.Map;
48
import java.util.Map;
50
import java.util.WeakHashMap;
49
import java.util.WeakHashMap;
Lines 65-72 Link Here
65
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
64
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
66
import org.openide.filesystems.FileObject;
65
import org.openide.filesystems.FileObject;
67
import org.openide.loaders.DataObject;
66
import org.openide.loaders.DataObject;
67
import org.openide.util.CallbackReferences;
68
import org.openide.util.RequestProcessor;
68
import org.openide.util.RequestProcessor;
69
import org.openide.util.Utilities;
70
import org.openide.util.WeakListeners;
69
import org.openide.util.WeakListeners;
71
import org.openide.util.lookup.ServiceProvider;
70
import org.openide.util.lookup.ServiceProvider;
72
71
Lines 93-99 Link Here
93
92
94
    private static final Logger LOG = Logger.getLogger(ProjectAwareCodeStylePreferences.class.getName());
93
    private static final Logger LOG = Logger.getLogger(ProjectAwareCodeStylePreferences.class.getName());
95
    private static final RequestProcessor RP = new RequestProcessor("Project Aware Code Style Preferences", 1, false, false); //NOI18N
94
    private static final RequestProcessor RP = new RequestProcessor("Project Aware Code Style Preferences", 1, false, false); //NOI18N
96
    private static final CodeStylePreferences.Provider singleton = new CodeStylePreferences.Provider() {
95
    private static final CodeStylePreferences.Provider singleton = new CSPProvider();
96
    
97
    private static final class CSPProvider implements CodeStylePreferences.Provider, CallbackReferences.Callback {
97
98
98
        @Override
99
        @Override
99
        public Preferences forFile(FileObject file, String mimeType) {
100
        public Preferences forFile(FileObject file, String mimeType) {
Lines 131-137 Link Here
131
132
132
                    csp = new Csp(
133
                    csp = new Csp(
133
                            mimeType,
134
                            mimeType,
134
                            doc == null ? null : new CleaningWeakReference(doc),
135
                            doc == null ? null : new CallbackReferences.Weak(doc, this),
135
                            file);
136
                            file);
136
                    if (csps == null) {
137
                    if (csps == null) {
137
                        csps = new HashMap<String, Csp>();
138
                        csps = new HashMap<String, Csp>();
Lines 159-178 Link Here
159
            return csp;
160
            return csp;
160
        }
161
        }
161
162
162
        final class CleaningWeakReference extends WeakReference<Document> implements Runnable {
163
        @Override
164
        public void referenceCleared(Reference reference) {
165
            synchronized (cache) {
166
                //expunge stale entries from the cache:
167
                cache.size();
168
            }
169
        }
163
170
164
            public CleaningWeakReference(Document referent) {
165
                super(referent, Utilities.activeReferenceQueue());
166
            }
167
168
            public @Override void run() {
169
                synchronized (cache) {
170
                    //expunge stale entries from the cache:
171
                    cache.size();
172
                }
173
            }
174
175
        }
176
    };
171
    };
177
172
178
    private static final class Csp {
173
    private static final class Csp {
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/impl/MultiMark.java (-4 / +4 lines)
Lines 44-51 Link Here
44
44
45
package org.netbeans.modules.editor.lib.impl;
45
package org.netbeans.modules.editor.lib.impl;
46
46
47
import java.lang.ref.WeakReference;
48
import javax.swing.text.Position;
47
import javax.swing.text.Position;
48
import org.openide.util.CallbackReferences;
49
49
50
50
51
/**
51
/**
Lines 57-63 Link Here
57
 * @version 1.00
57
 * @version 1.00
58
 */
58
 */
59
59
60
public final class MultiMark extends WeakReference<BasePosition> implements Runnable {
60
public final class MultiMark extends CallbackReferences.WeakCallback<BasePosition> {
61
61
62
    /** Whether mark has a backward (or forward) bias */
62
    /** Whether mark has a backward (or forward) bias */
63
    static final int BACKWARD_BIAS = 1;
63
    static final int BACKWARD_BIAS = 1;
Lines 107-113 Link Here
107
    /** Construct new mark. The mark is invalid by default.
107
    /** Construct new mark. The mark is invalid by default.
108
     */
108
     */
109
    private MultiMark(BasePosition pos, MarkVector markVector, int offset, int flags) {
109
    private MultiMark(BasePosition pos, MarkVector markVector, int offset, int flags) {
110
        super(pos, org.openide.util.Utilities.activeReferenceQueue());
110
        super(pos);
111
        if (pos != null) {
111
        if (pos != null) {
112
            pos.setMark(this);
112
            pos.setMark(this);
113
        }
113
        }
Lines 140-146 Link Here
140
    }
140
    }
141
    
141
    
142
    public void run() {
142
    public void run() {
143
        // Called by Utilities.activeReferenceQueue() once the BasePosition
143
        // Called by CallbackReferences once the BasePosition
144
        // is no longer reachable
144
        // is no longer reachable
145
        dispose();
145
        dispose();
146
146
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/WeakReferenceStableList.java (-3 / +3 lines)
Lines 41-52 Link Here
41
 */
41
 */
42
package org.netbeans.modules.editor.lib2;
42
package org.netbeans.modules.editor.lib2;
43
43
44
import java.lang.ref.WeakReference;
45
import java.util.AbstractList;
44
import java.util.AbstractList;
46
import java.util.Collection;
45
import java.util.Collection;
47
import java.util.Iterator;
46
import java.util.Iterator;
48
import java.util.List;
47
import java.util.List;
49
import java.util.NoSuchElementException;
48
import java.util.NoSuchElementException;
49
import org.openide.util.CallbackReferences;
50
50
51
/**
51
/**
52
 * List holding non-null items weakly with automatic collection of GCed items.
52
 * List holding non-null items weakly with automatic collection of GCed items.
Lines 238-249 Link Here
238
238
239
    }
239
    }
240
    
240
    
241
    private static final class WeakRef<E> extends WeakReference<E> implements Runnable {
241
    private static final class WeakRef<E> extends CallbackReferences.WeakCallback<E> {
242
        
242
        
243
        private final WeakReferenceStableList list;
243
        private final WeakReferenceStableList list;
244
244
245
        public WeakRef(E e, WeakReferenceStableList list) {
245
        public WeakRef(E e, WeakReferenceStableList list) {
246
            super(e, org.openide.util.Utilities.activeReferenceQueue());
246
            super(e);
247
            this.list = list;
247
            this.list = list;
248
        }
248
        }
249
        
249
        
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/KeyBindingsUpdater.java (-3 / +3 lines)
Lines 41-47 Link Here
41
 */
41
 */
42
package org.netbeans.modules.editor.lib2.actions;
42
package org.netbeans.modules.editor.lib2.actions;
43
43
44
import java.lang.ref.WeakReference;
45
import java.util.ArrayList;
44
import java.util.ArrayList;
46
import java.util.Collection;
45
import java.util.Collection;
47
import java.util.Collections;
46
import java.util.Collections;
Lines 57-62 Link Here
57
import org.netbeans.api.editor.settings.MultiKeyBinding;
56
import org.netbeans.api.editor.settings.MultiKeyBinding;
58
import org.netbeans.lib.editor.util.ArrayUtilities;
57
import org.netbeans.lib.editor.util.ArrayUtilities;
59
import org.netbeans.spi.editor.AbstractEditorAction;
58
import org.netbeans.spi.editor.AbstractEditorAction;
59
import org.openide.util.CallbackReferences;
60
import org.openide.util.Lookup;
60
import org.openide.util.Lookup;
61
import org.openide.util.LookupEvent;
61
import org.openide.util.LookupEvent;
62
import org.openide.util.LookupListener;
62
import org.openide.util.LookupListener;
Lines 203-212 Link Here
203
        updateActionsAndKits();
203
        updateActionsAndKits();
204
    }
204
    }
205
    
205
    
206
    private final class KitReference extends WeakReference<EditorKit> implements Runnable {
206
    private final class KitReference extends CallbackReferences.WeakCallback<EditorKit> {
207
        
207
        
208
        KitReference(EditorKit kit) {
208
        KitReference(EditorKit kit) {
209
            super(kit, org.openide.util.Utilities.activeReferenceQueue());
209
            super(kit);
210
        }
210
        }
211
211
212
        @Override
212
        @Override
(-)a/editor.lib2/src/org/netbeans/spi/editor/highlighting/support/OffsetsBag.java (-4 / +3 lines)
Lines 44-50 Link Here
44
44
45
package org.netbeans.spi.editor.highlighting.support;
45
package org.netbeans.spi.editor.highlighting.support;
46
46
47
import java.lang.ref.WeakReference;
48
import java.util.logging.Level;
47
import java.util.logging.Level;
49
import java.util.logging.Logger;
48
import java.util.logging.Logger;
50
import javax.swing.event.DocumentEvent;
49
import javax.swing.event.DocumentEvent;
Lines 54-60 Link Here
54
import org.netbeans.api.editor.settings.AttributesUtilities;
53
import org.netbeans.api.editor.settings.AttributesUtilities;
55
import org.netbeans.modules.editor.lib2.highlighting.OffsetGapList;
54
import org.netbeans.modules.editor.lib2.highlighting.OffsetGapList;
56
import org.netbeans.spi.editor.highlighting.*;
55
import org.netbeans.spi.editor.highlighting.*;
57
import org.openide.util.Utilities;
56
import org.openide.util.CallbackReferences;
58
57
59
/**
58
/**
60
 * A bag of highlighted areas specified by their offsets in a document.
59
 * A bag of highlighted areas specified by their offsets in a document.
Lines 922-933 Link Here
922
        }
921
        }
923
    } // End of Seq class
922
    } // End of Seq class
924
    
923
    
925
    private static final class DocL extends WeakReference<OffsetsBag> implements DocumentListener, Runnable {
924
    private static final class DocL extends CallbackReferences.WeakCallback<OffsetsBag> implements DocumentListener {
926
        
925
        
927
        private Document document;
926
        private Document document;
928
        
927
        
929
        public DocL(OffsetsBag bag) {
928
        public DocL(OffsetsBag bag) {
930
            super(bag, Utilities.activeReferenceQueue());
929
            super(bag);
931
            this.document = bag.getDocument();
930
            this.document = bag.getDocument();
932
        }
931
        }
933
        
932
        
(-)a/editor.mimelookup.impl/src/org/netbeans/modules/editor/mimelookup/impl/FolderPathLookup.java (-16 / +8 lines)
Lines 47-53 Link Here
47
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeEvent;
48
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
49
import java.lang.ref.Reference;
49
import java.lang.ref.Reference;
50
import java.lang.ref.WeakReference;
51
import java.lang.reflect.Constructor;
50
import java.lang.reflect.Constructor;
52
import java.lang.reflect.InvocationTargetException;
51
import java.lang.reflect.InvocationTargetException;
53
import java.util.ArrayList;
52
import java.util.ArrayList;
Lines 63-68 Link Here
63
import org.openide.filesystems.FileStateInvalidException;
62
import org.openide.filesystems.FileStateInvalidException;
64
import org.openide.filesystems.spi.CustomInstanceFactory;
63
import org.openide.filesystems.spi.CustomInstanceFactory;
65
import org.openide.util.BaseUtilities;
64
import org.openide.util.BaseUtilities;
65
import org.openide.util.CallbackReferences;
66
import org.openide.util.Exceptions;
66
import org.openide.util.Exceptions;
67
import org.openide.util.Lookup;
67
import org.openide.util.Lookup;
68
import org.openide.util.lookup.AbstractLookup;
68
import org.openide.util.lookup.AbstractLookup;
Lines 279-285 Link Here
279
     * <br/>
279
     * <br/>
280
     * Once the instance gets released the item will be removed from cache.
280
     * Once the instance gets released the item will be removed from cache.
281
     */
281
     */
282
    private static final class InstanceItem {
282
    private static final class InstanceItem implements CallbackReferences.Callback {
283
283
284
        static final long serialVersionUID = 10L;
284
        static final long serialVersionUID = 10L;
285
        
285
        
Lines 348-354 Link Here
348
            if (inst == null) {
348
            if (inst == null) {
349
                inst = createInstanceFor(fo, Object.class);
349
                inst = createInstanceFor(fo, Object.class);
350
                if (inst != null) {
350
                if (inst != null) {
351
                    setRef(new Ref(inst));
351
                    setRef(new CallbackReferences.Weak(inst, this));
352
                }
352
                }
353
            }
353
            }
354
            return inst;
354
            return inst;
Lines 481-500 Link Here
481
        void release() {
481
        void release() {
482
            releaseInstanceItem(this);
482
            releaseInstanceItem(this);
483
        }
483
        }
484
485
        @Override
486
        public void referenceCleared(Reference reference) {
487
            release();
488
        }
484
        
489
        
485
        private final class Ref extends WeakReference<Object> implements Runnable {
486
            
487
            Ref(Object inst) {
488
                super(inst, BaseUtilities.activeReferenceQueue());
489
            }
490
491
            @Override
492
            public void run() {
493
                release();
494
            }
495
            
496
        }
497
498
    }
490
    }
499
        
491
        
500
}
492
}
(-)a/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/keybindings/KeyBindingSettingsImpl.java (-3 / +3 lines)
Lines 68-74 Link Here
68
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
68
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
69
import org.netbeans.modules.editor.settings.storage.api.EditorSettingsStorage;
69
import org.netbeans.modules.editor.settings.storage.api.EditorSettingsStorage;
70
import org.netbeans.modules.editor.settings.storage.api.KeyBindingSettingsFactory;
70
import org.netbeans.modules.editor.settings.storage.api.KeyBindingSettingsFactory;
71
import org.openide.util.Utilities;
71
import org.openide.util.CallbackReferences;
72
72
73
/**
73
/**
74
 * KeyBindings settings are represented by List of keybindings.
74
 * KeyBindings settings are represented by List of keybindings.
Lines 293-299 Link Here
293
        return new Immutable(result);
293
        return new Immutable(result);
294
    }
294
    }
295
    
295
    
296
    private static final class Listener extends WeakReference<KeyBindingSettingsImpl> implements PropertyChangeListener, Runnable {
296
    private static final class Listener extends CallbackReferences.WeakCallback<KeyBindingSettingsImpl> implements PropertyChangeListener {
297
        
297
        
298
        private final KeyBindingSettingsFactory baseKBS;
298
        private final KeyBindingSettingsFactory baseKBS;
299
        private final EditorSettingsStorage<Collection<KeyStroke>, MultiKeyBinding> storage;
299
        private final EditorSettingsStorage<Collection<KeyStroke>, MultiKeyBinding> storage;
Lines 302-308 Link Here
302
            KeyBindingSettingsImpl kb,
302
            KeyBindingSettingsImpl kb,
303
            KeyBindingSettingsFactory baseKBS
303
            KeyBindingSettingsFactory baseKBS
304
        ) {
304
        ) {
305
            super(kb, Utilities.activeReferenceQueue());
305
            super(kb);
306
            this.baseKBS = baseKBS;
306
            this.baseKBS = baseKBS;
307
            this.storage = EditorSettingsStorage.get(KeyMapsStorage.ID);
307
            this.storage = EditorSettingsStorage.get(KeyMapsStorage.ID);
308
308
(-)a/editor.tools.storage/src/org/netbeans/modules/editor/tools/storage/api/XMLHintPreferences.java (-3 / +3 lines)
Lines 50-56 Link Here
50
import java.io.InputStream;
50
import java.io.InputStream;
51
import java.io.OutputStream;
51
import java.io.OutputStream;
52
import java.lang.ref.Reference;
52
import java.lang.ref.Reference;
53
import java.lang.ref.SoftReference;
54
import java.net.URI;
53
import java.net.URI;
55
import java.util.ArrayList;
54
import java.util.ArrayList;
56
import java.util.HashMap;
55
import java.util.HashMap;
Lines 62-67 Link Here
62
import java.util.prefs.BackingStoreException;
61
import java.util.prefs.BackingStoreException;
63
import java.util.prefs.Preferences;
62
import java.util.prefs.Preferences;
64
import org.netbeans.api.annotations.common.NonNull;
63
import org.netbeans.api.annotations.common.NonNull;
64
import org.openide.util.CallbackReferences;
65
import org.openide.util.Exceptions;
65
import org.openide.util.Exceptions;
66
import org.openide.util.RequestProcessor;
66
import org.openide.util.RequestProcessor;
67
import org.openide.util.Utilities;
67
import org.openide.util.Utilities;
Lines 324-334 Link Here
324
        private static final int SAVE_DELAY = 30000;
324
        private static final int SAVE_DELAY = 30000;
325
    }
325
    }
326
326
327
    private static final class CleaneableSoftReference extends SoftReference<HintPreferencesProviderImpl> implements Runnable {
327
    private static final class CleaneableSoftReference extends CallbackReferences.SoftCallback<HintPreferencesProviderImpl> {
328
328
329
        private static URI settings;
329
        private static URI settings;
330
        public CleaneableSoftReference(HintPreferencesProviderImpl referent, URI settings) {
330
        public CleaneableSoftReference(HintPreferencesProviderImpl referent, URI settings) {
331
            super(referent, Utilities.activeReferenceQueue());
331
            super(referent);
332
        }
332
        }
333
333
334
        @Override
334
        @Override
(-)a/java.editor/src/org/netbeans/modules/java/editor/overridden/ComputeOverriding.java (-4 / +3 lines)
Lines 46-52 Link Here
46
46
47
import com.sun.source.tree.CompilationUnitTree;
47
import com.sun.source.tree.CompilationUnitTree;
48
import java.lang.ref.Reference;
48
import java.lang.ref.Reference;
49
import java.lang.ref.WeakReference;
50
import java.util.ArrayList;
49
import java.util.ArrayList;
51
import java.util.HashMap;
50
import java.util.HashMap;
52
import java.util.HashSet;
51
import java.util.HashSet;
Lines 72-78 Link Here
72
import org.netbeans.api.java.source.CompilationInfo;
71
import org.netbeans.api.java.source.CompilationInfo;
73
import org.netbeans.api.java.source.ElementHandle;
72
import org.netbeans.api.java.source.ElementHandle;
74
import org.netbeans.api.java.source.SourceUtils;
73
import org.netbeans.api.java.source.SourceUtils;
75
import org.openide.util.Utilities;
74
import org.openide.util.CallbackReferences;
76
75
77
76
78
/**
77
/**
Lines 275-283 Link Here
275
        }
274
        }
276
    }
275
    }
277
276
278
    private static final class CleaningWR extends WeakReference<Elements> implements Runnable {
277
    private static final class CleaningWR extends CallbackReferences.WeakCallback<Elements> {
279
        public CleaningWR(Elements el) {
278
        public CleaningWR(Elements el) {
280
            super(el, Utilities.activeReferenceQueue());
279
            super(el);
281
        }
280
        }
282
        public void run() {
281
        public void run() {
283
            synchronized(CACHE) {
282
            synchronized(CACHE) {
(-)a/java.project.ui/src/org/netbeans/modules/java/project/ui/ProjectProblemsProviders.java (-3 / +3 lines)
Lines 115-125 Link Here
115
import org.openide.filesystems.FileRenameEvent;
115
import org.openide.filesystems.FileRenameEvent;
116
import org.openide.filesystems.FileUtil;
116
import org.openide.filesystems.FileUtil;
117
import org.openide.modules.SpecificationVersion;
117
import org.openide.modules.SpecificationVersion;
118
import org.openide.util.CallbackReferences;
118
import org.openide.util.Exceptions;
119
import org.openide.util.Exceptions;
119
import org.openide.util.Lookup;
120
import org.openide.util.Lookup;
120
import org.openide.util.Mutex;
121
import org.openide.util.Mutex;
121
import org.openide.util.RequestProcessor;
122
import org.openide.util.RequestProcessor;
122
import org.openide.util.Utilities;
123
import org.openide.util.WeakListeners;
123
import org.openide.util.WeakListeners;
124
124
125
/**
125
/**
Lines 1494-1503 Link Here
1494
        }
1494
        }
1495
    }
1495
    }
1496
1496
1497
    private static class OpenManagersWeakListener extends WeakReference<PropertyChangeListener> implements Runnable, PropertyChangeListener {
1497
    private static class OpenManagersWeakListener extends CallbackReferences.WeakCallback<PropertyChangeListener> implements PropertyChangeListener {
1498
1498
1499
        public OpenManagersWeakListener(final PropertyChangeListener listener) {
1499
        public OpenManagersWeakListener(final PropertyChangeListener listener) {
1500
            super(listener, Utilities.activeReferenceQueue());
1500
            super(listener);
1501
        }
1501
        }
1502
1502
1503
        @Override
1503
        @Override
(-)a/java.source.base/src/org/netbeans/modules/java/source/indexing/APTUtils.java (-4 / +3 lines)
Lines 49-55 Link Here
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.io.InputStreamReader;
50
import java.io.InputStreamReader;
51
import java.lang.ref.Reference;
51
import java.lang.ref.Reference;
52
import java.lang.ref.SoftReference;
53
import java.lang.ref.WeakReference;
52
import java.lang.ref.WeakReference;
54
import java.net.URL;
53
import java.net.URL;
55
import java.util.Arrays;
54
import java.util.Arrays;
Lines 85-91 Link Here
85
import org.openide.util.Exceptions;
84
import org.openide.util.Exceptions;
86
import org.openide.util.Lookup;
85
import org.openide.util.Lookup;
87
import org.openide.util.RequestProcessor;
86
import org.openide.util.RequestProcessor;
88
import org.openide.util.BaseUtilities;
87
import org.openide.util.CallbackReferences;
89
import org.openide.util.WeakListeners;
88
import org.openide.util.WeakListeners;
90
import org.openide.util.lookup.Lookups;
89
import org.openide.util.lookup.Lookups;
91
90
Lines 491-503 Link Here
491
        //getResource and getResources of module classloaders do not return resources from parent's META-INF, so no need to override them
490
        //getResource and getResources of module classloaders do not return resources from parent's META-INF, so no need to override them
492
    }
491
    }
493
492
494
    private static final class ClassLoaderRef extends SoftReference<ClassLoader> implements Runnable {
493
    private static final class ClassLoaderRef extends CallbackReferences.SoftCallback<ClassLoader> {
495
494
496
        private final long timeStamp;
495
        private final long timeStamp;
497
        private final String rootPath;
496
        private final String rootPath;
498
497
499
        public ClassLoaderRef(final ClassLoader cl, final FileObject root) {
498
        public ClassLoaderRef(final ClassLoader cl, final FileObject root) {
500
            super(cl, BaseUtilities.activeReferenceQueue());
499
            super(cl);
501
            this.timeStamp = getTimeStamp(root);
500
            this.timeStamp = getTimeStamp(root);
502
            this.rootPath = FileUtil.getFileDisplayName(root);
501
            this.rootPath = FileUtil.getFileDisplayName(root);
503
            LOG.log(Level.FINER, "ClassLoader for root {0} created.", new Object[]{rootPath});  //NOI18N
502
            LOG.log(Level.FINER, "ClassLoader for root {0} created.", new Object[]{rootPath});  //NOI18N
(-)a/java.source.base/src/org/netbeans/modules/java/source/parsing/WriteBackTransaction.java (-4 / +3 lines)
Lines 49-55 Link Here
49
import java.io.InputStream;
49
import java.io.InputStream;
50
import java.io.OutputStream;
50
import java.io.OutputStream;
51
import java.lang.ref.Reference;
51
import java.lang.ref.Reference;
52
import java.lang.ref.SoftReference;
53
import java.net.URL;
52
import java.net.URL;
54
import java.nio.charset.Charset;
53
import java.nio.charset.Charset;
55
import java.util.ArrayList;
54
import java.util.ArrayList;
Lines 70-76 Link Here
70
import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation;
69
import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation;
71
import org.netbeans.modules.java.source.util.Iterators;
70
import org.netbeans.modules.java.source.util.Iterators;
72
import org.openide.util.Pair;
71
import org.openide.util.Pair;
73
import org.openide.util.BaseUtilities;
72
import org.openide.util.CallbackReferences;
74
73
75
/**
74
/**
76
 * 
75
 * 
Lines 342-352 Link Here
342
     * Simple guard against memory overflow; when the reference is freed, it instructs
341
     * Simple guard against memory overflow; when the reference is freed, it instructs
343
     * Storage to flush on next file addition.
342
     * Storage to flush on next file addition.
344
     */
343
     */
345
    private static class CacheRef extends SoftReference implements Runnable {
344
    private static class CacheRef extends CallbackReferences.SoftCallback {
346
        private WriteBackTransaction storage;
345
        private WriteBackTransaction storage;
347
346
348
        public CacheRef(WriteBackTransaction storage, Object referent) {
347
        public CacheRef(WriteBackTransaction storage, Object referent) {
349
            super(referent, BaseUtilities.activeReferenceQueue());
348
            super(referent);
350
            this.storage = storage;
349
            this.storage = storage;
351
        }
350
        }
352
351
(-)a/java.source.base/src/org/netbeans/modules/java/source/usages/ClassIndexImpl.java (-3 / +3 lines)
Lines 69-75 Link Here
69
import org.openide.filesystems.FileObject;
69
import org.openide.filesystems.FileObject;
70
import org.openide.util.Exceptions;
70
import org.openide.util.Exceptions;
71
import org.openide.util.Pair;
71
import org.openide.util.Pair;
72
import org.openide.util.BaseUtilities;
72
import org.openide.util.CallbackReferences;
73
73
74
/** Should probably final class with private constructor.
74
/** Should probably final class with private constructor.
75
 *
75
 *
Lines 284-292 Link Here
284
        void rollback() throws IOException;
284
        void rollback() throws IOException;
285
    }
285
    }
286
    
286
    
287
    private class Ref extends WeakReference<ClassIndexImplListener> implements Runnable {
287
    private class Ref extends CallbackReferences.WeakCallback<ClassIndexImplListener> {
288
        public Ref (ClassIndexImplListener listener) {
288
        public Ref (ClassIndexImplListener listener) {
289
            super (listener, BaseUtilities.activeReferenceQueue());
289
            super (listener);
290
        }
290
        }
291
291
292
        public void run() {
292
        public void run() {
(-)a/java.source.base/src/org/netbeans/modules/java/source/usages/fcs/FileChangeSupport.java (-4 / +3 lines)
Lines 48-54 Link Here
48
import java.util.Map;
48
import java.util.Map;
49
import java.util.WeakHashMap;
49
import java.util.WeakHashMap;
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
51
import java.lang.ref.WeakReference;
52
import java.util.HashMap;
51
import java.util.HashMap;
53
52
54
import org.openide.filesystems.FileChangeListener;
53
import org.openide.filesystems.FileChangeListener;
Lines 56-62 Link Here
56
import org.openide.filesystems.FileEvent;
55
import org.openide.filesystems.FileEvent;
57
import org.openide.filesystems.FileRenameEvent;
56
import org.openide.filesystems.FileRenameEvent;
58
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
59
import org.openide.util.BaseUtilities;
58
import org.openide.util.CallbackReferences;
60
59
61
// XXX current implementation is not efficient for listening to a large # of files
60
// XXX current implementation is not efficient for listening to a large # of files
62
// XXX copied from project.ant ("purge" method added into this copy, otherwise unmodified)
61
// XXX copied from project.ant ("purge" method added into this copy, otherwise unmodified)
Lines 122-135 Link Here
122
        for (Object o : holders.keySet());
121
        for (Object o : holders.keySet());
123
    }
122
    }
124
    
123
    
125
    private static final class Holder extends WeakReference<FileChangeSupportListener> implements FileChangeListener, Runnable {
124
    private static final class Holder extends CallbackReferences.WeakCallback<FileChangeSupportListener> implements FileChangeListener {
126
        
125
        
127
        private final File path;
126
        private final File path;
128
        private FileObject current;
127
        private FileObject current;
129
        private File currentF;
128
        private File currentF;
130
        
129
        
131
        public Holder(FileChangeSupportListener listener, File path) {
130
        public Holder(FileChangeSupportListener listener, File path) {
132
            super(listener, BaseUtilities.activeReferenceQueue());
131
            super(listener);
133
            assert path != null;
132
            assert path != null;
134
            this.path = path;
133
            this.path = path;
135
            locateCurrent();
134
            locateCurrent();
(-)a/javaee.project/src/org/netbeans/modules/javaee/project/api/ant/ui/logicalview/AbstractLogicalViewProvider.java (-4 / +3 lines)
Lines 50-56 Link Here
50
import java.beans.PropertyChangeListener;
50
import java.beans.PropertyChangeListener;
51
import java.io.CharConversionException;
51
import java.io.CharConversionException;
52
import java.io.IOException;
52
import java.io.IOException;
53
import java.lang.ref.WeakReference;
54
import java.net.URL;
53
import java.net.URL;
55
import java.text.MessageFormat;
54
import java.text.MessageFormat;
56
import java.util.Collection;
55
import java.util.Collection;
Lines 121-130 Link Here
121
import org.openide.ErrorManager;
120
import org.openide.ErrorManager;
122
import org.openide.NotifyDescriptor;
121
import org.openide.NotifyDescriptor;
123
import org.openide.awt.DynamicMenuContent;
122
import org.openide.awt.DynamicMenuContent;
123
import org.openide.util.CallbackReferences;
124
import org.openide.util.ChangeSupport;
124
import org.openide.util.ChangeSupport;
125
import org.openide.util.ContextAwareAction;
125
import org.openide.util.ContextAwareAction;
126
import org.openide.util.Exceptions;
126
import org.openide.util.Exceptions;
127
import org.openide.util.Utilities;
128
import org.w3c.dom.Element;
127
import org.w3c.dom.Element;
129
128
130
/**
129
/**
Lines 889-898 Link Here
889
        return BrokenServerLibrarySupport.isBroken(project);
888
        return BrokenServerLibrarySupport.isBroken(project);
890
    }
889
    }
891
            
890
            
892
    private static class OpenManagersWeakListener extends WeakReference<PropertyChangeListener> implements Runnable, PropertyChangeListener {
891
    private static class OpenManagersWeakListener extends CallbackReferences.WeakCallback<PropertyChangeListener> implements PropertyChangeListener {
893
892
894
        public OpenManagersWeakListener(final PropertyChangeListener listener) {
893
        public OpenManagersWeakListener(final PropertyChangeListener listener) {
895
            super(listener, Utilities.activeReferenceQueue());
894
            super(listener);
896
        }
895
        }
897
896
898
        @Override
897
        @Override
(-)a/javafx2.editor/src/org/netbeans/modules/javafx2/editor/completion/beans/FxBeanCache.java (-9 / +3 lines)
Lines 42-61 Link Here
42
package org.netbeans.modules.javafx2.editor.completion.beans;
42
package org.netbeans.modules.javafx2.editor.completion.beans;
43
43
44
import java.lang.ref.Reference;
44
import java.lang.ref.Reference;
45
import java.lang.ref.ReferenceQueue;
46
import java.lang.ref.SoftReference;
47
import java.lang.ref.WeakReference;
48
import java.util.ArrayList;
45
import java.util.ArrayList;
49
import java.util.Collection;
46
import java.util.Collection;
50
import java.util.Collections;
51
import java.util.Deque;
47
import java.util.Deque;
52
import java.util.HashMap;
48
import java.util.HashMap;
53
import java.util.HashSet;
49
import java.util.HashSet;
54
import java.util.LinkedList;
50
import java.util.LinkedList;
55
import java.util.List;
56
import java.util.Map;
51
import java.util.Map;
57
import java.util.Set;
52
import java.util.Set;
58
import java.util.WeakHashMap;
59
import javax.lang.model.element.TypeElement;
53
import javax.lang.model.element.TypeElement;
60
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeEvent;
61
import javax.swing.event.ChangeListener;
55
import javax.swing.event.ChangeListener;
Lines 65-71 Link Here
65
import org.netbeans.api.java.source.ElementHandle;
59
import org.netbeans.api.java.source.ElementHandle;
66
import org.netbeans.api.java.source.RootsEvent;
60
import org.netbeans.api.java.source.RootsEvent;
67
import org.netbeans.api.java.source.TypesEvent;
61
import org.netbeans.api.java.source.TypesEvent;
68
import org.openide.util.Utilities;
62
import org.openide.util.CallbackReferences;
69
import org.openide.util.WeakListeners;
63
import org.openide.util.WeakListeners;
70
64
71
/**
65
/**
Lines 159-169 Link Here
159
        cc.addBeanInfo(instance, parents);
153
        cc.addBeanInfo(instance, parents);
160
    }
154
    }
161
    
155
    
162
    private static class CacheRef extends WeakReference<ClasspathCache> implements Runnable {
156
    private static class CacheRef extends CallbackReferences.WeakCallback<ClasspathCache> {
163
        private String    refKey;
157
        private String    refKey;
164
158
165
        public CacheRef(ClasspathCache referent, String key) {
159
        public CacheRef(ClasspathCache referent, String key) {
166
            super(referent, Utilities.activeReferenceQueue());
160
            super(referent);
167
            this.refKey = key;
161
            this.refKey = key;
168
        }
162
        }
169
163
(-)a/lexer/src/org/netbeans/lib/lexer/TokenHierarchyOperation.java (-2 / +2 lines)
Lines 859-868 Link Here
859
        }
859
        }
860
    }
860
    }
861
861
862
//    private final class SnapshotRef extends WeakReference<TokenHierarchyOperation<I,T>> implements Runnable {
862
//    private final class SnapshotRef extends CallbackReferences.WeakCallback<TokenHierarchyOperation<I,T>> {
863
//        
863
//        
864
//        SnapshotRef(TokenHierarchyOperation<I,T> snapshot) {
864
//        SnapshotRef(TokenHierarchyOperation<I,T> snapshot) {
865
//            super(snapshot, org.openide.util.Utilities.activeReferenceQueue());
865
//            super(snapshot);
866
//        }
866
//        }
867
//
867
//
868
//        public void run() {
868
//        public void run() {
(-)a/openide.awt/src/org/openide/awt/ContextManager.java (-4 / +3 lines)
Lines 59-64 Link Here
59
import java.util.concurrent.CopyOnWriteArrayList;
59
import java.util.concurrent.CopyOnWriteArrayList;
60
import java.util.logging.Level;
60
import java.util.logging.Level;
61
import java.util.logging.Logger;
61
import java.util.logging.Logger;
62
import org.openide.util.CallbackReferences;
62
import org.openide.util.Lookup;
63
import org.openide.util.Lookup;
63
import org.openide.util.Lookup.Item;
64
import org.openide.util.Lookup.Item;
64
import org.openide.util.Lookup.Provider;
65
import org.openide.util.Lookup.Provider;
Lines 66-72 Link Here
66
import org.openide.util.LookupEvent;
67
import org.openide.util.LookupEvent;
67
import org.openide.util.LookupListener;
68
import org.openide.util.LookupListener;
68
import org.openide.util.Mutex;
69
import org.openide.util.Mutex;
69
import org.openide.util.Utilities;
70
import org.openide.util.WeakListeners;
70
import org.openide.util.WeakListeners;
71
import org.openide.util.WeakSet;
71
import org.openide.util.WeakSet;
72
import org.openide.util.lookup.Lookups;
72
import org.openide.util.lookup.Lookups;
Lines 289-301 Link Here
289
    }
289
    }
290
290
291
    
291
    
292
    private static final class GMReference extends WeakReference<ContextManager> 
292
    private static final class GMReference extends CallbackReferences.WeakCallback<ContextManager> {
293
    implements Runnable {
294
        private LookupRef context;
293
        private LookupRef context;
295
        private boolean survive;
294
        private boolean survive;
296
        
295
        
297
        public GMReference(ContextManager m, LookupRef context, boolean survive) {
296
        public GMReference(ContextManager m, LookupRef context, boolean survive) {
298
            super(m, Utilities.activeReferenceQueue());
297
            super(m);
299
            this.context = context;
298
            this.context = context;
300
            this.survive = survive;
299
            this.survive = survive;
301
        }
300
        }
(-)a/openide.awt/src/org/openide/awt/GlobalManager.java (-4 / +3 lines)
Lines 59-68 Link Here
59
import javax.swing.Action;
59
import javax.swing.Action;
60
import javax.swing.ActionMap;
60
import javax.swing.ActionMap;
61
import org.openide.awt.ContextManager.LookupRef;
61
import org.openide.awt.ContextManager.LookupRef;
62
import org.openide.util.CallbackReferences;
62
import org.openide.util.Lookup;
63
import org.openide.util.Lookup;
63
import org.openide.util.LookupListener;
64
import org.openide.util.LookupListener;
64
import org.openide.util.Mutex;
65
import org.openide.util.Mutex;
65
import org.openide.util.Utilities;
66
import org.openide.util.WeakSet;
66
import org.openide.util.WeakSet;
67
67
68
68
Lines 224-236 Link Here
224
        return newMap;
224
        return newMap;
225
    }
225
    }
226
226
227
    private static final class GMReference extends WeakReference<GlobalManager> 
227
    private static final class GMReference extends CallbackReferences.WeakCallback<GlobalManager> {
228
    implements Runnable {
229
        private LookupRef context;
228
        private LookupRef context;
230
        private boolean survive;
229
        private boolean survive;
231
        
230
        
232
        public GMReference(GlobalManager m, LookupRef context, boolean survive) {
231
        public GMReference(GlobalManager m, LookupRef context, boolean survive) {
233
            super(m, Utilities.activeReferenceQueue());
232
            super(m);
234
            this.context = context;
233
            this.context = context;
235
            this.survive = survive;
234
            this.survive = survive;
236
        }
235
        }
(-)a/openide.compat/src/org/openide/util/WeakListener.java (-2 / +2 lines)
Lines 924-930 Link Here
924
924
925
    /** Reference that also holds ref to WeakListener.
925
    /** Reference that also holds ref to WeakListener.
926
    */
926
    */
927
    private static final class ListenerReference extends WeakReference implements Runnable {
927
    private static final class ListenerReference extends CallbackReferences.WeakCallback {
928
        private static Class lastClass;
928
        private static Class lastClass;
929
        private static String lastMethodName;
929
        private static String lastMethodName;
930
        private static Method lastRemove;
930
        private static Method lastRemove;
Lines 932-938 Link Here
932
        final WeakListener weakListener;
932
        final WeakListener weakListener;
933
933
934
        public ListenerReference(Object ref, WeakListener weakListener) {
934
        public ListenerReference(Object ref, WeakListener weakListener) {
935
            super(ref, Utilities.activeReferenceQueue());
935
            super(ref);
936
            this.weakListener = weakListener;
936
            this.weakListener = weakListener;
937
        }
937
        }
938
938
(-)a/openide.filesystems/src/org/openide/filesystems/DeepListener.java (-4 / +3 lines)
Lines 44-50 Link Here
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileFilter;
46
import java.io.FileFilter;
47
import java.lang.ref.WeakReference;
48
import java.util.ArrayList;
47
import java.util.ArrayList;
49
import java.util.Collections;
48
import java.util.Collections;
50
import java.util.List;
49
import java.util.List;
Lines 52-65 Link Here
52
import java.util.concurrent.Callable;
51
import java.util.concurrent.Callable;
53
import java.util.logging.Level;
52
import java.util.logging.Level;
54
import java.util.logging.Logger;
53
import java.util.logging.Logger;
55
import org.openide.util.BaseUtilities;
54
import org.openide.util.CallbackReferences;
56
import org.openide.util.WeakSet;
55
import org.openide.util.WeakSet;
57
56
58
/**
57
/**
59
 *
58
 *
60
 * @author Jaroslav Tulach <jtulach@netbeans.org>
59
 * @author Jaroslav Tulach <jtulach@netbeans.org>
61
 */
60
 */
62
final class DeepListener extends WeakReference<FileChangeListener>
61
final class DeepListener extends CallbackReferences.WeakCallback<FileChangeListener>
63
implements FileChangeListener, Runnable, Callable<Boolean>, FileFilter {
62
implements FileChangeListener, Runnable, Callable<Boolean>, FileFilter {
64
    static final Logger LOG = Logger.getLogger(FileUtil.class.getName() + ".recursive");
63
    static final Logger LOG = Logger.getLogger(FileUtil.class.getName() + ".recursive");
65
    private final File path;
64
    private final File path;
Lines 71-77 Link Here
71
    private final int hash;
70
    private final int hash;
72
71
73
    DeepListener(FileChangeListener listener, File path, FileFilter ff, Callable<Boolean> stop) {
72
    DeepListener(FileChangeListener listener, File path, FileFilter ff, Callable<Boolean> stop) {
74
        super(listener, BaseUtilities.activeReferenceQueue());
73
        super(listener);
75
        this.path = path;
74
        this.path = path;
76
        this.stop = stop;
75
        this.stop = stop;
77
        this.filter = ff;
76
        this.filter = ff;
(-)a/openide.filesystems/src/org/openide/filesystems/FileChangeImpl.java (-3 / +3 lines)
Lines 43-49 Link Here
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.io.FileFilter;
45
import java.io.FileFilter;
46
import java.lang.ref.WeakReference;
47
import java.util.HashMap;
46
import java.util.HashMap;
48
import java.util.Map;
47
import java.util.Map;
49
import java.util.WeakHashMap;
48
import java.util.WeakHashMap;
Lines 51-61 Link Here
51
import java.util.logging.Level;
50
import java.util.logging.Level;
52
import java.util.logging.Logger;
51
import java.util.logging.Logger;
53
import org.openide.util.BaseUtilities;
52
import org.openide.util.BaseUtilities;
53
import org.openide.util.CallbackReferences;
54
54
55
/** Holds FileChangeListener and File pair and handle movement of auxiliary
55
/** Holds FileChangeListener and File pair and handle movement of auxiliary
56
 * FileChangeListener to the first existing upper folder and firing appropriate events.
56
 * FileChangeListener to the first existing upper folder and firing appropriate events.
57
 */
57
 */
58
final class FileChangeImpl extends WeakReference<FileChangeListener> implements FileChangeListener, Runnable {
58
final class FileChangeImpl extends CallbackReferences.WeakCallback<FileChangeListener> implements FileChangeListener {
59
    /** Contains mapping of FileChangeListener to File. */
59
    /** Contains mapping of FileChangeListener to File. */
60
    private static final Map<FileChangeListener,Map<File,FileChangeImpl>> holders = new WeakHashMap<FileChangeListener,Map<File,FileChangeImpl>>();
60
    private static final Map<FileChangeListener,Map<File,FileChangeImpl>> holders = new WeakHashMap<FileChangeListener,Map<File,FileChangeImpl>>();
61
61
Lines 66-72 Link Here
66
    private boolean isOnTarget = false;
66
    private boolean isOnTarget = false;
67
67
68
    public FileChangeImpl(FileChangeListener listener, File path) {
68
    public FileChangeImpl(FileChangeListener listener, File path) {
69
        super(listener, BaseUtilities.activeReferenceQueue());
69
        super(listener);
70
        assert path != null;
70
        assert path != null;
71
        this.path = path;
71
        this.path = path;
72
    }
72
    }
(-)a/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java (-3 / +3 lines)
Lines 59-65 Link Here
59
import java.lang.management.ManagementFactory;
59
import java.lang.management.ManagementFactory;
60
import java.lang.ref.Reference;
60
import java.lang.ref.Reference;
61
import java.lang.ref.SoftReference;
61
import java.lang.ref.SoftReference;
62
import java.lang.ref.WeakReference;
63
import java.util.Collection;
62
import java.util.Collection;
64
import java.util.Collections;
63
import java.util.Collections;
65
import java.util.Date;
64
import java.util.Date;
Lines 81-86 Link Here
81
import org.openide.util.RequestProcessor;
80
import org.openide.util.RequestProcessor;
82
import org.openide.util.RequestProcessor.Task;
81
import org.openide.util.RequestProcessor.Task;
83
import org.openide.util.BaseUtilities;
82
import org.openide.util.BaseUtilities;
83
import org.openide.util.CallbackReferences;
84
84
85
/** A virtual filesystem based on a JAR archive.
85
/** A virtual filesystem based on a JAR archive.
86
* <p>For historical reasons many AbstractFileSystem.* methods are implemented
86
* <p>For historical reasons many AbstractFileSystem.* methods are implemented
Lines 992-1000 Link Here
992
     * JarFS if often queried for its FOs e.g. by java parser, which
992
     * JarFS if often queried for its FOs e.g. by java parser, which
993
     * leaves the references immediately.
993
     * leaves the references immediately.
994
     */
994
     */
995
    private class Ref<T extends FileObject> extends WeakReference<T> implements Runnable {
995
    private class Ref<T extends FileObject> extends CallbackReferences.WeakCallback<T> {
996
        public Ref(T fo) {
996
        public Ref(T fo) {
997
            super(fo, BaseUtilities.activeReferenceQueue());
997
            super(fo);
998
        }
998
        }
999
999
1000
        // do the cleanup
1000
        // do the cleanup
(-)a/openide.loaders/src/org/openide/loaders/DataObjectPool.java (-3 / +3 lines)
Lines 954-960 Link Here
954
        */
954
        */
955
        public void setDataObject (DataObject dobj) {
955
        public void setDataObject (DataObject dobj) {
956
            synchronized (DataObjectPool.getPOOL()) {
956
            synchronized (DataObjectPool.getPOOL()) {
957
                this.obj = new ItemReference (dobj, this);
957
                this.obj = dobj != null ? new ItemReference (dobj, this) : REFERENCE_NOT_SET;
958
                if (dobj != null && !dobj.getPrimaryFile ().isValid()) {
958
                if (dobj != null && !dobj.getPrimaryFile ().isValid()) {
959
                    // if the primary file is already invalid => mark the object as invalid
959
                    // if the primary file is already invalid => mark the object as invalid
960
                    DataObjectPool.getPOOL().countRegistration(dobj.getPrimaryFile());
960
                    DataObjectPool.getPOOL().countRegistration(dobj.getPrimaryFile());
Lines 1031-1043 Link Here
1031
    }
1031
    }
1032
1032
1033
    /** WeakReference - references a DataObject, strongly references an Item */
1033
    /** WeakReference - references a DataObject, strongly references an Item */
1034
    static final class ItemReference extends WeakReference<DataObject>
1034
    static final class ItemReference extends CallbackReferences.WeakCallback<DataObject>
1035
    implements Runnable {
1035
    implements Runnable {
1036
        /** Reference to an Item */
1036
        /** Reference to an Item */
1037
        private Item item;
1037
        private Item item;
1038
        
1038
        
1039
        ItemReference(DataObject dobject, Item item) {
1039
        ItemReference(DataObject dobject, Item item) {
1040
            super(dobject, org.openide.util.Utilities.activeReferenceQueue());
1040
            super(dobject);
1041
            this.item = item;
1041
            this.item = item;
1042
        }
1042
        }
1043
1043
(-)a/openide.loaders/src/org/openide/loaders/DataShadow.java (-3 / +2 lines)
Lines 1204-1216 Link Here
1204
        }
1204
        }
1205
    }
1205
    }
1206
    
1206
    
1207
    static final class DSWeakReference<T> extends WeakReference<T>
1207
    static final class DSWeakReference<T> extends CallbackReferences.WeakCallback<T> {
1208
    implements Runnable {
1209
        private int hash;
1208
        private int hash;
1210
        private FileObject original;
1209
        private FileObject original;
1211
        
1210
        
1212
        DSWeakReference(T o) {
1211
        DSWeakReference(T o) {
1213
            super(o, org.openide.util.Utilities.activeReferenceQueue());
1212
            super(o);
1214
            this.hash = o.hashCode();
1213
            this.hash = o.hashCode();
1215
            if (o instanceof DataShadow) {
1214
            if (o instanceof DataShadow) {
1216
                DataShadow s = (DataShadow)o;
1215
                DataShadow s = (DataShadow)o;
(-)a/openide.loaders/test/unit/src/org/openide/loaders/DataObjectSizeTest.java (-1 / +1 lines)
Lines 85-91 Link Here
85
        Object[] exclude = {
85
        Object[] exclude = {
86
            original.getLoader (),
86
            original.getLoader (),
87
            original.getPrimaryFile (),
87
            original.getPrimaryFile (),
88
            org.openide.util.Utilities.activeReferenceQueue (),
88
            //org.openide.util.Utilities.activeReferenceQueue (),
89
        };
89
        };
90
        
90
        
91
        assertSize ("If we exclude all the static things, like loader and " +
91
        assertSize ("If we exclude all the static things, like loader and " +
(-)a/openide.nodes/src/org/openide/nodes/EntrySupportDefault.java (-3 / +3 lines)
Lines 59-65 Link Here
59
import java.util.logging.Level;
59
import java.util.logging.Level;
60
import java.util.logging.Logger;
60
import java.util.logging.Logger;
61
import org.openide.nodes.Children.Entry;
61
import org.openide.nodes.Children.Entry;
62
import org.openide.util.Utilities;
62
import org.openide.util.CallbackReferences;
63
63
64
/** Default support that just fires changes directly to children and is suitable
64
/** Default support that just fires changes directly to children and is suitable
65
 * for simple mappings.
65
 * for simple mappings.
Lines 845-855 Link Here
845
        }
845
        }
846
    }
846
    }
847
847
848
    private class ChArrRef extends WeakReference<ChildrenArray> implements Runnable {
848
    private class ChArrRef extends CallbackReferences.WeakCallback<ChildrenArray> {
849
        private final ChildrenArray chArr;
849
        private final ChildrenArray chArr;
850
850
851
        public ChArrRef(ChildrenArray referent, boolean weak) {
851
        public ChArrRef(ChildrenArray referent, boolean weak) {
852
            super(referent, Utilities.activeReferenceQueue());
852
            super(referent);
853
            this.chArr = weak ? null : referent;
853
            this.chArr = weak ? null : referent;
854
        }
854
        }
855
855
(-)a/openide.nodes/src/org/openide/nodes/EntrySupportLazyState.java (-4 / +3 lines)
Lines 41-54 Link Here
41
 */
41
 */
42
package org.openide.nodes;
42
package org.openide.nodes;
43
43
44
import java.lang.ref.WeakReference;
45
import java.util.Collection;
44
import java.util.Collection;
46
import java.util.Collections;
45
import java.util.Collections;
47
import java.util.List;
46
import java.util.List;
48
import java.util.Map;
47
import java.util.Map;
49
import java.util.logging.Level;
48
import java.util.logging.Level;
50
import org.openide.nodes.Children.Entry;
49
import org.openide.nodes.Children.Entry;
51
import org.openide.util.Utilities;
50
import org.openide.util.CallbackReferences;
52
51
53
/** This class should represent an immutable state of a EntrySupportLazy instance.
52
/** This class should represent an immutable state of a EntrySupportLazy instance.
54
 *
53
 *
Lines 363-374 Link Here
363
        }
362
        }
364
    }
363
    }
365
364
366
    private static final class NodeRef extends WeakReference<Node> implements Runnable {
365
    private static final class NodeRef extends CallbackReferences.WeakCallback<Node> {
367
366
368
        private final EntryInfo info;
367
        private final EntryInfo info;
369
368
370
        public NodeRef(Node node, EntryInfo info) {
369
        public NodeRef(Node node, EntryInfo info) {
371
            super(node, Utilities.activeReferenceQueue());
370
            super(node);
372
            info.lazy().registerNode(1, info);
371
            info.lazy().registerNode(1, info);
373
            this.info = info;
372
            this.info = info;
374
        }
373
        }
(-)a/openide.nodes/test/unit/src/org/openide/nodes/ChildrenKeysTest.java (-3 / +3 lines)
Lines 70-78 Link Here
70
import org.netbeans.junit.Log;
70
import org.netbeans.junit.Log;
71
import org.netbeans.junit.NbTestCase;
71
import org.netbeans.junit.NbTestCase;
72
import org.netbeans.junit.RandomlyFails;
72
import org.netbeans.junit.RandomlyFails;
73
import org.openide.util.CallbackReferences;
73
import org.openide.util.Exceptions;
74
import org.openide.util.Exceptions;
74
import org.openide.util.RequestProcessor;
75
import org.openide.util.RequestProcessor;
75
import org.openide.util.Utilities;
76
76
77
public class ChildrenKeysTest extends NbTestCase {
77
public class ChildrenKeysTest extends NbTestCase {
78
    private Logger LOG;
78
    private Logger LOG;
Lines 918-929 Link Here
918
    }
918
    }
919
919
920
    static void waitActiveReferenceQueue() throws InterruptedException {
920
    static void waitActiveReferenceQueue() throws InterruptedException {
921
        class W extends WeakReference<Object> implements Runnable {
921
        class W extends CallbackReferences.WeakCallback<Object> {
922
            boolean cleaned;
922
            boolean cleaned;
923
            boolean finalized;
923
            boolean finalized;
924
924
925
            public W(Object obj) {
925
            public W(Object obj) {
926
                super(obj, Utilities.activeReferenceQueue());
926
                super(obj);
927
            }
927
            }
928
            public synchronized void run() {
928
            public synchronized void run() {
929
                cleaned = true;
929
                cleaned = true;
(-)a/openide.text/src/org/openide/text/DocumentOpenClose.java (-2 / +3 lines)
Lines 56-61 Link Here
56
import javax.swing.text.Position;
56
import javax.swing.text.Position;
57
import javax.swing.text.StyledDocument;
57
import javax.swing.text.StyledDocument;
58
import org.openide.awt.UndoRedo;
58
import org.openide.awt.UndoRedo;
59
import org.openide.util.CallbackReferences;
59
import org.openide.util.Mutex;
60
import org.openide.util.Mutex;
60
import org.openide.util.RequestProcessor;
61
import org.openide.util.RequestProcessor;
61
import org.openide.util.Task;
62
import org.openide.util.Task;
Lines 1043-1052 Link Here
1043
        
1044
        
1044
    }
1045
    }
1045
    
1046
    
1046
    private final class DocumentRef extends WeakReference<StyledDocument> implements Runnable {
1047
    private final class DocumentRef extends CallbackReferences.WeakCallback<StyledDocument> {
1047
1048
1048
        public DocumentRef(StyledDocument doc) {
1049
        public DocumentRef(StyledDocument doc) {
1049
            super(doc, org.openide.util.Utilities.activeReferenceQueue());
1050
            super(doc);
1050
            Logger.getLogger("TIMER").log(Level.FINE, "TextDocument", doc);
1051
            Logger.getLogger("TIMER").log(Level.FINE, "TextDocument", doc);
1051
        }
1052
        }
1052
1053
(-)a/openide.text/src/org/openide/text/LineVector.java (-3 / +3 lines)
Lines 41-51 Link Here
41
 */
41
 */
42
package org.openide.text;
42
package org.openide.text;
43
43
44
import java.lang.ref.WeakReference;
45
import java.util.ArrayList;
44
import java.util.ArrayList;
46
import java.util.List;
45
import java.util.List;
47
import java.util.logging.Level;
46
import java.util.logging.Level;
48
import java.util.logging.Logger;
47
import java.util.logging.Logger;
48
import org.openide.util.CallbackReferences;
49
49
50
/**
50
/**
51
 * Binary searchable list of document lines.
51
 * Binary searchable list of document lines.
Lines 431-440 Link Here
431
    }
431
    }
432
432
433
    
433
    
434
    private final class Ref extends WeakReference<Line> implements Runnable {
434
    private final class Ref extends CallbackReferences.WeakCallback<Line> {
435
435
436
        public Ref(Line line) {
436
        public Ref(Line line) {
437
            super(line, org.openide.util.BaseUtilities.activeReferenceQueue()); // The queue calls run() when unreachable
437
            super(line); // Calls run() when unreachable
438
        }
438
        }
439
439
440
        @Override
440
        @Override
(-)a/openide.text/test/unit/src/org/openide/text/CloneableEditorDocumentGCTest.java (-2 / +3 lines)
Lines 63-68 Link Here
63
import javax.swing.text.Position.Bias;
63
import javax.swing.text.Position.Bias;
64
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.junit.NbTestCase;
65
import org.openide.text.CloneableEditorSupport.Pane;
65
import org.openide.text.CloneableEditorSupport.Pane;
66
import org.openide.util.CallbackReferences;
66
import org.openide.util.Exceptions;
67
import org.openide.util.Exceptions;
67
import org.openide.util.Lookup;
68
import org.openide.util.Lookup;
68
import org.openide.windows.CloneableOpenSupport;
69
import org.openide.windows.CloneableOpenSupport;
Lines 120-129 Link Here
120
    }
121
    }
121
    
122
    
122
    public void testDocumentGCed () throws Exception {
123
    public void testDocumentGCed () throws Exception {
123
        class R extends WeakReference<Object> implements Runnable {
124
        class R extends CallbackReferences.WeakCallback<Object> {
124
125
125
            public R (Object o) {
126
            public R (Object o) {
126
                super(o, org.openide.util.Utilities.activeReferenceQueue());
127
                super(o);
127
            }
128
            }
128
129
129
            public void run() {
130
            public void run() {
(-)a/openide.util.ui/src/org/openide/util/ImageUtilities.java (-13 / +14 lines)
Lines 61-66 Link Here
61
import java.awt.image.RGBImageFilter;
61
import java.awt.image.RGBImageFilter;
62
import java.awt.image.WritableRaster;
62
import java.awt.image.WritableRaster;
63
import java.io.IOException;
63
import java.io.IOException;
64
import java.lang.ref.Reference;
64
import java.lang.ref.SoftReference;
65
import java.lang.ref.SoftReference;
65
import java.net.URL;
66
import java.net.URL;
66
import java.util.HashMap;
67
import java.util.HashMap;
Lines 90-101 Link Here
90
    /** separator for individual parts of tool tip text */
91
    /** separator for individual parts of tool tip text */
91
    static final String TOOLTIP_SEPAR = "<br>"; // NOI18N
92
    static final String TOOLTIP_SEPAR = "<br>"; // NOI18N
92
    /** a value that indicates that the icon does not exists */
93
    /** a value that indicates that the icon does not exists */
93
    private static final ActiveRef<String> NO_ICON = new ActiveRef<String>(null, null, null);
94
    private static final Reference<Image> NO_ICON = new SoftReference<Image>(null);
94
95
95
    private static final Map<String,ActiveRef<String>> cache = new HashMap<String,ActiveRef<String>>(128);
96
    private static final Map<String,Reference<Image>> cache = new HashMap<String,Reference<Image>>(128);
96
    private static final Map<String,ActiveRef<String>> localizedCache = new HashMap<String,ActiveRef<String>>(128);
97
    private static final Map<String,Reference<Image>> localizedCache = new HashMap<String,Reference<Image>>(128);
97
    private static final Map<CompositeImageKey,ActiveRef<CompositeImageKey>> compositeCache = new HashMap<CompositeImageKey,ActiveRef<CompositeImageKey>>(128);
98
    private static final Map<CompositeImageKey,Reference<Image>> compositeCache = new HashMap<CompositeImageKey,Reference<Image>>(128);
98
    private static final Map<ToolTipImageKey, ActiveRef<ToolTipImageKey>> imageToolTipCache = new HashMap<ToolTipImageKey, ActiveRef<ToolTipImageKey>>(128);
99
    private static final Map<ToolTipImageKey, Reference<Image>> imageToolTipCache = new HashMap<ToolTipImageKey, Reference<Image>>(128);
99
100
100
    private static RGBImageFilter imageIconFilter = null;
101
    private static RGBImageFilter imageIconFilter = null;
101
102
Lines 251-257 Link Here
251
        Image cached;
252
        Image cached;
252
253
253
        synchronized (compositeCache) {
254
        synchronized (compositeCache) {
254
            ActiveRef<CompositeImageKey> r = compositeCache.get(k);
255
            Reference<Image> r = compositeCache.get(k);
255
            if (r != null) {
256
            if (r != null) {
256
                cached = r.get();
257
                cached = r.get();
257
                if (cached != null) {
258
                if (cached != null) {
Lines 307-313 Link Here
307
        ToolTipImageKey key = new ToolTipImageKey(image, text);
308
        ToolTipImageKey key = new ToolTipImageKey(image, text);
308
        Image cached;
309
        Image cached;
309
        synchronized (imageToolTipCache) {
310
        synchronized (imageToolTipCache) {
310
            ActiveRef<ToolTipImageKey> r = imageToolTipCache.get(key);
311
            Reference<Image> r = imageToolTipCache.get(key);
311
            if (r != null) {
312
            if (r != null) {
312
                cached = r.get();
313
                cached = r.get();
313
                if (cached != null) {
314
                if (cached != null) {
Lines 424-430 Link Here
424
    static Image getIcon(String resource, boolean localized) {
425
    static Image getIcon(String resource, boolean localized) {
425
        if (localized) {
426
        if (localized) {
426
            synchronized (localizedCache) {
427
            synchronized (localizedCache) {
427
                ActiveRef<String> ref = localizedCache.get(resource);
428
                Reference<Image> ref = localizedCache.get(resource);
428
                Image img = null;
429
                Image img = null;
429
430
430
                // no icon for this name (already tested)
431
                // no icon for this name (already tested)
Lines 495-501 Link Here
495
    *  and is not optimized/interned
496
    *  and is not optimized/interned
496
    */
497
    */
497
    private static Image getIcon(String name, ClassLoader loader, boolean localizedQuery) {
498
    private static Image getIcon(String name, ClassLoader loader, boolean localizedQuery) {
498
        ActiveRef<String> ref = cache.get(name);
499
        Reference<Image> ref = cache.get(name);
499
        Image img = null;
500
        Image img = null;
500
501
501
        // no icon for this name (already tested)
502
        // no icon for this name (already tested)
Lines 791-802 Link Here
791
    }
792
    }
792
793
793
    /** Cleaning reference. */
794
    /** Cleaning reference. */
794
    private static final class ActiveRef<T> extends SoftReference<Image> implements Runnable {
795
    private static final class ActiveRef<T> extends CallbackReferences.SoftCallback<Image> {
795
        private final Map<T,ActiveRef<T>> holder;
796
        private final Map<T,Reference<Image>> holder;
796
        private final T key;
797
        private final T key;
797
798
798
        public ActiveRef(Image o, Map<T,ActiveRef<T>> holder, T key) {
799
        public ActiveRef(Image o, Map<T,Reference<Image>> holder, T key) {
799
            super(o, Utilities.activeReferenceQueue());
800
            super(o);
800
            this.holder = holder;
801
            this.holder = holder;
801
            this.key = key;
802
            this.key = key;
802
        }
803
        }
(-)a/openide.util.ui/src/org/openide/util/Utilities.java (+2 lines)
Lines 278-283 Link Here
278
     * Be sure to call this method anew for each reference.
278
     * Be sure to call this method anew for each reference.
279
     * Do not attempt to cache the return value.
279
     * Do not attempt to cache the return value.
280
     * @since 3.11
280
     * @since 3.11
281
     * @Deprecated This API requires an indefinitely running background thread.
282
     *             Use {@link CallbackReferences} instead.
281
     */
283
     */
282
    public static ReferenceQueue<Object> activeReferenceQueue() {
284
    public static ReferenceQueue<Object> activeReferenceQueue() {
283
        return BaseUtilities.activeReferenceQueue();
285
        return BaseUtilities.activeReferenceQueue();
(-)a/openide.util.ui/src/org/openide/util/doc-files/api.html (-1 lines)
Lines 87-93 Link Here
87
    <a href="../Utilities.html#loadImage-java.lang.String-"><code>loadImage</code></a>,
87
    <a href="../Utilities.html#loadImage-java.lang.String-"><code>loadImage</code></a>,
88
    <a href="../Utilities.html#mergeImages-java.awt.Image-java.awt.Image-int-int-"><code>mergeImage</code></a>,
88
    <a href="../Utilities.html#mergeImages-java.awt.Image-java.awt.Image-int-int-"><code>mergeImage</code></a>,
89
    <a href="../Utilities.html#topologicalSort-java.util.Collection-java.util.Map-"><code>topologicalSort</code></a>,
89
    <a href="../Utilities.html#topologicalSort-java.util.Collection-java.util.Map-"><code>topologicalSort</code></a>,
90
    <a href="../Utilities.html#activeReferenceQueue--"><code>activeReferenceQueue</code></a>,
91
    <a href="../Utilities.html#translate-java.lang.String-"><code>translate</code></a>.
90
    <a href="../Utilities.html#translate-java.lang.String-"><code>translate</code></a>.
92
    </li>
91
    </li>
93
92
(-)a/openide.util/src/org/openide/util/TimedSoftReference.java (-4 / +2 lines)
Lines 43-50 Link Here
43
 */
43
 */
44
package org.openide.util;
44
package org.openide.util;
45
45
46
import java.lang.ref.SoftReference;
47
48
import java.util.Map;
46
import java.util.Map;
49
47
50
48
Lines 68-74 Link Here
68
 * </ol>
66
 * </ol>
69
 * @author Jesse Glick
67
 * @author Jesse Glick
70
 */
68
 */
71
final class TimedSoftReference<T> extends SoftReference<T> implements Runnable {
69
final class TimedSoftReference<T> extends CallbackReferences.SoftCallback<T> {
72
    private static final int TIMEOUT = 30000;
70
    private static final int TIMEOUT = 30000;
73
    private static final RequestProcessor RP = new RequestProcessor("TimedSoftReference"); // NOI18N
71
    private static final RequestProcessor RP = new RequestProcessor("TimedSoftReference"); // NOI18N
74
    private RequestProcessor.Task task;
72
    private RequestProcessor.Task task;
Lines 88-94 Link Here
88
     * @param k the key whose value in <code>m</code> may be this reference
86
     * @param k the key whose value in <code>m</code> may be this reference
89
     */
87
     */
90
    public TimedSoftReference(T o, Map m, Object k) {
88
    public TimedSoftReference(T o, Map m, Object k) {
91
        super(o, BaseUtilities.activeReferenceQueue());
89
        super(o);
92
        this.o = o;
90
        this.o = o;
93
        this.m = m;
91
        this.m = m;
94
        this.k = k;
92
        this.k = k;
(-)a/openide.util/src/org/openide/util/WeakListenerImpl.java (-4 / +3 lines)
Lines 535-541 Link Here
535
535
536
    /** Reference that also holds ref to WeakListenerImpl.
536
    /** Reference that also holds ref to WeakListenerImpl.
537
    */
537
    */
538
    private static final class ListenerReference extends WeakReference<Object> implements Runnable {
538
    private static final class ListenerReference extends CallbackReferences.WeakCallback<Object> {
539
        private static Class<?> lastClass;
539
        private static Class<?> lastClass;
540
        private static Class<?> lastNClass;
540
        private static Class<?> lastNClass;
541
        private static String lastMethodName;
541
        private static String lastMethodName;
Lines 547-553 Link Here
547
        private String name;
547
        private String name;
548
548
549
        ListenerReference(Object ref, String name, WeakListenerImpl weakListener) {
549
        ListenerReference(Object ref, String name, WeakListenerImpl weakListener) {
550
            super(ref, BaseUtilities.activeReferenceQueue());
550
            super(ref);
551
            this.weakListener = weakListener;
551
            this.weakListener = weakListener;
552
            this.name = name;
552
            this.name = name;
553
        }
553
        }
Lines 562-569 Link Here
562
            }
562
            }
563
563
564
            if (weakListener.getSource() != source) {
564
            if (weakListener.getSource() != source) {
565
                // plan new cleanup into the activeReferenceQueue with this listener and 
565
                // plan new cleanup with this listener and provided source
566
                // provided source
567
                weakListener.source = new WeakReference<Object> (source) {
566
                weakListener.source = new WeakReference<Object> (source) {
568
                    ListenerReference doNotGCRef = new ListenerReference(new Object(), name, weakListener);
567
                    ListenerReference doNotGCRef = new ListenerReference(new Object(), name, weakListener);
569
                };
568
                };
(-)a/openide.util/test/unit/src/org/openide/util/WeakListenersTest.java (-1 / +1 lines)
Lines 526-532 Link Here
526
            l, 
526
            l, 
527
            button,
527
            button,
528
            c,
528
            c,
529
            BaseUtilities.activeReferenceQueue()
529
            //BaseUtilities.activeReferenceQueue()
530
        };
530
        };
531
        
531
        
532
        
532
        
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/TaskProcessor.java (-3 / +3 lines)
Lines 42-48 Link Here
42
42
43
package org.netbeans.modules.parsing.impl;
43
package org.netbeans.modules.parsing.impl;
44
44
45
import java.lang.ref.WeakReference;
46
import java.lang.reflect.Method;
45
import java.lang.reflect.Method;
47
import java.util.ArrayList;
46
import java.util.ArrayList;
48
import java.util.Collection;
47
import java.util.Collection;
Lines 79-84 Link Here
79
import org.netbeans.modules.parsing.lucene.spi.ScanSuspendImplementation;
78
import org.netbeans.modules.parsing.lucene.spi.ScanSuspendImplementation;
80
import org.netbeans.modules.parsing.spi.*;
79
import org.netbeans.modules.parsing.spi.*;
81
import org.netbeans.modules.parsing.spi.Parser.Result;
80
import org.netbeans.modules.parsing.spi.Parser.Result;
81
import org.openide.util.CallbackReferences;
82
import org.openide.util.Exceptions;
82
import org.openide.util.Exceptions;
83
import org.openide.util.Lookup;
83
import org.openide.util.Lookup;
84
import org.openide.util.Mutex;
84
import org.openide.util.Mutex;
Lines 1244-1255 Link Here
1244
1244
1245
    
1245
    
1246
1246
1247
    static final class RemovedTask extends WeakReference<Source> implements Runnable {
1247
    static final class RemovedTask extends CallbackReferences.WeakCallback<Source> {
1248
        
1248
        
1249
        private final SchedulerTask task;
1249
        private final SchedulerTask task;
1250
        
1250
        
1251
        public RemovedTask(final @NonNull Source src, final @NonNull SchedulerTask task) {
1251
        public RemovedTask(final @NonNull Source src, final @NonNull SchedulerTask task) {
1252
            super (src, org.openide.util.BaseUtilities.activeReferenceQueue());
1252
            super (src);
1253
            Parameters.notNull("src", src);     //NOI18N
1253
            Parameters.notNull("src", src);     //NOI18N
1254
            Parameters.notNull("task", task);   //NOI18N
1254
            Parameters.notNull("task", task);   //NOI18N
1255
            this.task = task;            
1255
            this.task = task;            
(-)a/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/ClusteredIndexables.java (-4 / +3 lines)
Lines 43-49 Link Here
43
package org.netbeans.modules.parsing.impl.indexing;
43
package org.netbeans.modules.parsing.impl.indexing;
44
44
45
import java.lang.ref.Reference;
45
import java.lang.ref.Reference;
46
import java.lang.ref.SoftReference;
47
import java.text.MessageFormat;
46
import java.text.MessageFormat;
48
import java.util.AbstractCollection;
47
import java.util.AbstractCollection;
49
import java.util.ArrayList;
48
import java.util.ArrayList;
Lines 75-81 Link Here
75
import org.netbeans.modules.parsing.spi.indexing.Indexable;
74
import org.netbeans.modules.parsing.spi.indexing.Indexable;
76
import org.openide.util.Pair;
75
import org.openide.util.Pair;
77
import org.openide.util.Parameters;
76
import org.openide.util.Parameters;
78
import org.openide.util.BaseUtilities;
77
import org.openide.util.CallbackReferences;
79
78
80
/**
79
/**
81
 *
80
 *
Lines 493-499 Link Here
493
    //</editor-fold>
492
    //</editor-fold>
494
493
495
    //<editor-fold defaultstate="collapsed" desc="Flushing Soft Reference">
494
    //<editor-fold defaultstate="collapsed" desc="Flushing Soft Reference">
496
    private static final class ClearReference extends SoftReference<Collection[]> implements Runnable, Callable<Void> {
495
    private static final class ClearReference extends CallbackReferences.SoftCallback<Collection[]> implements Callable<Void> {
497
496
498
        private final DocumentIndexCacheImpl owner;
497
        private final DocumentIndexCacheImpl owner;
499
        private final AtomicInteger state = new AtomicInteger();
498
        private final AtomicInteger state = new AtomicInteger();
Lines 501-507 Link Here
501
        public ClearReference(
500
        public ClearReference(
502
                @NonNull final Collection[] data,
501
                @NonNull final Collection[] data,
503
                @NonNull final DocumentIndexCacheImpl owner) {
502
                @NonNull final DocumentIndexCacheImpl owner) {
504
            super(data, BaseUtilities.activeReferenceQueue());
503
            super(data);
505
            Parameters.notNull("data", data);   //NOI18N
504
            Parameters.notNull("data", data);   //NOI18N
506
            Parameters.notNull("owner", owner); //NOI18N
505
            Parameters.notNull("owner", owner); //NOI18N
507
            this.owner = owner;
506
            this.owner = owner;
(-)a/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/PathRegistry.java (-3 / +3 lines)
Lines 81-87 Link Here
81
import org.openide.util.Exceptions;
81
import org.openide.util.Exceptions;
82
import org.openide.util.Parameters;
82
import org.openide.util.Parameters;
83
import org.openide.util.RequestProcessor;
83
import org.openide.util.RequestProcessor;
84
import org.openide.util.BaseUtilities;
84
import org.openide.util.CallbackReferences;
85
import org.openide.util.WeakListeners;
85
import org.openide.util.WeakListeners;
86
86
87
/**
87
/**
Lines 1190-1201 Link Here
1190
        }
1190
        }
1191
    }
1191
    }
1192
1192
1193
    private class WeakValue extends WeakReference<ClassPath> implements Runnable {
1193
    private class WeakValue extends CallbackReferences.WeakCallback<ClassPath> {
1194
1194
1195
        private final URL key;
1195
        private final URL key;
1196
1196
1197
        public WeakValue (ClassPath ref, URL key) {
1197
        public WeakValue (ClassPath ref, URL key) {
1198
            super (ref, BaseUtilities.activeReferenceQueue());
1198
            super (ref);
1199
            assert key != null;
1199
            assert key != null;
1200
            this.key = key;
1200
            this.key = key;
1201
        }
1201
        }
(-)a/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/URLCache.java (-4 / +3 lines)
Lines 42-48 Link Here
42
package org.netbeans.modules.parsing.impl.indexing;
42
package org.netbeans.modules.parsing.impl.indexing;
43
43
44
import java.lang.ref.Reference;
44
import java.lang.ref.Reference;
45
import java.lang.ref.WeakReference;
46
import java.net.URI;
45
import java.net.URI;
47
import java.net.URISyntaxException;
46
import java.net.URISyntaxException;
48
import java.net.URL;
47
import java.net.URL;
Lines 56-62 Link Here
56
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.URLMapper;
56
import org.openide.filesystems.URLMapper;
58
import org.openide.util.Exceptions;
57
import org.openide.util.Exceptions;
59
import org.openide.util.BaseUtilities;
58
import org.openide.util.CallbackReferences;
60
59
61
/**
60
/**
62
 * Cache for {@link URLMapper#findFileObject} for source roots.
61
 * Cache for {@link URLMapper#findFileObject} for source roots.
Lines 129-142 Link Here
129
    private URLCache() {
128
    private URLCache() {
130
    }
129
    }
131
    
130
    
132
    private final class CleanReference extends WeakReference<FileObject> implements Runnable {        
131
    private final class CleanReference extends CallbackReferences.WeakCallback<FileObject> {
133
        
132
        
134
        private final URI uri;
133
        private final URI uri;
135
        
134
        
136
        CleanReference(
135
        CleanReference(
137
                @NonNull FileObject referent,
136
                @NonNull FileObject referent,
138
                @NonNull URI uri) {            
137
                @NonNull URI uri) {            
139
            super(referent, BaseUtilities.activeReferenceQueue());
138
            super(referent);
140
            assert referent != null;
139
            assert referent != null;
141
            assert uri != null;
140
            assert uri != null;
142
            this.uri = uri;
141
            this.uri = uri;
(-)a/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java (-3 / +3 lines)
Lines 48-54 Link Here
48
import java.io.FileNotFoundException;
48
import java.io.FileNotFoundException;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.io.InterruptedIOException;
50
import java.io.InterruptedIOException;
51
import java.lang.ref.SoftReference;
52
import java.net.URI;
51
import java.net.URI;
53
import java.nio.channels.ClosedByInterruptException;
52
import java.nio.channels.ClosedByInterruptException;
54
import java.nio.file.Path;
53
import java.nio.file.Path;
Lines 92-97 Link Here
92
import org.netbeans.modules.parsing.lucene.support.IndexReaderInjection;
91
import org.netbeans.modules.parsing.lucene.support.IndexReaderInjection;
93
import org.netbeans.modules.parsing.lucene.support.StoppableConvertor;
92
import org.netbeans.modules.parsing.lucene.support.StoppableConvertor;
94
import org.openide.util.BaseUtilities;
93
import org.openide.util.BaseUtilities;
94
import org.openide.util.CallbackReferences;
95
import org.openide.util.Exceptions;
95
import org.openide.util.Exceptions;
96
import org.openide.util.Pair;
96
import org.openide.util.Pair;
97
import org.openide.util.Parameters;
97
import org.openide.util.Parameters;
Lines 1208-1221 Link Here
1208
            }
1208
            }
1209
        }
1209
        }
1210
1210
1211
        private final class CleanReference extends SoftReference<RAMDirectory[]> implements Runnable {
1211
        private final class CleanReference extends CallbackReferences.SoftCallback<RAMDirectory[]> {
1212
            
1212
            
1213
            @SuppressWarnings("VolatileArrayField")
1213
            @SuppressWarnings("VolatileArrayField")
1214
            private volatile Directory[] hardRef; //clearHRef may be called by more concurrently (read lock).
1214
            private volatile Directory[] hardRef; //clearHRef may be called by more concurrently (read lock).
1215
            private final AtomicLong size = new AtomicLong();  //clearHRef may be called by more concurrently (read lock).
1215
            private final AtomicLong size = new AtomicLong();  //clearHRef may be called by more concurrently (read lock).
1216
1216
1217
            private CleanReference(final RAMDirectory[] dir) {
1217
            private CleanReference(final RAMDirectory[] dir) {
1218
                super (dir, BaseUtilities.activeReferenceQueue());
1218
                super (dir);
1219
                final IndexCacheFactory.RAMController c = IndexCacheFactory.getDefault().getRAMController();
1219
                final IndexCacheFactory.RAMController c = IndexCacheFactory.getDefault().getRAMController();
1220
                final boolean doHardRef = !c.isFull();
1220
                final boolean doHardRef = !c.isFull();
1221
                if (doHardRef) {
1221
                if (doHardRef) {
(-)a/parsing.lucene/src/org/netbeans/modules/parsing/lucene/support/IndexManager.java (-4 / +3 lines)
Lines 45-51 Link Here
45
import java.io.File;
45
import java.io.File;
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.lang.ref.Reference;
47
import java.lang.ref.Reference;
48
import java.lang.ref.WeakReference;
49
import java.util.ArrayList;
48
import java.util.ArrayList;
50
import java.util.Collection;
49
import java.util.Collection;
51
import java.util.Collections;
50
import java.util.Collections;
Lines 66-72 Link Here
66
import org.netbeans.modules.parsing.lucene.SupportAccessor;
65
import org.netbeans.modules.parsing.lucene.SupportAccessor;
67
import org.netbeans.modules.parsing.lucene.spi.ScanSuspendImplementation;
66
import org.netbeans.modules.parsing.lucene.spi.ScanSuspendImplementation;
68
import org.netbeans.modules.parsing.lucene.support.Index.WithTermFrequencies.TermFreq;
67
import org.netbeans.modules.parsing.lucene.support.Index.WithTermFrequencies.TermFreq;
69
import org.openide.util.BaseUtilities;
68
import org.openide.util.CallbackReferences;
70
import org.openide.util.Lookup;
69
import org.openide.util.Lookup;
71
import org.openide.util.LookupEvent;
70
import org.openide.util.LookupEvent;
72
import org.openide.util.LookupListener;
71
import org.openide.util.LookupListener;
Lines 500-511 Link Here
500
    private static final Map<File,Reference<Index>> indexes =
499
    private static final Map<File,Reference<Index>> indexes =
501
            Collections.synchronizedMap(new HashMap<File, Reference<Index>>());
500
            Collections.synchronizedMap(new HashMap<File, Reference<Index>>());
502
501
503
    private static class Ref extends WeakReference<Index> implements Runnable {
502
    private static class Ref extends CallbackReferences.WeakCallback<Index> {
504
503
505
        private final File folder;
504
        private final File folder;
506
505
507
        Ref(@NonNull final File folder, @NonNull final Index index) {
506
        Ref(@NonNull final File folder, @NonNull final Index index) {
508
            super(index, BaseUtilities.activeReferenceQueue());
507
            super(index);
509
            this.folder = folder;
508
            this.folder = folder;
510
        }
509
        }
511
510
(-)a/projectapi.nb/src/org/netbeans/modules/projectapi/nb/TimedWeakReference.java (-4 / +3 lines)
Lines 49-56 Link Here
49
//     timeout
49
//     timeout
50
//     removed map key functionality
50
//     removed map key functionality
51
51
52
import java.lang.ref.WeakReference;
52
import org.openide.util.CallbackReferences;
53
import org.openide.util.BaseUtilities;
54
import org.openide.util.RequestProcessor;
53
import org.openide.util.RequestProcessor;
55
54
56
/**
55
/**
Lines 71-77 Link Here
71
 * </ol>
70
 * </ol>
72
 * @author Jesse Glick
71
 * @author Jesse Glick
73
 */
72
 */
74
public final class TimedWeakReference<T> extends WeakReference<T> implements Runnable {
73
public final class TimedWeakReference<T> extends CallbackReferences.WeakCallback<T> {
75
    
74
    
76
    public static int TIMEOUT = 15000;
75
    public static int TIMEOUT = 15000;
77
    
76
    
Lines 89-95 Link Here
89
     * @param o the referent
88
     * @param o the referent
90
     */
89
     */
91
    public TimedWeakReference(T o) {
90
    public TimedWeakReference(T o) {
92
        super(o, BaseUtilities.activeReferenceQueue());
91
        super(o);
93
        this.o = o;
92
        this.o = o;
94
        task = RP.create(this);
93
        task = RP.create(this);
95
        task.schedule(TIMEOUT);
94
        task.schedule(TIMEOUT);
(-)a/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsControllerImpl.java (-3 / +3 lines)
Lines 48-54 Link Here
48
import java.beans.PropertyChangeSupport;
48
import java.beans.PropertyChangeSupport;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.lang.ref.Reference;
50
import java.lang.ref.Reference;
51
import java.lang.ref.WeakReference;
52
import java.util.ArrayList;
51
import java.util.ArrayList;
53
import java.util.Collection;
52
import java.util.Collection;
54
import java.util.Collections;
53
import java.util.Collections;
Lines 77-82 Link Here
77
import org.openide.text.NbDocument;
76
import org.openide.text.NbDocument;
78
import org.openide.text.PositionBounds;
77
import org.openide.text.PositionBounds;
79
import org.openide.text.PositionRef;
78
import org.openide.text.PositionRef;
79
import org.openide.util.CallbackReferences;
80
import org.openide.util.Exceptions;
80
import org.openide.util.Exceptions;
81
81
82
/**
82
/**
Lines 293-304 Link Here
293
        }
293
        }
294
    }
294
    }
295
295
296
    private static final class CleaningReference extends WeakReference<Fix> implements Runnable {
296
    private static final class CleaningReference extends CallbackReferences.WeakCallback<Fix> {
297
297
298
        private final int hashCode;
298
        private final int hashCode;
299
299
300
        public CleaningReference(Fix referent) {
300
        public CleaningReference(Fix referent) {
301
            super(referent, org.openide.util.Utilities.activeReferenceQueue());
301
            super(referent);
302
            hashCode = System.identityHashCode(referent);
302
            hashCode = System.identityHashCode(referent);
303
        }
303
        }
304
304
(-)a/spring.beans/src/org/netbeans/modules/spring/util/fcs/FileChangeSupport.java (-4 / +3 lines)
Lines 48-54 Link Here
48
import java.util.Map;
48
import java.util.Map;
49
import java.util.WeakHashMap;
49
import java.util.WeakHashMap;
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
51
import java.lang.ref.WeakReference;
52
import java.util.HashMap;
51
import java.util.HashMap;
53
52
54
import org.openide.filesystems.FileChangeListener;
53
import org.openide.filesystems.FileChangeListener;
Lines 56-62 Link Here
56
import org.openide.filesystems.FileEvent;
55
import org.openide.filesystems.FileEvent;
57
import org.openide.filesystems.FileRenameEvent;
56
import org.openide.filesystems.FileRenameEvent;
58
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
59
import org.openide.util.Utilities;
58
import org.openide.util.CallbackReferences;
60
59
61
// XXX current implementation is not efficient for listening to a large # of files
60
// XXX current implementation is not efficient for listening to a large # of files
62
61
Lines 116-129 Link Here
116
        }
115
        }
117
    }
116
    }
118
    
117
    
119
    private static final class Holder extends WeakReference<FileChangeSupportListener> implements FileChangeListener, Runnable {
118
    private static final class Holder extends CallbackReferences.WeakCallback<FileChangeSupportListener> implements FileChangeListener {
120
        
119
        
121
        private final File path;
120
        private final File path;
122
        private FileObject current;
121
        private FileObject current;
123
        private File currentF;
122
        private File currentF;
124
        
123
        
125
        public Holder(FileChangeSupportListener listener, File path) {
124
        public Holder(FileChangeSupportListener listener, File path) {
126
            super(listener, Utilities.activeReferenceQueue());
125
            super(listener);
127
            assert path != null;
126
            assert path != null;
128
            this.path = path;
127
            this.path = path;
129
            locateCurrent();
128
            locateCurrent();
(-)a/timers/src/org/netbeans/modules/timers/InstanceWatcher.java (-3 / +3 lines)
Lines 53-59 Link Here
53
import java.util.Map;
53
import java.util.Map;
54
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeEvent;
55
import javax.swing.event.ChangeListener;
55
import javax.swing.event.ChangeListener;
56
import org.openide.util.Utilities;
56
import org.openide.util.CallbackReferences;
57
57
58
/** A class for watching instances.
58
/** A class for watching instances.
59
 *
59
 *
Lines 180-189 Link Here
180
180
181
    // Private innerclasses ----------------------------------------------------
181
    // Private innerclasses ----------------------------------------------------
182
    
182
    
183
    private final class CleanableWeakReference extends WeakReference<Object> implements Runnable {
183
    private final class CleanableWeakReference extends CallbackReferences.WeakCallback<Object> {
184
184
185
        public CleanableWeakReference(Object i) {
185
        public CleanableWeakReference(Object i) {
186
            super(i, Utilities.activeReferenceQueue());
186
            super(i);
187
        }
187
        }
188
188
189
        public void run() {
189
        public void run() {
(-)a/timers/src/org/netbeans/modules/timers/TimesCollectorPeer.java (-3 / +3 lines)
Lines 57-66 Link Here
57
import javax.swing.event.ChangeEvent;
57
import javax.swing.event.ChangeEvent;
58
import javax.swing.event.ChangeListener;
58
import javax.swing.event.ChangeListener;
59
import org.openide.util.RequestProcessor;
59
import org.openide.util.RequestProcessor;
60
import org.openide.util.Utilities;
61
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileChangeAdapter;
61
import org.openide.filesystems.FileChangeAdapter;
63
import org.openide.filesystems.FileEvent;
62
import org.openide.filesystems.FileEvent;
63
import org.openide.util.CallbackReferences;
64
64
65
/**
65
/**
66
 *
66
 *
Lines 240-248 Link Here
240
    }
240
    }
241
241
242
    private static final RequestProcessor CLEANER = new RequestProcessor("CleanableWeakReference"); // NOI18N
242
    private static final RequestProcessor CLEANER = new RequestProcessor("CleanableWeakReference"); // NOI18N
243
    private class CleanableWeakReference<T> extends WeakReference<T> implements Runnable {
243
    private class CleanableWeakReference<T> extends CallbackReferences.WeakCallback<T> {
244
        public CleanableWeakReference(T o) {
244
        public CleanableWeakReference(T o) {
245
            super(o, Utilities.activeReferenceQueue());
245
            super(o);
246
        }
246
        }
247
247
248
        public void run() {
248
        public void run() {
(-)a/vmd.model/src/org/netbeans/modules/vmd/api/model/DesignDocument.java (-5 / +3 lines)
Lines 43-52 Link Here
43
 */
43
 */
44
package org.netbeans.modules.vmd.api.model;
44
package org.netbeans.modules.vmd.api.model;
45
45
46
import org.openide.util.Utilities;
47
48
import java.lang.ref.WeakReference;
49
import java.util.*;
46
import java.util.*;
47
import org.openide.util.CallbackReferences;
50
48
51
/**
49
/**
52
 * This class represents a document holding all components.
50
 * This class represents a document holding all components.
Lines 393-404 Link Here
393
        }
391
        }
394
    }
392
    }
395
393
396
    private final class TimedWeakReference extends WeakReference<DesignComponent> implements Runnable {
394
    private final class TimedWeakReference extends CallbackReferences.WeakCallback<DesignComponent> {
397
395
398
        private final long componentID;
396
        private final long componentID;
399
397
400
        public TimedWeakReference (DesignComponent referent) {
398
        public TimedWeakReference (DesignComponent referent) {
401
            super (referent, Utilities.activeReferenceQueue ());
399
            super (referent);
402
            this.componentID = referent.getComponentID ();
400
            this.componentID = referent.getComponentID ();
403
        }
401
        }
404
402
(-)a/xml.tax/src/org/netbeans/modules/xml/tax/cookies/TreeEditorCookieImpl.java (-3 / +3 lines)
Lines 66-72 Link Here
66
import org.netbeans.modules.xml.tax.parser.DTDParsingSupport;
66
import org.netbeans.modules.xml.tax.parser.DTDParsingSupport;
67
import org.netbeans.modules.xml.tax.parser.ParsingSupport;
67
import org.netbeans.modules.xml.tax.parser.ParsingSupport;
68
import org.netbeans.modules.xml.tax.parser.XMLParsingSupport;
68
import org.netbeans.modules.xml.tax.parser.XMLParsingSupport;
69
import org.openide.util.Utilities;
69
import org.openide.util.CallbackReferences;
70
70
71
/** 
71
/** 
72
 * @author  Libor Kramolis
72
 * @author  Libor Kramolis
Lines 555-564 Link Here
555
    /*
555
    /*
556
     * Reference which remembers which editor created stored TreeDocumentRoot.
556
     * Reference which remembers which editor created stored TreeDocumentRoot.
557
     */
557
     */
558
    private class TreeReference extends WeakReference implements Runnable {
558
    private class TreeReference extends CallbackReferences.WeakCallback {
559
        
559
        
560
        TreeReference (TreeDocumentRoot root) {
560
        TreeReference (TreeDocumentRoot root) {
561
            super(root, Utilities.activeReferenceQueue());
561
            super(root);
562
        }
562
        }
563
        
563
        
564
        public TreeDocumentRoot getDocumentRoot() {
564
        public TreeDocumentRoot getDocumentRoot() {

Return to bug 257013