mirror of https://github.com/apache/nifi.git
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:
parent
bcfd6f0b13
commit
89295e52ef
|
@ -41,6 +41,16 @@ public class JythonScriptEngineConfigurator implements ScriptEngineConfigurator
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object init(ScriptEngine engine, String[] modulePaths) throws ScriptException {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,14 +58,6 @@ public class JythonScriptEngineConfigurator implements ScriptEngineConfigurator
|
||||||
public Object eval(ScriptEngine engine, String scriptBody, String[] modulePaths) throws ScriptException {
|
public Object eval(ScriptEngine engine, String scriptBody, String[] modulePaths) throws ScriptException {
|
||||||
Object returnValue = null;
|
Object returnValue = null;
|
||||||
if (engine != 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);
|
returnValue = engine.eval(scriptBody);
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
|
|
Loading…
Reference in New Issue