Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xText ParallelBuilderParticipant issue(Target resource data is loading into xtext model)
xText ParallelBuilderParticipant issue [message #1832274] Tue, 15 September 2020 06:49 Go to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hi,

I have grammar like below,

Component:
test_interfaces
'{'
Interfaces+=ProvidedInterface+
'}'
template' templates+=[Template|ID]*

Template:
test_interfaces
'{'
Interfaces+=ProvidedInterface+
'}'

When i try to collect the template interfaces from a component, getting interface list of template as empty even though interfaces for template is defined in grammar, this behavior is sporadic [sometime returns the data sometimes not]

for(template : comp.templates){
val intFaces +=template.getInterfaces ---[here it returns an empty]
}

This behavior is observed at generator phase, at validation phase getting right data, it is working fine.

Form configuration point of view, using ParallelBuilderParticipant and generator called through this participant.

what might be the actual issue for this behavior, can anyone help on this.

Thank you

Re: xText ParallelBuilderParticipant issue [message #1832277 is a reply to message #1832274] Tue, 15 September 2020 07:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
did you implement beforeGenerate and resolve the templates there?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xText ParallelBuilderParticipant issue [message #1832279 is a reply to message #1832277] Tue, 15 September 2020 07:45 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hello Christen,

Thank you very much for your input, is it mandatory to implement beforeGenerate method and resolve every cross references of that resource.

if i add below check in beforeGenerate, would it be fine?

if(template.eIsProxy){
EcoreUtil2.resolve(template, resource)
}


Thank you
Re: xText ParallelBuilderParticipant issue [message #1832280 is a reply to message #1832279] Tue, 15 September 2020 08:03 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hello Christen,

In the below method of ParallelBuilderParticipant, the template is not initialized.

once resource is initialized- Resource resource = context.resource;

no templates found in the resource content,

/**
* @since 2.9
*/
protected void handleChangedContents(ParallelBuildContext context, IFileSystemAccess2 access)
throws CoreException {
Resource resource = context.resource;
saveResourceStorage(resource, access);
if (shouldGenerate(resource, context)) {
getGenerator2().doGenerate(resource, access, context.getGeneratorContext());
}
}
Re: xText ParallelBuilderParticipant issue [message #1832282 is a reply to message #1832280] Tue, 15 September 2020 09:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the parallel gen should call before generated
on single thread

so if it is resolved there it should be available.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xText ParallelBuilderParticipant issue [message #1832286 is a reply to message #1832282] Tue, 15 September 2020 10:05 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hello Christen,

Thank you,

What does it mean, yes getting the right template instances at beforeGenerate method, but in doGenerate and afterGenerate not getting the expected template objects.

do i need to configure anything here? what would be the reason for not getting the right instance list in doGenerate and afterGenerate.


Thanks
Re: xText ParallelBuilderParticipant issue [message #1832288 is a reply to message #1832286] Tue, 15 September 2020 11:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i still dont understand your observations
i just point out:

do no resolve the proxies on multile threads

so please again:

you can see the templates in before generate but cant in doGenerate?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xText ParallelBuilderParticipant issue [message #1832309 is a reply to message #1832288] Wed, 16 September 2020 05:11 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hello Christen,

Yes you are right, template are visible in beforeGenerate but not in doGenerate.

As you said, do no resolve the proxies on multile threads, What does it mean ?

inside doGenerate we are reading the content of the resource and passing to the different our own generator classes to generate different files.

for Ex:

doGenerate(Resource resource){

val model = resource.contents.head

for(component : model.components){
callGenerator1(component)
callGenerator2(component)
callGenerator3(component)
}
}

Thanks
Re: xText ParallelBuilderParticipant issue [message #1832310 is a reply to message #1832309] Wed, 16 September 2020 05:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Again. You resolve the stuff in before generate and in do generate is gone?
Can you please provide a minimal example of what you do that reproduces the problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xText ParallelBuilderParticipant issue [message #1832311 is a reply to message #1832310] Wed, 16 September 2020 06:17 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hello Christen,

Thanks for kind response.

I am not resolving anything in beforeGenerator, but data is coming as expected.

issue is in doGenerate method. this might be due to my implementation in doGenerate method.

i am using below methods to resolve the index objects.

Reading the index using the method,

def getResolvedObjects(EObject context) {
val resolvedList = newArraylist
val contextResource = context.eResource
val resourceDescriptions = getResourceDescriptions(contextResource)
val contextRD = resourceDescriptions.getResourceDescription(contextResource.URI)
val container containerManager.getContainer(contextRD, resourceDescriptions)

val exportedObjects = container.getExportedObjectsByType(eClass)

for(expObj : exportedObjects){
// calling below resolve method.
val obj = resolve(context, expObj)
resolvedList .add(obj)
}
}

def <T> T resolve(EObject context, IEObjectDescription element) {
if (element === null)
return null
return EcoreUtil.resolve(element.EObjectOrProxy, context) as T
}

the above methods are calling inside the below our own generators.

callGenerator1(component)
callGenerator2(component)
callGenerator3(component)

i do not have small test project to share.

as you said, i think the issue might be due to the resolve method which is called from different instances same time while processing the resource inside doGenerate method.


Thank you again.



Re: xText ParallelBuilderParticipant issue [message #1832314 is a reply to message #1832311] Wed, 16 September 2020 06:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
as is said: you should do the complete code that does resolving to the beforeGenerate.
and yes you might call rsolves into same code when doing on multipiple threads

depending on what you do it might be enhought to use 1 worker thread for generation and the main thread for work
to circumvent the problem while keeping the performance gains


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xText ParallelBuilderParticipant issue [message #1832320 is a reply to message #1832314] Wed, 16 September 2020 09:50 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Hello Christen,

Thank you for your input.

As we use parallel builder participant, generation happens in multiple threads.
resolve used at many places, is there any possibility to execute generation sequentially one after another?
Re: xText ParallelBuilderParticipant issue [message #1832321 is a reply to message #1832320] Wed, 16 September 2020 09:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
just use 1 thread to do the generation (customize BuildExecutors)

or make sure all relevant resolves happen on beforeGenerate



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xText ParallelBuilderParticipant issue [message #1832349 is a reply to message #1832321] Thu, 17 September 2020 04:54 Go to previous message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 47
Registered: August 2011
Member
Thanks a lot Christain for your valuable input.
Previous Topic:Errors in Xtext 15 min extended tutorial
Next Topic: generator denies to run
Goto Forum:
  


Current Time: Fri Mar 29 10:14:03 GMT 2024

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

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

Back to the top