diff options
3 files changed, 41 insertions, 44 deletions
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/Computation.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/Computation.java index caa28eb2e..4a8d9b6b2 100644 --- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/Computation.java +++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/Computation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 IBM Corporation and others. + * Copyright (c) 2009, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,4 +32,8 @@ abstract public class Computation { hashCode = calcHashCode(); } + public boolean isValid() { + return true; + } + } diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java index e2c07ef73..62cf242a8 100644 --- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java +++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java @@ -14,7 +14,6 @@ import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -75,7 +74,7 @@ public class EclipseContext implements IEclipseContext { } } - private Map<String, HashSet<Computation>> listeners = Collections.synchronizedMap(new HashMap<String, HashSet<Computation>>(10, 0.8f)); + private WeakGroupedListenerList weakListeners = new WeakGroupedListenerList(); private Map<String, ValueComputation> localValueComputations = Collections.synchronizedMap(new HashMap<String, ValueComputation>()); final protected Map<String, Object> localValues = Collections.synchronizedMap(new HashMap<String, Object>()); @@ -165,7 +164,7 @@ public class EclipseContext implements IEclipseContext { ContextChangeEvent event = new ContextChangeEvent(this, ContextChangeEvent.DISPOSE, null, null, null); Set<Scheduled> scheduled = new LinkedHashSet<Scheduled>(); Set<Computation> allComputations = getListeners(); - listeners.clear(); + weakListeners.clear(); for (Computation computation : allComputations) { computation.handleInvalid(event, scheduled); } @@ -177,19 +176,27 @@ public class EclipseContext implements IEclipseContext { } } + for (ValueComputation computation : localValueComputations.values()) { + computation.dipose(); + } localValueComputations.clear(); // if this was the parent's active child, deactivate it EclipseContext parent = getParent(); + EclipseContext rootContext = null; if (parent != null) { + rootContext = getRoot(); if (this == parent.getActiveChild()) parent.set(ACTIVE_CHILD, null); } localValues.clear(); - if (parent != null) + if (parent != null) { parent.removeChild(this); + if (rootContext != null) + rootContext.cleanup(); + } if (debugAddOn != null) debugAddOn.notify(this, IEclipseContextDebugger.EventType.DISPOSED, null); @@ -251,14 +258,11 @@ public class EclipseContext implements IEclipseContext { if (computation != null) { if (computation.shouldRemove(event)) { localValueComputations.remove(name); - Collection<HashSet<Computation>> allListeners = listeners.values(); - for (HashSet<Computation> group : allListeners) { - group.remove(computation); - } + weakListeners.remove(computation); } computation.handleInvalid(event, scheduled); } - HashSet<Computation> namedComputations = listeners.get(name); + Set<Computation> namedComputations = weakListeners.getListeners(name); if (namedComputations != null) { for (Computation listener : namedComputations) { listener.handleInvalid(event, scheduled); @@ -306,10 +310,7 @@ public class EclipseContext implements IEclipseContext { public void removeRAT(Computation computation) { // remove from listeners - Collection<HashSet<Computation>> allListeners = listeners.values(); - for (HashSet<Computation> group : allListeners) { - group.remove(computation); - } + weakListeners.remove(computation); } protected void processScheduled(Set<Scheduled> scheduledList) { @@ -409,12 +410,7 @@ public class EclipseContext implements IEclipseContext { } public void addDependency(String name, Computation computation) { - HashSet<Computation> nameListeners = listeners.get(name); - if (nameListeners == null) { - nameListeners = new HashSet<Computation>(30, 0.75f); - listeners.put(name, nameListeners); - } - nameListeners.add(computation); + weakListeners.add(name, computation); } public void declareModifiable(String name) { @@ -451,13 +447,7 @@ public class EclipseContext implements IEclipseContext { } public Set<Computation> getListeners() { - Collection<HashSet<Computation>> collection = listeners.values(); - Set<Computation> comps = new HashSet<Computation>(); - - for (HashSet<Computation> tmp : collection) { - comps.addAll(tmp); - } - return comps; + return weakListeners.getListeners(); } private void handleReparent(EclipseContext newParent, Set<Scheduled> scheduled) { @@ -481,19 +471,15 @@ public class EclipseContext implements IEclipseContext { 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); - } + weakListeners.remove(computation); computation.handleInvalid(event, scheduled); } localValueComputations.clear(); } private void collectDependentNames(Set<String> usedNames) { - Set<String> tmp = listeners.keySet(); // clone internal name list - usedNames.addAll(tmp); - + Set<String> names = weakListeners.getNames(); + usedNames.addAll(names); for (EclipseContext childContext : getChildren()) { childContext.collectDependentNames(usedNames); } @@ -681,20 +667,12 @@ public class EclipseContext implements IEclipseContext { // This method is for debug only, do not use externally public Set<String> getRawListenerNames() { - Set<String> tmp = listeners.keySet(); // clone internal name list - Set<String> usedNames = new HashSet<String>(tmp.size()); - usedNames.addAll(tmp); - return usedNames; + return weakListeners.getNames(); } // This method is for debug only, do not use externally public Set<Computation> getListeners(String name) { - HashSet<Computation> tmp = listeners.get(name); - if (tmp == null) - return null; - Set<Computation> result = new HashSet<Computation>(tmp.size()); - result.addAll(tmp); - return result; + return weakListeners.getListeners(name); } static public Stack<Computation> getCalculatedComputations() { @@ -759,4 +737,11 @@ public class EclipseContext implements IEclipseContext { public WeakReference<Object> trackedWeakReference(Object object) { return new WeakReference<Object>(object, referenceQueue); } + + public void cleanup() { + for (EclipseContext childContext : getChildren()) { + childContext.cleanup(); + } + weakListeners.cleanup(); + } } diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/ValueComputation.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/ValueComputation.java index 6f567c059..713eafacd 100644 --- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/ValueComputation.java +++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/ValueComputation.java @@ -26,6 +26,7 @@ public class ValueComputation extends Computation { private Object cachedValue = NotAValue; private boolean computing; // cycle detection + private boolean valid = true; public ValueComputation(String name, IEclipseContext originatingContext, IContextFunction computedValue) { this.originatingContext = (EclipseContext) originatingContext; @@ -107,4 +108,11 @@ public class ValueComputation extends Computation { return true; } + public boolean isValid() { + return valid; + } + + public void dipose() { + valid = false; + } }
\ No newline at end of file |