Skip to content

Scripting Support

calltl edited this page Feb 27, 2013 · 2 revisions

Introduction

Gumtree support application level scripting such that users can use program Gumtree at runtime. The scripting support is achieved by using JSR-223 API. As long as a JVM language can provide JSR-223 binding, we can use this to script Gumtree. The recommended scripting language in Gumtree is Jython, which is available from the Gumtree Extensions.

Programming with Scripting API

// Get scripting manager
IScriptingManager manager = ServiceUtils.getService(IScriptingManager .class);
// Get default scripting engine
ScriptEngine defaultEngine = manager.createEngine();
// Get a specific scripting engine
ScriptEngine jythonEngine = manager.createEngine("jython");
// Evaluate script in the engine
jythonEngine.eval("x = 1");
int result = (Integer) jythonEngine.get("x");

Script Executor

Some scripting engine only support execution in a single thread. In order to make programming more simple, Gumtree provides the IScriptExecutor look after threading issues.

IScriptExecutor executor = new ScriptExecutor("jython");
executor.runScript("x = 1");

Scripts handled by the executor are queued in a list until previous execution is completed.

Clone this wiki locally