Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » How to make sure that a resource is written
How to make sure that a resource is written [message #483877] Thu, 03 September 2009 13:00 Go to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi all

I'm trying to read an EMF resource. In case it does not exist, I create a
new one, add some default content to it and call save().

Now I've got the problem, that after the save(), the resource might still
not exist and an IOException is thrown when I try to load the resource. It
seems like a race condition to me, since it never occurs in the debugger.
So I helped myself with the following loop:

while
(!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
Collections.EMPTY_MAP))
{
System.out.println("save it");
resource.save(saveOptions);
}

It is now clear, that save() does not guarantee the existence of the
resource after it has been called. I have seen up to 30 executions of the
while-loop until the resource finally existed.

My question is: how can I make sure, that the new resource really exists?
The while-loop does not look like a nice solution to me. Or am I
misunderstanding something?


Thanks for your helpful posts ;-)

Roland
Re: How to make sure that a resource is written [message #483995 is a reply to message #483877] Thu, 03 September 2009 20:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

Please post EMF questions to the EMF newsgroup, which I've added to the
"to" list of the reply. More comments below.


Roland Brand wrote:
> Hi all
>
> I'm trying to read an EMF resource. In case it does not exist, I
> create a new one, add some default content to it and call save().
>
> Now I've got the problem, that after the save(), the resource might
> still not exist and an IOException is thrown when I try to load the
> resource. It seems like a race condition to me, since it never occurs
> in the debugger. So I helped myself with the following loop:
>
> while
> (!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
> Collections.EMPTY_MAP))
> {
> System.out.println("save it");
> resource.save(saveOptions);
> }
>
> It is now clear, that save() does not guarantee the existence of the
> resource after it has been called. I have seen up to 30 executions of
> the while-loop until the resource finally existed.
What's the value of the URI?
>
> My question is: how can I make sure, that the new resource really
> exists? The while-loop does not look like a nice solution to me. Or am
> I misunderstanding something?
I wouldn't expect this kind of behavior...
>
>
> Thanks for your helpful posts ;-)
>
> Roland
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #484060 is a reply to message #483995] Fri, 04 September 2009 07:02 Go to previous messageGo to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Ed

Ed Merks wrote:
> Please post EMF questions to the EMF newsgroup, which I've added to the
> "to" list of the reply. More comments below.

Oops, sorry.


> Roland Brand wrote:
>> Hi all
>>
>> I'm trying to read an EMF resource. In case it does not exist, I
>> create a new one, add some default content to it and call save().
>>
>> Now I've got the problem, that after the save(), the resource might
>> still not exist and an IOException is thrown when I try to load the
>> resource. It seems like a race condition to me, since it never occurs
>> in the debugger. So I helped myself with the following loop:
>>
>> while
>> (!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
>> Collections.EMPTY_MAP))
>> {
>> System.out.println("save it");
>> resource.save(saveOptions);
>> }
>>
>> It is now clear, that save() does not guarantee the existence of the
>> resource after it has been called. I have seen up to 30 executions of
>> the while-loop until the resource finally existed.
> What's the value of the URI?

The URI is archive:file://home/rbrand/model.zip!/semantic.xmi

As you can probably guess, I have a Zipfile containing GMF resources: a
semantic model and a notation model.

