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

(-)a/projectapi/src/org/netbeans/modules/projectapi/LazyLookupProviders.java (-9 / +30 lines)
Lines 42-47 Link Here
42
42
43
package org.netbeans.modules.projectapi;
43
package org.netbeans.modules.projectapi;
44
44
45
import java.lang.ref.Reference;
46
import java.lang.ref.WeakReference;
45
import java.lang.reflect.Constructor;
47
import java.lang.reflect.Constructor;
46
import java.lang.reflect.Member;
48
import java.lang.reflect.Member;
47
import java.lang.reflect.Method;
49
import java.lang.reflect.Method;
Lines 83-91 Link Here
83
     */
85
     */
84
    public static LookupProvider forProjectServiceProvider(final Map<String,Object> attrs) throws ClassNotFoundException {
86
    public static LookupProvider forProjectServiceProvider(final Map<String,Object> attrs) throws ClassNotFoundException {
85
        return new LookupProvider() {
87
        return new LookupProvider() {
88
            private final Map<Lookup,Reference<Lookup>> lkps = Collections.synchronizedMap(new WeakHashMap<Lookup, Reference<Lookup>>());
86
            @Override
89
            @Override
87
            public Lookup createAdditionalLookup(final Lookup lkp) {
90
            public Lookup createAdditionalLookup(final Lookup lkp) {
88
                final Lookup result =  new ProxyLookup() {
91
                Reference<Lookup> resRef = lkps.get(lkp);
92
                Lookup result;
93
                if (resRef != null && (result=resRef.get()) != null) {
94
                    return result;
95
                }
96
                result =  new ProxyLookup() {
89
                    Collection<String> serviceNames = Arrays.asList(((String) attrs.get("service")).split(",")); // NOI18N
97
                    Collection<String> serviceNames = Arrays.asList(((String) attrs.get("service")).split(",")); // NOI18N
90
                    final ThreadLocal<Boolean> insideBeforeLookup = new ThreadLocal<Boolean>(); // #212862
98
                    final ThreadLocal<Boolean> insideBeforeLookup = new ThreadLocal<Boolean>(); // #212862
91
                    final Object LOCK = new Object();
99
                    final Object LOCK = new Object();
Lines 138-151 Link Here
138
                        }
146
                        }
139
                    }
147
                    }
140
                };
148
                };
141
                LOG.log(
149
                boolean created = false;
142
                    Level.FINE,
150
                synchronized (lkps) {
143
                    "Additional lookup created: {0} service class: {1} for base lookup: {2}",   //NOI18N
151
                    resRef = lkps.get(lkp);
144
                    new Object[]{
152
                    final Lookup tmp;
145
                        System.identityHashCode(result),
153
                    if (resRef == null || (tmp = resRef.get()) == null) {
146
                        attrs.get("class"),
154
                        lkps.put(lkp, new WeakReference<Lookup>(result));
147
                        System.identityHashCode(lkp)
155
                        created = true;
148
                    });
156
                    } else {
157
                        result = tmp;
158
                    }
159
                }
160
                if (created) {
161
                    LOG.log(
162
                        Level.FINE,
163
                        "Additional lookup created: {0} service class: {1} for base lookup: {2}",   //NOI18N
164
                        new Object[]{
165
                            System.identityHashCode(result),
166
                            attrs.get("class"),
167
                            System.identityHashCode(lkp)
168
                        });
169
                }
149
                return result;
170
                return result;
150
            }
171
            }
151
            
172
            

Return to bug 232400