Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem concurrently resolving proxies to same resource
Problem concurrently resolving proxies to same resource [message #968904] Fri, 02 November 2012 21:09 Go to next message
David J is currently offline David JFriend
Messages: 2
Registered: November 2012
Junior Member
I have two objects, o1 and o2, and they both have a reference to the same resource. When o1 and o2 concurrently attempt to resolve their proxy to the resource, only o1 is able to resolve. When they attempt to resolve sequentially, they are both able to resolve. Any ideas why this would happen?
Re: Problem concurrently resolving proxies to same resource [message #970990 is a reply to message #968904] Sun, 04 November 2012 13:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
David,

By concurrently, you mean on different threads? ResourceSets are not
thread safe (and they are used to resolve proxies). You need a high
level threading policy for concurrent access. If you only need
concurrent read access, you might just try making
resourceSet.getResource synchronized, or you might use
EcoreUtil.resolveAll right after you load the model so that no
additional proxies ever need to be resolved.


On 04/11/2012 1:04 PM, David Jacobson wrote:
> I have two objects, o1 and o2, and they both have a reference to the
> same resource. When o1 and o2 concurrently attempt to resolve their
> proxy to the resource, only o1 is able to resolve. When they attempt
> to resolve sequentially, they are both able to resolve. Any ideas why
> this would happen?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem concurrently resolving proxies to same resource [message #972574 is a reply to message #968904] Mon, 05 November 2012 18:39 Go to previous messageGo to next message
David J is currently offline David JFriend
Messages: 2
Registered: November 2012
Junior Member
Thanks for the reply. Yes, I mean on different threads, and I only need concurrent read access. I'm fairly new to EMF and not sure I follow you on synchronizing the getResource call. I'm using the getters generated for attributes from my ecore model, so I'm not calling the getResource method directly. Any of my object types can typically just call their respective getter (which contains generated code for calling eResolveProxy) to get the resource. But in the case of trying to get the resource on different threads, the generated getter becomes ineffective, only returning the proxy. Is there some way to force the getter to *really* return the resource? Right now I have a workaround where each object just keeps trying to get the resource until the resource that is returned is no longer a proxy, but having to add this to all of my object types is pretty ugly.
Re: Problem concurrently resolving proxies to same resource [message #973178 is a reply to message #972574] Tue, 06 November 2012 05:58 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
David,

Comments below.

On 05/11/2012 7:39 PM, David Jacobson wrote:
> Thanks for the reply. Yes, I mean on different threads, and I only
> need concurrent read access. I'm fairly new to EMF and not sure I
> follow you on synchronizing the getResource call.
Resolving a proxy involves a call to
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(InternalEObject)
which calls org.eclipse.emf.ecore.util.EcoreUtil.resolve(EObject,
ResourceSet) which calls
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(URI,
boolean) which finally calls
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(URI,
boolean) to load the resource to find the resolution in that resource,
so if you synchronized that method you could make proxy resolution
thread safe.
> I'm using the getters generated for attributes from my ecore model, so
> I'm not calling the getResource method directly.
No, not directly, but indirectly, what I outline above in the mechanism
by which you get non-proxy objects back from these calls (as well as
from accessing the element of lists).
> Any of my object types can typically just call their respective getter
> (which contains generated code for calling eResolveProxy) to get the
> resource.
Yes.
> But in the case of trying to get the resource on different threads,
> the generated getter becomes ineffective, only returning the proxy.
Resource loading takes relatively long so with multiple threads doing
the same thing, another thread might well find a resource that's not
fully loaded and hence can't yet resolve the proxy in that resource.
> Is there some way to force the getter to *really* return the resource?
Yes, by sentimentalizing the loading of resources.
> Right now I have a workaround where each object just keeps trying to
> get the resource until the resource that is returned is no longer a
> proxy, but having to add this to all of my object types is pretty ugly.
That's way too ugly. Do you have complete control over the resource set
that's being used, i.e., you create it?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Framework Model
Next Topic:[XCore] GenModel-Importer cannot handle cyclic package imports
Goto Forum:
  


Current Time: Thu Mar 28 20:41:06 GMT 2024

Powered by FUDForum. Page generated in 0.01715 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top