>>
>> My question is: how can I make sure, that the new resource really
>> exists? The while-loop does not look like a nice solution to me. Or am
>> I misunderstanding something?
> I wouldn't expect this kind of behavior...
>>
>>
>> Thanks for your helpful posts ;-)
>>
>> Roland
>>
Re: How to make sure that a resource is written [message #484200 is a reply to message #484060] Fri, 04 September 2009 15:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

Perhaps there is a bug in exists for this case. If you could create a
test case demonstrating the problem in a bugzilla report, I'll quickly
have a look and fix it if there is a basic problem.


Roland Brand wrote:
> Hi Ed
>
> Ed Merks wrote:
>> Please post EMF questions to the EMF newsgroup, which I've added to
>> the "to" list of the reply. More comments below.
>
> Oops, sorry.
>
>
>> Roland Brand wrote:
>>> Hi all
>>>
>>> I'm trying to read an EMF resource. In case it does not exist, I
>>> create a new one, add some default content to it and call save().
>>>
>>> Now I've got the problem, that after the save(), the resource might
>>> still not exist and an IOException is thrown when I try to load the
>>> resource. It seems like a race condition to me, since it never
>>> occurs in the debugger. So I helped myself with the following loop:
>>>
>>> while
>>> (!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
>>> Collections.EMPTY_MAP))
>>> {
>>> System.out.println("save it");
>>> resource.save(saveOptions);
>>> }
>>>
>>> It is now clear, that save() does not guarantee the existence of the
>>> resource after it has been called. I have seen up to 30 executions
>>> of the while-loop until the resource finally existed.
>> What's the value of the URI?
>
> The URI is archive:file://home/rbrand/model.zip!/semantic.xmi
>
> As you can probably guess, I have a Zipfile containing GMF resources:
> a semantic model and a notation model.
>
>>>
>>> My question is: how can I make sure, that the new resource really
>>> exists? The while-loop does not look like a nice solution to me. Or
>>> am I misunderstanding something?
>> I wouldn't expect this kind of behavior...
>>>
>>>
>>> Thanks for your helpful posts ;-)
>>>
>>> Roland
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #484352 is a reply to message #484200] Mon, 07 September 2009 07:47 Go to previous messageGo to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Ed

I think the exists() is working properly. When I omit the while-loop and
call resource.save() only once, I get an IOException when I try to read
the resource. It really does not exists for a short amount of time.

java.io.IOException: Archive entry not found
archive:file://home/rbrand/model.zip!/semantic.xmi
at
org.eclipse.emf.common.archive.ArchiveURLConnection.getInput Stream(ArchiveURLConnection.java:244)
at
org.eclipse.emf.ecore.resource.impl.ArchiveURIHandlerImpl.cr eateInputStream(ArchiveURIHandlerImpl.java:59)
at
org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterIm pl.createInputStream(ExtensibleURIConverterImpl.java:301)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1254)


Stepping into the resource.save() I could see that the OutputStream is
closed. But nevertheless it seems not to be written to disk directly.
Could there be OS caches? Is there a possiblity to flush the Zipfile?
Re: How to make sure that a resource is written [message #484435 is a reply to message #484352] Mon, 07 September 2009 13:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

It could well be an OS issue I suppose... I'm just not sure what to do
about it...


Roland Brand wrote:
> Hi Ed
>
> I think the exists() is working properly. When I omit the while-loop
> and call resource.save() only once, I get an IOException when I try to
> read the resource. It really does not exists for a short amount of time.
>
> java.io.IOException: Archive entry not found
> archive:file://home/rbrand/model.zip!/semantic.xmi
> at
> org.eclipse.emf.common.archive.ArchiveURLConnection.getInput Stream(ArchiveURLConnection.java:244)
>
> at
> org.eclipse.emf.ecore.resource.impl.ArchiveURIHandlerImpl.cr eateInputStream(ArchiveURIHandlerImpl.java:59)
>
> at
> org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterIm pl.createInputStream(ExtensibleURIConverterImpl.java:301)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1254)
>
>
>
> Stepping into the resource.save() I could see that the OutputStream is
> closed. But nevertheless it seems not to be written to disk directly.
> Could there be OS caches? Is there a possiblity to flush the Zipfile?
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #484542 is a reply to message #484435] Tue, 08 September 2009 07:53 Go to previous messageGo to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Ed

