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

(-)a/openide.util.lookup/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.util.lookup
2
OpenIDE-Module: org.openide.util.lookup
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/lookup/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/lookup/Bundle.properties
4
OpenIDE-Module-Specification-Version: 8.30
4
OpenIDE-Module-Specification-Version: 8.31
5
5
(-)a/openide.util.lookup/src/org/netbeans/modules/openide/util/GlobalLookup.java (+13 lines)
Lines 46-55 Link Here
46
public class GlobalLookup {
46
public class GlobalLookup {
47
    private static final ThreadLocal<Lookup> CURRENT = new ThreadLocal<Lookup>();
47
    private static final ThreadLocal<Lookup> CURRENT = new ThreadLocal<Lookup>();
48
    
48
    
49
    /**
50
     * The true system Lookup, the main, holy and only.
51
     */
52
    private static volatile Lookup systemLookup;
53
    
49
    private GlobalLookup() {
54
    private GlobalLookup() {
50
    }
55
    }
51
56
57
    @SuppressWarnings("AssignmentToMethodParameter")
52
    public static boolean execute(Lookup defaultLookup, Runnable r) {
58
    public static boolean execute(Lookup defaultLookup, Runnable r) {
59
        if (defaultLookup == null) {
60
            defaultLookup = systemLookup;
61
        }
53
        Lookup prev = CURRENT.get();
62
        Lookup prev = CURRENT.get();
54
        if (prev == defaultLookup) {
63
        if (prev == defaultLookup) {
55
            return false;
64
            return false;
Lines 66-69 Link Here
66
    public static Lookup current() {
75
    public static Lookup current() {
67
        return CURRENT.get();
76
        return CURRENT.get();
68
    }
77
    }
78
    
79
    public static void setSystemLookup(Lookup lkp) {
80
        systemLookup = lkp;
81
    }
69
}
82
}
(-)a/openide.util.lookup/src/org/openide/util/Lookup.java (-1 / +4 lines)
Lines 127-134 Link Here
127
                if (lkp != null) {
127
                if (lkp != null) {
128
                    return lkp;
128
                    return lkp;
129
                }
129
                }
130
            } else {
131
                return defaultLookup;
130
            }
132
            }
131
            return defaultLookup;
132
        }
133
        }
133
        LOG.log(Level.FINER, "About to initialize Lookup@{0}.getDefault() by {1}", 
134
        LOG.log(Level.FINER, "About to initialize Lookup@{0}.getDefault() by {1}", 
134
            new Object[] { Lookup.class.getClassLoader(), Thread.currentThread() }
135
            new Object[] { Lookup.class.getClassLoader(), Thread.currentThread() }
Lines 149-154 Link Here
149
            if (className != null) {
150
            if (className != null) {
150
                Object o = Class.forName(className, true, l).newInstance();
151
                Object o = Class.forName(className, true, l).newInstance();
151
                defaultLookup = (Lookup)o;
152
                defaultLookup = (Lookup)o;
153
                // set the global global Lookuo
154
                GlobalLookup.setSystemLookup(defaultLookup);
152
                LOG.log(Level.FINE, "Default lookup initialized {0}", defaultLookup);
155
                LOG.log(Level.FINE, "Default lookup initialized {0}", defaultLookup);
153
                // for testing purposes, tests may setup a class implementing both interfaces
156
                // for testing purposes, tests may setup a class implementing both interfaces
154
                if (o instanceof Lookup.Provider) {
157
                if (o instanceof Lookup.Provider) {
(-)a/openide.util.lookup/src/org/openide/util/lookup/Lookups.java (+9 lines)
Lines 285-294 Link Here
285
     * of {@link Lookup#getDefault()} to here-in provided lookup. Useful in a
285
     * of {@link Lookup#getDefault()} to here-in provided lookup. Useful in a
286
     * multi user environment where different users and their requests should
286
     * multi user environment where different users and their requests should
287
     * be associated with different content of default lookup.
287
     * be associated with different content of default lookup.
288
     * <p/>
289
     * As a special case, {@code executeWith} will execute the Runnable with
290
     * the system global lookup (the one effective during system bootstrap), when
291
     * the passed {@code defaultLookup} parameter is {@code null}. This feature may
292
     * be useful to switch from a specialized Lookup back to a default one for
293
     * some limited processing, or when the caller needs to bypass potential
294
     * execution-local content temporary effective in the default Lookup and
295
     * work with system-wide services only.
288
     * 
296
     * 
289
     * @param defaultLookup the lookup to be come default while code is running
297
     * @param defaultLookup the lookup to be come default while code is running
290
     * @param code the code to execute (synchronously) before the method returns
298
     * @param code the code to execute (synchronously) before the method returns
291
     * @since 8.30
299
     * @since 8.30
300
     * @since 8.31 can delegate to the system Lookup
292
     */
301
     */
293
    public static void executeWith(Lookup defaultLookup, Runnable code) {
302
    public static void executeWith(Lookup defaultLookup, Runnable code) {
294
        if (!GlobalLookup.execute(defaultLookup, code)) {
303
        if (!GlobalLookup.execute(defaultLookup, code)) {
(-)a/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java (+4 lines)
Lines 512-517 Link Here
512
512
513
                        if (o == null) {
513
                        if (o == null) {
514
                            o = SharedClassObjectBridge.newInstance(c);
514
                            o = SharedClassObjectBridge.newInstance(c);
515
                            Object other = CACHE.findInstance(c);
516
                            if (other != null) {
517
                                return object = other;
518
                            }
515
                            CACHE.storeInstance(o);
519
                            CACHE.storeInstance(o);
516
                        }
520
                        }
517
521

Return to bug 250873