Lines 63-68
import java.util.Set;
Link Here
|
63 |
import java.util.Set; |
63 |
import java.util.Set; |
64 |
import java.util.TreeSet; |
64 |
import java.util.TreeSet; |
65 |
|
65 |
|
|
|
66 |
import java.util.concurrent.Executor; |
66 |
import org.openide.util.Utilities; |
67 |
import org.openide.util.Utilities; |
67 |
|
68 |
|
68 |
|
69 |
|
Lines 200-209
public class AbstractLookup extends Look
Link Here
|
200 |
* @param pair class/instance pair |
201 |
* @param pair class/instance pair |
201 |
*/ |
202 |
*/ |
202 |
protected final void addPair(Pair<?> pair) { |
203 |
protected final void addPair(Pair<?> pair) { |
203 |
addPairImpl(pair); |
204 |
addPairImpl(pair, null); |
204 |
} |
205 |
} |
205 |
|
206 |
|
206 |
private final <Transaction> void addPairImpl(Pair<?> pair) { |
207 |
/** The method to add instance to the lookup with. |
|
|
208 |
* @param pair class/instance pair |
209 |
* @param notifyIn the executor that will handle the notification of events |
210 |
* @since 7.16 |
211 |
*/ |
212 |
protected final void addPair(Pair<?> pair, Executor notifyIn) { |
213 |
addPairImpl(pair, notifyIn); |
214 |
} |
215 |
|
216 |
private final <Transaction> void addPairImpl(Pair<?> pair, Executor notifyIn) { |
207 |
HashSet<R> toNotify = new HashSet<R>(); |
217 |
HashSet<R> toNotify = new HashSet<R>(); |
208 |
|
218 |
|
209 |
AbstractLookup.Storage<Transaction> t = enterStorage(); |
219 |
AbstractLookup.Storage<Transaction> t = enterStorage(); |
Lines 233-249
public class AbstractLookup extends Look
Link Here
|
233 |
exitStorage(); |
243 |
exitStorage(); |
234 |
} |
244 |
} |
235 |
|
245 |
|
236 |
notifyListeners(toNotify); |
246 |
notifyIn(notifyIn, toNotify); |
237 |
} |
247 |
} |
238 |
|
248 |
|
239 |
/** Remove instance. |
249 |
/** Remove instance. |
240 |
* @param pair class/instance pair |
250 |
* @param pair class/instance pair |
241 |
*/ |
251 |
*/ |
242 |
protected final void removePair(Pair<?> pair) { |
252 |
protected final void removePair(Pair<?> pair) { |
243 |
removePairImpl(pair); |
253 |
removePairImpl(pair, null); |
|
|
254 |
} |
255 |
/** Remove instance. |
256 |
* @param pair class/instance pair |
257 |
* @param notifyIn the executor that will handle the notification of events |
258 |
* @since 7.16 |
259 |
*/ |
260 |
protected final void removePair(Pair<?> pair, Executor notifyIn) { |
261 |
removePairImpl(pair, notifyIn); |
244 |
} |
262 |
} |
245 |
|
263 |
|
246 |
private <Transaction> void removePairImpl(Pair<?> pair) { |
264 |
private <Transaction> void removePairImpl(Pair<?> pair, Executor notifyIn) { |
247 |
HashSet<R> toNotify = new HashSet<R>(); |
265 |
HashSet<R> toNotify = new HashSet<R>(); |
248 |
|
266 |
|
249 |
AbstractLookup.Storage<Transaction> t = enterStorage(); |
267 |
AbstractLookup.Storage<Transaction> t = enterStorage(); |
Lines 257-270
public class AbstractLookup extends Look
Link Here
|
257 |
exitStorage(); |
275 |
exitStorage(); |
258 |
} |
276 |
} |
259 |
|
277 |
|
260 |
notifyListeners(toNotify); |
278 |
notifyIn(notifyIn, toNotify); |
261 |
} |
279 |
} |
262 |
|
280 |
|
263 |
/** Changes all pairs in the lookup to new values. |
281 |
/** Changes all pairs in the lookup to new values. |
264 |
* @param collection the collection of (Pair) objects |
282 |
* @param collection the collection of (Pair) objects |
265 |
*/ |
283 |
*/ |
266 |
protected final void setPairs(Collection<? extends Pair> collection) { |
284 |
protected final void setPairs(Collection<? extends Pair> collection) { |
267 |
notifyCollectedListeners(setPairsAndCollectListeners(collection)); |
285 |
setPairs(collection, null); |
|
|
286 |
} |
287 |
|
288 |
/** Changes all pairs in the lookup to new values, notifies listeners |
289 |
* using provided executor. |
290 |
* |
291 |
* @param collection the collection of (Pair) objects |
292 |
* @param notifyIn the executor that will handle the notification of events |
293 |
* @since 7.16 |
294 |
*/ |
295 |
protected final void setPairs(Collection<? extends Pair> collection, Executor notifyIn) { |
296 |
HashSet<R> listeners = setPairsAndCollectListeners(collection); |
297 |
notifyIn(notifyIn, listeners); |
298 |
} |
299 |
|
300 |
private final void notifyIn(Executor notifyIn, final HashSet<R> listeners) { |
301 |
if (notifyIn == null) { |
302 |
notifyListeners(listeners); |
303 |
return; |
304 |
} |
305 |
|
306 |
class Notify implements Runnable { |
307 |
public void run() { |
308 |
notifyListeners(listeners); |
309 |
} |
310 |
} |
311 |
notifyIn.execute(new Notify()); |
268 |
} |
312 |
} |
269 |
|
313 |
|
270 |
/** Getter for set of pairs. Package private contract with MetaInfServicesLookup. |
314 |
/** Getter for set of pairs. Package private contract with MetaInfServicesLookup. |
Lines 349-361
public class AbstractLookup extends Look
Link Here
|
349 |
} |
393 |
} |
350 |
|
394 |
|
351 |
return toNotify; |
395 |
return toNotify; |
352 |
} |
|
|
353 |
|
354 |
/** Notifies all collected listeners. Needed by MetaInfServicesLookup, |
355 |
* maybe it will be an API later. |
356 |
*/ |
357 |
final void notifyCollectedListeners(Set<R> listeners) { |
358 |
notifyListeners(listeners); |
359 |
} |
396 |
} |
360 |
|
397 |
|
361 |
private final void writeObject(ObjectOutputStream oos) |
398 |
private final void writeObject(ObjectOutputStream oos) |
Lines 461-467
public class AbstractLookup extends Look
Link Here
|
461 |
/** Notifies listeners. |
498 |
/** Notifies listeners. |
462 |
* @param allAffectedResults set of R |
499 |
* @param allAffectedResults set of R |
463 |
*/ |
500 |
*/ |
464 |
private static void notifyListeners(Set<R> allAffectedResults) { |
501 |
static void notifyListeners(Set<R> allAffectedResults) { |
465 |
if (allAffectedResults.isEmpty()) { |
502 |
if (allAffectedResults.isEmpty()) { |
466 |
return; |
503 |
return; |
467 |
} |
504 |
} |
Lines 1078-1085
public class AbstractLookup extends Look
Link Here
|
1078 |
// one of them is always null (except attach stage) |
1115 |
// one of them is always null (except attach stage) |
1079 |
|
1116 |
|
1080 |
/** abstract lookup we are connected to */ |
1117 |
/** abstract lookup we are connected to */ |
1081 |
private AbstractLookup al = null; |
1118 |
private AbstractLookup al; |
1082 |
private transient ArrayList<Pair> earlyPairs; |
1119 |
private transient Object notifyIn; |
|
|
1120 |
|
1121 |
/** Default constructor. |
1122 |
*/ |
1123 |
public Content() { |
1124 |
this(null); |
1125 |
} |
1126 |
|
1127 |
/** Creates a content associated with an executor to handle dispatch |
1128 |
* of changes. |
1129 |
* @param notifyIn the executor to notify changes in |
1130 |
* @since 7.16 |
1131 |
*/ |
1132 |
public Content(Executor notifyIn) { |
1133 |
this.notifyIn = notifyIn; |
1134 |
} |
1135 |
|
1136 |
/** for testing purposes */ |
1137 |
final void attachExecutor(Executor notifyIn) { |
1138 |
this.notifyIn = notifyIn; |
1139 |
} |
1083 |
|
1140 |
|
1084 |
/** A lookup attaches to this object. |
1141 |
/** A lookup attaches to this object. |
1085 |
*/ |
1142 |
*/ |
Lines 1087-1095
public class AbstractLookup extends Look
Link Here
|
1087 |
if (this.al == null) { |
1144 |
if (this.al == null) { |
1088 |
this.al = al; |
1145 |
this.al = al; |
1089 |
|
1146 |
|
1090 |
if (earlyPairs != null) { |
1147 |
ArrayList<Pair> ep = getEarlyPairs(); |
1091 |
ArrayList<Pair> ep = earlyPairs; |
1148 |
if (ep != null) { |
1092 |
earlyPairs = null; |
1149 |
notifyIn = null; |
1093 |
setPairs(ep); |
1150 |
setPairs(ep); |
1094 |
} |
1151 |
} |
1095 |
} else { |
1152 |
} else { |
Lines 1104-1118
public class AbstractLookup extends Look
Link Here
|
1104 |
*/ |
1161 |
*/ |
1105 |
public final void addPair(Pair<?> pair) { |
1162 |
public final void addPair(Pair<?> pair) { |
1106 |
AbstractLookup a = al; |
1163 |
AbstractLookup a = al; |
|
|
1164 |
Executor e = getExecutor(); |
1107 |
|
1165 |
|
1108 |
if (a != null) { |
1166 |
if (a != null || e != null) { |
1109 |
a.addPair(pair); |
1167 |
a.addPair(pair, e); |
1110 |
} else { |
1168 |
} else { |
1111 |
if (earlyPairs == null) { |
1169 |
if (notifyIn == null) { |
1112 |
earlyPairs = new ArrayList<Pair>(3); |
1170 |
notifyIn = new ArrayList<Pair>(3); |
1113 |
} |
1171 |
} |
1114 |
|
1172 |
|
1115 |
earlyPairs.add(pair); |
1173 |
getEarlyPairs().add(pair); |
1116 |
} |
1174 |
} |
1117 |
} |
1175 |
} |
1118 |
|
1176 |
|
Lines 1121-1135
public class AbstractLookup extends Look
Link Here
|
1121 |
*/ |
1179 |
*/ |
1122 |
public final void removePair(Pair<?> pair) { |
1180 |
public final void removePair(Pair<?> pair) { |
1123 |
AbstractLookup a = al; |
1181 |
AbstractLookup a = al; |
|
|
1182 |
Executor e = getExecutor(); |
1124 |
|
1183 |
|
1125 |
if (a != null) { |
1184 |
if (a != null || e != null) { |
1126 |
a.removePair(pair); |
1185 |
a.removePair(pair, e); |
1127 |
} else { |
1186 |
} else { |
1128 |
if (earlyPairs == null) { |
1187 |
if (notifyIn == null) { |
1129 |
earlyPairs = new ArrayList<Pair>(3); |
1188 |
notifyIn = new ArrayList<Pair>(3); |
1130 |
} |
1189 |
} |
1131 |
|
1190 |
|
1132 |
earlyPairs.remove(pair); |
1191 |
getEarlyPairs().remove(pair); |
1133 |
} |
1192 |
} |
1134 |
} |
1193 |
} |
1135 |
|
1194 |
|
Lines 1138-1149
public class AbstractLookup extends Look
Link Here
|
1138 |
*/ |
1197 |
*/ |
1139 |
public final void setPairs(Collection<? extends Pair> c) { |
1198 |
public final void setPairs(Collection<? extends Pair> c) { |
1140 |
AbstractLookup a = al; |
1199 |
AbstractLookup a = al; |
|
|
1200 |
Executor e = getExecutor(); |
1201 |
|
1202 |
if (a != null || e != null) { |
1203 |
a.setPairs(c, e); |
1204 |
} else { |
1205 |
notifyIn = new ArrayList<Pair>(c); |
1206 |
} |
1207 |
} |
1141 |
|
1208 |
|
1142 |
if (a != null) { |
1209 |
@SuppressWarnings("unchecked") |
1143 |
a.setPairs(c); |
1210 |
private ArrayList<Pair> getEarlyPairs() { |
1144 |
} else { |
1211 |
Object o = notifyIn; |
1145 |
earlyPairs = new ArrayList<Pair>(c); |
1212 |
return o instanceof ArrayList ? (ArrayList<Pair>)o : null; |
1146 |
} |
1213 |
} |
|
|
1214 |
|
1215 |
private Executor getExecutor() { |
1216 |
Object o = notifyIn; |
1217 |
return o instanceof Executor ? (Executor)o : null; |
1147 |
} |
1218 |
} |
1148 |
} |
1219 |
} |
1149 |
// end of Content |
1220 |
// end of Content |