I just filed bug #288799 for this, hoping you can reproduce the problem.
Re: How to make sure that a resource is written [message #484641 is a reply to message #484542] Tue, 08 September 2009 14:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

Unfortunately it works fine for me so I can only assume that
network/filesystem issues specific to Linux are at play. I'm not even
in a position to reproduce OS-specific issues nor can I imagine how EMF
itself could address such things.


Roland Brand wrote:
> Hi Ed
>
> I just filed bug #288799 for this, hoping you can reproduce the problem.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #617812 is a reply to message #483877] Thu, 03 September 2009 20:36 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

Please post EMF questions to the EMF newsgroup, which I've added to the
"to" list of the reply. More comments below.


Roland Brand wrote:
> Hi all
>
> I'm trying to read an EMF resource. In case it does not exist, I
> create a new one, add some default content to it and call save().
>
> Now I've got the problem, that after the save(), the resource might
> still not exist and an IOException is thrown when I try to load the
> resource. It seems like a race condition to me, since it never occurs
> in the debugger. So I helped myself with the following loop:
>
> while
> (!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
> Collections.EMPTY_MAP))
> {
> System.out.println("save it");
> resource.save(saveOptions);
> }
>
> It is now clear, that save() does not guarantee the existence of the
> resource after it has been called. I have seen up to 30 executions of
> the while-loop until the resource finally existed.
What's the value of the URI?
>
> My question is: how can I make sure, that the new resource really
> exists? The while-loop does not look like a nice solution to me. Or am
> I misunderstanding something?
I wouldn't expect this kind of behavior...
>
>
> Thanks for your helpful posts ;-)
>
> Roland
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #617814 is a reply to message #483995] Fri, 04 September 2009 07:02 Go to previous message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Ed

Ed Merks wrote:
> Please post EMF questions to the EMF newsgroup, which I've added to the
> "to" list of the reply. More comments below.

Oops, sorry.


> Roland Brand wrote:
>> Hi all
>>
>> I'm trying to read an EMF resource. In case it does not exist, I
>> create a new one, add some default content to it and call save().
>>
>> Now I've got the problem, that after the save(), the resource might
>> still not exist and an IOException is thrown when I try to load the
>> resource. It seems like a race condition to me, since it never occurs
>> in the debugger. So I helped myself with the following loop:
>>
>> while
>> (!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
>> Collections.EMPTY_MAP))
>> {
>> System.out.println("save it");
>> resource.save(saveOptions);
>> }
>>
>> It is now clear, that save() does not guarantee the existence of the
>> resource after it has been called. I have seen up to 30 executions of
>> the while-loop until the resource finally existed.
> What's the value of the URI?

The URI is archive:file://home/rbrand/model.zip!/semantic.xmi

As you can probably guess, I have a Zipfile containing GMF resources: a
semantic model and a notation model.

>>
>> My question is: how can I make sure, that the new resource really
>> exists? The while-loop does not look like a nice solution to me. Or am
>> I misunderstanding something?
> I wouldn't expect this kind of behavior...
>>
>>
>> Thanks for your helpful posts ;-)
>>
>> Roland
>>
Re: How to make sure that a resource is written [message #617816 is a reply to message #484060] Fri, 04 September 2009 15:05 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

Perhaps there is a bug in exists for this case. If you could create a
test case demonstrating the problem in a bugzilla report, I'll quickly
have a look and fix it if there is a basic problem.


Roland Brand wrote:
> Hi Ed
>
> Ed Merks wrote:
>> Please post EMF questions to the EMF newsgroup, which I've added to
>> the "to" list of the reply. More comments below.
>
> Oops, sorry.
>
>
>> Roland Brand wrote:
>>> Hi all
>>>
>>> I'm trying to read an EMF resource. In case it does not exist, I
>>> create a new one, add some default content to it and call save().
>>>
>>> Now I've got the problem, that after the save(), the resource might
>>> still not exist and an IOException is thrown when I try to load the
>>> resource. It seems like a race condition to me, since it never
>>> occurs in the debugger. So I helped myself with the following loop:
>>>
>>> while
>>> (!resource.getResourceSet().getURIConverter().exists(resourc e.getURI(),
>>> Collections.EMPTY_MAP))
>>> {
>>> System.out.println("save it");
>>> resource.save(saveOptions);
>>> }
>>>
>>> It is now clear, that save() does not guarantee the existence of the
>>> resource after it has been called. I have seen up to 30 executions
>>> of the while-loop until the resource finally existed.
>> What's the value of the URI?
>
> The URI is archive:file://home/rbrand/model.zip!/semantic.xmi
>
> As you can probably guess, I have a Zipfile containing GMF resources:
> a semantic model and a notation model.
>
>>>
>>> My question is: how can I make sure, that the new resource really
>>> exists? The while-loop does not look like a nice solution to me. Or
>>> am I misunderstanding something?
>> I wouldn't expect this kind of behavior...
>>>
>>>
>>> Thanks for your helpful posts ;-)
>>>
>>> Roland
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #617818 is a reply to message #484200] Mon, 07 September 2009 07:47 Go to previous message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Ed

