Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Advanced Scripting Environment (EASE) » Execute script programmatically and synchronous
Execute script programmatically and synchronous [message #1780088] Wed, 17 January 2018 09:52 Go to next message
Edgar Keller is currently offline Edgar KellerFriend
Messages: 3
Registered: January 2018
Junior Member
Hi,

I'm facing a problem with my usage of EASE.

What I'm trying to do is running a script programmatically from a custom plugin, actually I already achieved that. The problem is that the script execution is called from a Job (custom build system, I'm also passing some context to the executed script with engine.setVariable() ) and when I e.g. try to create a Resource from the script it will run into a dead lock.

I'm not too familiar with Eclipse development, I just wanted to have a proof of concept. I assume the Job from where I start script execution holds some kind of Lock which my script is trying to get when creating a Resource and therefore runs into this dead lock.

So what I would like to achieve is script execution within the callers thread, assuming that would circumvent the dead lock.
Is there any possibility to do so?

Some more background:
I'm using the Rhino Engine with EASE 0.4.0.

Initially I was using engine.executeSync(), but that is actually executeAsync() + wait, so does not help.

I also tried using engine.inject() directly, but that gives me always
SyntaxError: missing ; before statement (unnamed script#1)
org.eclipse.ease.ui.scripts.repository.impl.ScriptImpl@2196ba3c

Although the script works fine when executed with .executeSync(). I get the same exception even when I only use print("test"); as the script content.

I thought using .inject() on a newly created engine might fail because some initialization is missing, so I also tried:
engine.setTerminateOnIdle(false);
engine.executeSync("null;");
ScriptResult result = (ScriptResult) engine.inject(script);

but this gives the same exception as above.

Probably I could use the Rhino Engine directly, but I would loose EASE modules, which I'm currently relying on. Furthermore I'm writing the scripts in such a way that they can be executed as usual (popup) and programmatically. So good for script development/debugging.

I don't have any ideas anymore, would be really nice to get some help/hints.

Thanks in advance.

Regards,
Edgar
Re: Execute script programmatically and synchronous [message #1780128 is a reply to message #1780088] Wed, 17 January 2018 17:57 Go to previous messageGo to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
Hi Edgar,

script execution for almost any engine happens in a separate Job and therefore thread. When you get a new engine instance from the IScriptService you need to .schedule() it, otherwise the whole setup procedure will not get executed and therefore the engine will not run. Of course you could mimic everything that AbstractScriptEngine.run() and RhinoScriptEngine.setup() do and then execute stuff in your thread, but you would have to keep up with changes we apply to EASE.

I am actually wondering why your script runs into a deadlock. I suspect a conceptual problem here in your code. Generally creating resources from scripts works fine, I guess you are using the Resources module for that purpose.
Is your code acquiring any locks before it launches the script? Then consider releasing them before running your script.

Probably some code examples from your side could clarify the problem.

Christian
Re: Execute script programmatically and synchronous [message #1780646 is a reply to message #1780128] Thu, 25 January 2018 09:13 Go to previous messageGo to next message
Edgar Keller is currently offline Edgar KellerFriend
Messages: 3
Registered: January 2018
Junior Member
Hi Christian,

I'm also wondering why the script runs into a deadlock, because when I use similar java code (see below) to save a resource immediately before or after script execution from my plugin it just works as it should, it only fails if executed from the script.

Here is the snippet I use to save a resource, which works totally fine when I run the script via popup. I'm using ARTOP (www.artop.org) in an AUTOSAR context.
        var autosarRelease = org.artop.aal.workspace.preferences.IAutosarWorkspacePreferences.AUTOSAR_RELEASE.
                get(project);
        var editingDomain = org.eclipse.sphinx.emf.util.WorkspaceEditingDomainUtil.
                getEditingDomain(project, autosarRelease);
        var contentTypeID = Packages.autosar40.util.Autosar40ReleaseDescriptor.ARXML_CONTENT_TYPE_ID;

        org.eclipse.sphinx.emf.util.EcorePlatformUtil.saveNewModelResource(
                editingDomain,
                file.getFullPath(),
                contentTypeID,
                eObj,
                null,  // options
                false, // async
                new org.eclipse.core.runtime.NullProgressMonitor());


I just read chapter "Job Scheduling Rules" (after I wrote the above part) of https://www.eclipse.org/articles/Article-Concurrency/jobs-api.html . Meanwhile I assume that the job from where I try to execute the script is using a SchedulingRule to lock all the project resources (it's a build system, so probably it wants to ensure that nothing is changed while the build is running).

Maybe I could use the JobManger to temporarily release the rule of the outer job, but that would most likely lead to unwanted side effects. E.g. A pending file save operation while the build is running might get executed and lead to unexpected output.

Do you know if there is a way to atomically pass a SchedulingRule from one job to another and back again after the nested Job is done?

Regards,
Edgar
Re: Execute script programmatically and synchronous [message #1780692 is a reply to message #1780646] Thu, 25 January 2018 18:48 Go to previous messageGo to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
A locked workspace would be an explanation for your deadlock situation.

I had a short look at the InternalJob implementation. There exists yieldRule(), unfortunately it is protected.

If scheduling rules are the reason for your deadlock, probably ask the eclipse platform guys. I cannot be of much help here as I have no experience in that topic.

Christian
Re: Execute script programmatically and synchronous [message #1780867 is a reply to message #1780692] Mon, 29 January 2018 11:27 Go to previous message
Edgar Keller is currently offline Edgar KellerFriend
Messages: 3
Registered: January 2018
Junior Member
Hi Christian,

yes, I will do so. Thanks a lot for your support.

Keep up the good work with EASE, very much appreciated.

Regards,
Edgar
Previous Topic:Py4J Update site Problem
Next Topic:EAST=ADL instance injection
Goto Forum:
  


Current Time: Fri Mar 29 06:51:18 GMT 2024

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

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

Back to the top