mirror of https://github.com/apache/nifi.git
NIFI-1822 Added for loop to instantiate multiple script engines in queue.
This commit is contained in:
parent
8c5ba51128
commit
8ab0ce59a4
|
@ -16,22 +16,6 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.script;
|
||||
|
||||
import org.apache.nifi.annotation.lifecycle.OnStopped;
|
||||
import org.apache.nifi.components.AllowableValue;
|
||||
import org.apache.nifi.components.PropertyDescriptor;
|
||||
import org.apache.nifi.components.ValidationContext;
|
||||
import org.apache.nifi.components.ValidationResult;
|
||||
import org.apache.nifi.components.Validator;
|
||||
import org.apache.nifi.logging.ProcessorLog;
|
||||
import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
|
||||
import org.apache.nifi.processor.Relationship;
|
||||
import org.apache.nifi.processor.util.StandardValidators;
|
||||
import org.apache.nifi.util.StringUtils;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
@ -53,6 +37,21 @@ import java.util.concurrent.BlockingQueue;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import org.apache.nifi.annotation.lifecycle.OnStopped;
|
||||
import org.apache.nifi.components.AllowableValue;
|
||||
import org.apache.nifi.components.PropertyDescriptor;
|
||||
import org.apache.nifi.components.ValidationContext;
|
||||
import org.apache.nifi.components.ValidationResult;
|
||||
import org.apache.nifi.components.Validator;
|
||||
import org.apache.nifi.logging.ProcessorLog;
|
||||
import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
|
||||
import org.apache.nifi.processor.Relationship;
|
||||
import org.apache.nifi.processor.util.StandardValidators;
|
||||
import org.apache.nifi.util.StringUtils;
|
||||
|
||||
/**
|
||||
* This class contains variables and methods common to scripting processors
|
||||
|
@ -226,6 +225,10 @@ public abstract class AbstractScriptProcessor extends AbstractSessionFactoryProc
|
|||
try {
|
||||
ProcessorLog log = getLogger();
|
||||
|
||||
if (StringUtils.isBlank(scriptEngineName)) {
|
||||
throw new IllegalArgumentException("The script engine name cannot be null");
|
||||
}
|
||||
|
||||
ScriptEngineConfigurator configurator = scriptEngineConfiguratorMap.get(scriptEngineName.toLowerCase());
|
||||
|
||||
// Get a list of URLs from the configurator (if present), or just convert modules from Strings to URLs
|
||||
|
@ -253,6 +256,7 @@ public abstract class AbstractScriptProcessor extends AbstractSessionFactoryProc
|
|||
Thread.currentThread().setContextClassLoader(scriptEngineModuleClassLoader);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfScriptEngines; i++) {
|
||||
ScriptEngine scriptEngine = createScriptEngine();
|
||||
try {
|
||||
if (configurator != null) {
|
||||
|
@ -266,7 +270,7 @@ public abstract class AbstractScriptProcessor extends AbstractSessionFactoryProc
|
|||
log.error("Error initializing script engine configurator", se);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} finally {
|
||||
// Restore original context class loader
|
||||
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
|
||||
|
|
Loading…
Reference in New Issue