Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Saving/Loading to/from BinaryResourceImpl
Saving/Loading to/from BinaryResourceImpl [message #1383901] Tue, 27 May 2014 06:10 Go to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
Hey

I have some code to persist a linked/merged/patched/whatever xtext dsl based EMF model to a BinaryResourceImpl, and re-read it from such. This seems to work rather well, however, when re-reading the model from the resource, it seems to disappear suddenly. I have this method:

        def load(InputStream binary) {
		try {
			val bin = resourceSet.createResource(URI.createURI("http://www.wamas.com/dummy.wdlbin"));
			
			bin.load(binary, binaryResourceOptions);
			
			contents = bin.allContents.toIterable.filter(TopLevelElement)
			packages = bin.allContents.toIterable.filter(Package)
		} finally {
			binary.close
		}
	}


when i set a breakpoint at the end of the method, the contents looks ok. All elements that i'd expect are there. When i step out of this method, contents disappears (is an empty collection then).

What the heck is going on here? what am i missing? any ideas? Thanks!
Re: Saving/Loading to/from BinaryResourceImpl [message #1383903 is a reply to message #1383901] Tue, 27 May 2014 06:25 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
i debugged a little in the generated code and recorded a screencast of how the collection magically empties...: http://dev.gentoo.org/~mduft/screencast_xtend.webm

there are a few strange things i can see here:

1) the _allContents collection is shown as empty, however the _filter is initially NOT empty.
2) when hovering over _filter right after the line is executed, it is non-empty.
3) when hovering over _filter a second time it is suddenly empty.

WTF is going on here?
Re: Saving/Loading to/from BinaryResourceImpl [message #1383904 is a reply to message #1383903] Tue, 27 May 2014 06:29 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
if i change the contents and package assignment to this it works:

contents = resourceSet.resources.map(r|r.allContents.toIterable).flatten.filter(TopLevelElement)
packages = resourceSet.resources.map(r|r.allContents.toIterable).flatten.filter(Package)


still: some ideas?

[Updated on: Tue, 27 May 2014 06:29]

Report message to a moderator

Re: Saving/Loading to/from BinaryResourceImpl [message #1383907 is a reply to message #1383903] Tue, 27 May 2014 06:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
It may be caused by guava expressions being lazy. Some assignments
may force an actual execution


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Saving/Loading to/from BinaryResourceImpl [message #1383942 is a reply to message #1383901] Tue, 27 May 2014 10:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6566
Registered: July 2009
Senior Member
Hi

A common problem with persistence is accidentally neglecting to define
the reference as containment, or defining it as transient/volatile.

A common problem while running is child-stealing, adding an object as a
child of a new container removes it from an old container.

For non-trivial models child-stealing can cause such obscure problems
that I add

@Override
protected void eBasicSetContainer(InternalEObject newContainer, int
newContainerFeatureID) {
if (newContainer != null) {
EObject oldContainer = eContainer();
assert ((oldContainer == null) || (newContainer ==
oldContainer) || (oldContainer.eResource() == null));
}
super.eBasicSetContainer(newContainer, newContainerFeatureID);
}

@Override
public NotificationChain eBasicSetContainer(InternalEObject
newContainer, int newContainerFeatureID, NotificationChain msgs) {
if (newContainer != null) {
EObject oldContainer = eContainer();
assert ((oldContainer == null) || (newContainer ==
oldContainer) || (oldContainer.eResource() == null));
}
return super.eBasicSetContainer(newContainer,
newContainerFeatureID, msgs);
}

to my root XXXEObjectImpl.

Minor downside; if you really want to reparent an EObject you must
explicitly set its parent to null in the interim.

Regards

Ed Willink

On 27/05/2014 07:10, Markus Duft wrote:
> Hey
>
> I have some code to persist a linked/merged/patched/whatever xtext dsl
> based EMF model to a BinaryResourceImpl, and re-read it from such.
> This seems to work rather well, however, when re-reading the model
> from the resource, it seems to disappear suddenly. I have this method:
>
>
> def load(InputStream binary) {
> try {
> val bin =
> resourceSet.createResource(URI.createURI("http://www.wamas.com/dummy.wdlbin"));
>
> bin.load(binary, binaryResourceOptions);
>
> contents = bin.allContents.toIterable.filter(TopLevelElement)
> packages = bin.allContents.toIterable.filter(Package)
> } finally {
> binary.close
> }
> }
>
>
> when i set a breakpoint at the end of the method, the contents looks
> ok. All elements that i'd expect are there. When i step out of this
> method, contents disappears (is an empty collection then).
>
> What the heck is going on here? what am i missing? any ideas? Thanks!
Re: Saving/Loading to/from BinaryResourceImpl [message #1383943 is a reply to message #1383942] Tue, 27 May 2014 10:38 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
thanks for the hints.

@Ed: thanks for the insight, very good to keep that in mind Smile In this case i don't think that i have this kind of problem. I verified that the model is persisted correctly (all elements are in the file), and that it is read correctly (model.contents contains all root elements, and in the debugger i can have a look at them). Just right after "bin.allContents.toIterable.filter(TopLevelElement)" the returned collection is filled, and half a second later it's empty, without any (obvious, in the current thread) code running...
Re: Saving/Loading to/from BinaryResourceImpl [message #1383999 is a reply to message #1383943] Tue, 27 May 2014 18:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
HI,

can you share a complete example/unittest something to reproduce.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Generate Xtext Artifacts 10 errors
Next Topic:XText cross-reference to rule containing a cross-reference
Goto Forum:
  


Current Time: Sat Jan 18 20:50:16 GMT 2020

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

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

Back to the top