use of jep.Jep in project apex-malhar by apache.
the class InterpreterThread method startInterpreter.
/**
* Starts the interpreter by loading the shared libraries
* @throws ApexPythonInterpreterException if the interpreter could not be started
*/
public void startInterpreter() throws ApexPythonInterpreterException {
Thread.currentThread().setName(threadID);
// To allow for time aware calls
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
loadMandatoryJVMLibraries();
JepConfig config = new JepConfig().setRedirectOutputStreams(true).setInteractive(false).setClassLoader(Thread.currentThread().getContextClassLoader());
if (initConfigs.containsKey(PYTHON_INCLUDE_PATHS)) {
List<String> includePaths = (List<String>) initConfigs.get(PYTHON_INCLUDE_PATHS);
if (includePaths != null) {
LOG.info("Adding include path for the in-memory interpreter instance");
for (String anIncludePath : includePaths) {
config.addIncludePaths(anIncludePath);
}
}
}
if (initConfigs.containsKey(PYTHON_SHARED_LIBS)) {
Set<String> sharedLibs = (Set<String>) initConfigs.get(PYTHON_SHARED_LIBS);
if (sharedLibs != null) {
config.setSharedModules(sharedLibs);
LOG.info("Loaded " + sharedLibs.size() + " shared libraries as config");
}
} else {
LOG.info(" No shared libraries loaded");
}
if (initConfigs.containsKey(IDLE_INTERPRETER_SPIN_POLICY)) {
spinPolicy = SpinPolicy.valueOf((String) initConfigs.get(IDLE_INTERPRETER_SPIN_POLICY));
LOG.debug("Configuring spin policy to be " + spinPolicy);
}
if (initConfigs.containsKey(SLEEP_TIME_MS_IN_CASE_OF_NO_REQUESTS)) {
sleepTimeMsInCaseOfNoRequests = (Long) initConfigs.get(SLEEP_TIME_MS_IN_CASE_OF_NO_REQUESTS);
LOG.debug("Configuring sleep time for no requests situation to be " + sleepTimeMsInCaseOfNoRequests);
}
try {
LOG.info("Launching the in-memory interpreter");
JEP_INSTANCE = new Jep(config);
} catch (JepException e) {
// Purposefully logging as this will help in startup issues being captured inline
LOG.error(e.getMessage(), e);
throw new ApexPythonInterpreterException(e);
}
}
use of jep.Jep in project twister2 by DSC-SPIDAL.
the class AbstractPythonProcessor method initialValue.
@Override
protected Jep initialValue() {
try {
// get the jep instance for this thread
Jep jep = JepInstance.getInstance();
// todo temporary workaround for JepArray issue.
// This won't be a significant performance bottleneck though
String lambdaString = Base64.getEncoder().encodeToString(bytes);
jep.set("func_bin", lambdaString);
jep.eval(this.objectId + " = cp.loads(base64.b64decode(func_bin))");
jep.eval("del func_bin");
return jep;
} catch (JepException e) {
throw new Twister2RuntimeException("Error in building lambda function", e);
}
}
Aggregations