private void handleReparent(EclipseContext newParent, Set<Scheduled> scheduled) { // TBD should we lock waiting list while doing reparent? // Add "boolean inReparent" on the root context and process right away? processWaiting(); // 1) everybody who depends on me: I need to collect combined list of names injected Set<String> usedNames = new HashSet<String>(); collectDependentNames(usedNames); // 2) for each used name: for (Iterator<String> i = usedNames.iterator(); i.hasNext(); ) { String name = i.next(); if (localValues.containsKey(name)) continue; // it is a local value Object oldValue = get(name); Object newValue = (newParent != null) ? newParent.get(name) : null; if (oldValue != newValue) invalidate(name, ContextChangeEvent.ADDED, oldValue, scheduled); } ContextChangeEvent event = new ContextChangeEvent(this, ContextChangeEvent.ADDED, null, null, null); for (Computation computation : localValueComputations.values()) { Collection<HashSet<Computation>> allListeners = listeners.values(); for (HashSet<Computation> group : allListeners) { group.remove(computation); } computation.handleInvalid(event, scheduled); } localValueComputations.clear(); }
public void processWaiting() { // traverse to the root node EclipseContext parent = getParent(); if (parent != null) { parent.processWaiting(); return; } if (waiting == null) return; // create update notifications Computation[] ls = waiting.toArray(new Computation[waiting.size()]); waiting.clear(); ContextChangeEvent event = new ContextChangeEvent(this, ContextChangeEvent.UPDATE, null, null, null); for (int i = 0; i < ls.length; i++) { if (ls[i] instanceof TrackableComputationExt) ((TrackableComputationExt) ls[i]).update(event); } }