I think the exists() is working properly. When I omit the while-loop and
call resource.save() only once, I get an IOException when I try to read
the resource. It really does not exists for a short amount of time.

java.io.IOException: Archive entry not found
archive:file://home/rbrand/model.zip!/semantic.xmi
at
org.eclipse.emf.common.archive.ArchiveURLConnection.getInput Stream(ArchiveURLConnection.java:244)
at
org.eclipse.emf.ecore.resource.impl.ArchiveURIHandlerImpl.cr eateInputStream(ArchiveURIHandlerImpl.java:59)
at
org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterIm pl.createInputStream(ExtensibleURIConverterImpl.java:301)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1254)


Stepping into the resource.save() I could see that the OutputStream is
closed. But nevertheless it seems not to be written to disk directly.
Could there be OS caches? Is there a possiblity to flush the Zipfile?
Re: How to make sure that a resource is written [message #617820 is a reply to message #484352] Mon, 07 September 2009 13:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

It could well be an OS issue I suppose... I'm just not sure what to do
about it...


Roland Brand wrote:
> Hi Ed
>
> I think the exists() is working properly. When I omit the while-loop
> and call resource.save() only once, I get an IOException when I try to
> read the resource. It really does not exists for a short amount of time.
>
> java.io.IOException: Archive entry not found
> archive:file://home/rbrand/model.zip!/semantic.xmi
> at
> org.eclipse.emf.common.archive.ArchiveURLConnection.getInput Stream(ArchiveURLConnection.java:244)
>
> at
> org.eclipse.emf.ecore.resource.impl.ArchiveURIHandlerImpl.cr eateInputStream(ArchiveURIHandlerImpl.java:59)
>
> at
> org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterIm pl.createInputStream(ExtensibleURIConverterImpl.java:301)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1254)
>
>
>
> Stepping into the resource.save() I could see that the OutputStream is
> closed. But nevertheless it seems not to be written to disk directly.
> Could there be OS caches? Is there a possiblity to flush the Zipfile?
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to make sure that a resource is written [message #618206 is a reply to message #484435] Tue, 08 September 2009 07:53 Go to previous message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Ed

I just filed bug #288799 for this, hoping you can reproduce the problem.
Re: How to make sure that a resource is written [message #618207 is a reply to message #484542] Tue, 08 September 2009 14:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Roland,

Unfortunately it works fine for me so I can only assume that
network/filesystem issues specific to Linux are at play. I'm not even
in a position to reproduce OS-specific issues nor can I imagine how EMF
itself could address such things.


Roland Brand wrote:
> Hi Ed
>
> I just filed bug #288799 for this, hoping you can reproduce the problem.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to make sure that a resource is written
Next Topic:[PMF] Current status
Goto Forum:
  


Current Time: Tue Mar 19 07:55:02 GMT 2024

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

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

Back to the top