Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2013-09-05 14:40:58 -0400
committerChristian W. Damus2013-09-05 14:40:58 -0400
commit54a1f4ae74f0bca91c4626216c11eea7806d4265 (patch)
tree7994da6f1a04978cb148b513291130935ff6e3da
parentd761ecc300b10390d5c2eb266145f2b9082bc9de (diff)
downloadorg.eclipse.papyrus-54a1f4ae74f0bca91c4626216c11eea7806d4265.tar.gz
org.eclipse.papyrus-54a1f4ae74f0bca91c4626216c11eea7806d4265.tar.xz
org.eclipse.papyrus-54a1f4ae74f0bca91c4626216c11eea7806d4265.zip
416655: [CDO] Failing JUnit test ModelValidationMarkersTest::testMemoryLeaksInValidation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=416655 Do the ModelSet disposal sequence before closing the CDO transaction. However, this requires preventing removal of the CDOViewSet adapter from the CDOAwareModelSet until such time as the transaction is closed.
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java79
1 files changed, 68 insertions, 11 deletions
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java
index 5d3a70a41b0..150bb5e73fe 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java
@@ -12,12 +12,15 @@
package org.eclipse.papyrus.cdo.core.resource;
import java.io.IOException;
+import java.util.Collections;
import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.cdo.view.CDOViewInvalidationEvent;
import org.eclipse.emf.cdo.view.CDOViewSet;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
@@ -31,6 +34,7 @@ import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
import org.eclipse.papyrus.infra.services.resourceloading.OnDemandLoadingModelSet;
+import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
/**
@@ -146,20 +150,25 @@ public class CDOAwareModelSet extends OnDemandLoadingModelSet {
@Override
public void unload() {
- if((repository != null) && (getCDOView() != null)) {
- CDOView view = getCDOView();
- if(view != null) {
- view.removeListener(getInvalidationListener());
- }
- invalidationListener = null;
+ try {
+ super.unload();
+ } finally {
+ if((repository != null) && (getCDOView() != null)) {
+ CDOView view = getCDOView();
+ if(view != null) {
+ view.removeListener(getInvalidationListener());
+ }
+ invalidationListener = null;
- // dispose the transaction
- repository.close(this);
- }
+ // dispose the transaction
+ repository.close(this);
- repository = null;
+ // now, we can remove the CDOViewSet adapter
+ eAdapters().clear();
+ }
- super.unload();
+ repository = null;
+ }
}
protected final IListener getInvalidationListener() {
@@ -182,4 +191,52 @@ public class CDOAwareModelSet extends OnDemandLoadingModelSet {
}
};
}
+
+ @Override
+ public EList<Adapter> eAdapters() {
+ if(eAdapters == null) {
+ eAdapters = new EAdapterList<Adapter>(this) {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Adapter remove(int index) {
+ Adapter toRemove = primitiveGet(index);
+ if((toRemove instanceof CDOViewSet) && isViewActive()) {
+ // don't allow its removal if my view is still open!
+ // (Papyrus attempts to clear the resource set's adapters when disposing a ModelSet)
+ return null;
+ }
+
+ return super.remove(index);
+ }
+
+ @Override
+ public void clear() {
+ if(isViewActive()) {
+ // we can remove everything but the view-set adapter
+ Adapter viewSetAdapter = getViewSetAdapter();
+ if(viewSetAdapter != null) {
+ retainAll(Collections.singleton(viewSetAdapter));
+ } else {
+ super.clear();
+ }
+ } else {
+ super.clear();
+ }
+ }
+
+ private Adapter getViewSetAdapter() {
+ return Iterables.find(this, Predicates.instanceOf(CDOViewSet.class), null);
+ }
+ };
+ }
+
+ return eAdapters;
+ }
+
+ private boolean isViewActive() {
+ CDOView view = getCDOView();
+ return (view != null) && !view.isClosed();
+ }
}

Back to the top