Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Delaigue2015-05-07 13:05:44 +0000
committerAxel RICHARD2015-05-13 14:16:57 +0000
commite059d0fd3bad2f92176e9b3116f56991abbfab22 (patch)
tree03afbcd42419e2f00bad2ce1d8350d62fdb08207 /plugins
parentd9e42051dc4564ef62d255b3296ae05d7c23cbf6 (diff)
downloadorg.eclipse.emf.compare-e059d0fd3bad2f92176e9b3116f56991abbfab22.tar.gz
org.eclipse.emf.compare-e059d0fd3bad2f92176e9b3116f56991abbfab22.tar.xz
org.eclipse.emf.compare-e059d0fd3bad2f92176e9b3116f56991abbfab22.zip
Fixed issues in SynchronizedResourceSet.
Change-Id: I30f2e842a9795a77a16eb476af34cc3e32a4d95f Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java62
1 files changed, 57 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java
index 2a1db6d07..83df18be1 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/resolver/SynchronizedResourceSet.java
@@ -18,6 +18,7 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
@@ -39,6 +40,9 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
class SynchronizedResourceSet extends ResourceSetImpl {
+ /** The logger. */
+ private static final Logger LOGGER = Logger.getLogger(SynchronizedResourceSet.class);
+
/** Associates URIs with their resources. */
private final ConcurrentHashMap<URI, Resource> uriCache;
@@ -94,11 +98,21 @@ class SynchronizedResourceSet extends ResourceSetImpl {
final URI normalizedURI = theURIConverter.normalize(uri);
Resource result = null;
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".loadResource for " + normalizedURI); //$NON-NLS-1$ //$NON-NLS-2$
+ }
result = uriCache.get(normalizedURI);
if (result == null) {
result = delegatedGetResource(uri, true);
if (result != null) {
- result = uriCache.putIfAbsent(uri, result);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".loadResource - caching " //$NON-NLS-1$ //$NON-NLS-2$
+ + normalizedURI);
+ }
+ Resource former = uriCache.putIfAbsent(normalizedURI, result);
+ if (former != null) {
+ result = former;
+ }
}
}
@@ -119,6 +133,10 @@ class SynchronizedResourceSet extends ResourceSetImpl {
throw new RuntimeException("Cannot create a resource for '" + uri //$NON-NLS-1$
+ "'; a registered resource factory is needed"); //$NON-NLS-1$
}
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".loadResource - No caching for " //$NON-NLS-1$ //$NON-NLS-2$
+ + normalizedURI);
+ }
demandLoadHelper(result);
}
return result;
@@ -150,6 +168,9 @@ class SynchronizedResourceSet extends ResourceSetImpl {
*/
public void unload(Resource resource, IProgressMonitor monitor) {
final URI uri = resource.getURI();
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".unload " + uri); //$NON-NLS-1$ //$NON-NLS-2$
+ }
uriCache.remove(uri);
getResources().remove(resource);
resource.eAdapters().clear();
@@ -165,15 +186,26 @@ class SynchronizedResourceSet extends ResourceSetImpl {
public Resource getResource(URI uri, boolean loadOnDemand) {
// Never load resources from here, we only care for the EPackages to prevent the XMLHandler from going
// into a stackoverflow
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".getResource for " + uri); //$NON-NLS-1$ //$NON-NLS-2$
+ }
Resource demanded = uriCache.get(uri);
if (demanded == null) {
final EPackage ePackage = getPackageRegistry().getEPackage(uri.toString());
if (ePackage != null) {
demanded = ePackage.eResource();
- demanded = uriCache.putIfAbsent(uri, demanded);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".getResource - caching " + uri); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ Resource former = uriCache.putIfAbsent(uri, demanded);
+ if (former != null) {
+ demanded = former;
+ }
} else {
// simply return null
}
+ } else if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".getResource - FOUND in cache " + uri); //$NON-NLS-1$ //$NON-NLS-2$
}
return demanded;
}
@@ -185,8 +217,7 @@ class SynchronizedResourceSet extends ResourceSetImpl {
*/
@Override
public synchronized Resource createResource(URI uri) {
- final Resource created = super.createResource(uri);
- return created;
+ return super.createResource(uri);
}
/**
@@ -197,7 +228,28 @@ class SynchronizedResourceSet extends ResourceSetImpl {
*/
@Override
public synchronized Resource createResource(URI uri, String contentType) {
- final Resource created = super.createResource(uri, contentType);
+ // In some cases like the load of Profile in UML via pathmaps,
+ // The XMLHandler#getPackageForURI will call createResource after having got null by getResource()
+ final URI normalizedURI = getURIConverter().normalize(uri);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".createResource " + uri); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (uriCache.containsKey(normalizedURI)) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".createResource FOUND IN CACHE " + uri); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return uriCache.get(normalizedURI);
+ }
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SRS@" + Integer.toHexString(hashCode()) + ".createResource CREATING " + uri); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ Resource created = super.createResource(uri, contentType);
+ // putIfAbsent will return atomically the one that's already registered
+ // if another instance has been registered in between
+ Resource former = uriCache.putIfAbsent(normalizedURI, created);
+ if (former != null) {
+ created = former;
+ }
return created;
}

Back to the top