Groovy Module (Commons)
Groovy Execution API |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Table of contents
Description
This module has the following features:
- Ability to define Groovy Compilation Customizer components to customize execution of Groovy scripts
- A Timed Interrupt Customizer allowing to stop executing Groovy Scripts after a given timeout has been reached
Timed Interrupt Customizer
This customizer stops execution of Groovy Script after a timeout has been reached, thus preventing long running operations. However this works only for Groovy code. If the Groovy code calls Java methods for example and these methods take a long time to execute the execution will be stopped only when the Groovy code regains control.
Implementing a new Customizer
Do the following:
- Add a Component implementing the org.xwiki.groovy.GroovyCompilationCustomizer Component Role.
- Implement the CompilationCustomizer createCustomizer(); method.
For example:
@Component
@Named("timedInterrupt")
@Singleton
public class TimedInterruptGroovyCompilationCustomizer implements GroovyCompilationCustomizer
{
/**
* Used to get the script timeout configuration parameter value.
*/
@Inject
private TimedInterruptCustomizerConfiguration configuration;
@Override
public CompilationCustomizer createCustomizer()
{
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("value", this.configuration.getTimeout());
return new ASTTransformationCustomizer(parameters, TimedInterrupt.class);
}
}
Prerequisites & Installation Instructions
No Groovy Customizers are defined by default.
To add a Compilation Customizer, edit the xwiki.properties configuration file and add the following property:
For example to enable the Timed Interrupt Customizer, you would write:
You can also configure the Timed Interrupt Customize timeout value by adding/editing the following property, in seconds (60 seconds being the default):