NIFI-5770 Fix Memory Leak in ExecuteScript on Jython

Moved module appending (aka classpath in python) into init stage instead of running each time onTrigger.

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #3117
This commit is contained in:
Ed B 2018-10-31 09:10:27 -04:00 committed by Matthew Burgess
parent bcfd6f0b13
commit 89295e52ef
1 changed files with 10 additions and 8 deletions

View File

@ -41,6 +41,16 @@ public class JythonScriptEngineConfigurator implements ScriptEngineConfigurator
@Override
public Object init(ScriptEngine engine, String[] modulePaths) throws ScriptException {
if (engine != null) {
// Need to import the module path inside the engine, in order to pick up
// other Python/Jython modules.
engine.eval("import sys");
if (modulePaths != null) {
for (String modulePath : modulePaths) {
engine.eval("sys.path.append('" + modulePath + "')");
}
}
}
return null;
}
@ -48,14 +58,6 @@ public class JythonScriptEngineConfigurator implements ScriptEngineConfigurator
public Object eval(ScriptEngine engine, String scriptBody, String[] modulePaths) throws ScriptException {
Object returnValue = null;
if (engine != null) {
// Need to import the module path inside the engine, in order to pick up
// other Python/Jython modules
engine.eval("import sys");
if (modulePaths != null) {
for (String modulePath : modulePaths) {
engine.eval("sys.path.append('" + modulePath + "')");
}
}
returnValue = engine.eval(scriptBody);
}
return returnValue;