use of org.ow2.proactive.scheduler.common.task.executable.internal.JavaStandaloneExecutableInitializer in project scheduling by ow2-proactive.
the class JavaClassScriptEngine method eval.
@Override
public Object eval(String userExecutableClassName, ScriptContext context) throws ScriptException {
try {
JavaExecutable javaExecutable = getExecutable(userExecutableClassName);
JavaStandaloneExecutableInitializer execInitializer = new JavaStandaloneExecutableInitializer();
PrintStream output = new PrintStream(new WriterOutputStream(context.getWriter()), true);
execInitializer.setOutputSink(output);
PrintStream error = new PrintStream(new WriterOutputStream(context.getErrorWriter()), true);
execInitializer.setErrorSink(error);
Map<String, byte[]> propagatedVariables = null;
if (context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME) != null) {
propagatedVariables = SerializationUtil.serializeVariableMap(((VariablesMap) context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME)).getPropagatedVariables());
execInitializer.setPropagatedVariables(propagatedVariables);
} else {
execInitializer.setPropagatedVariables(Collections.<String, byte[]>emptyMap());
}
if (context.getAttribute(Script.ARGUMENTS_NAME) != null) {
execInitializer.setSerializedArguments((Map<String, byte[]>) ((Serializable[]) context.getAttribute(Script.ARGUMENTS_NAME))[0]);
} else {
execInitializer.setSerializedArguments(Collections.<String, byte[]>emptyMap());
}
if (context.getAttribute(SchedulerConstants.CREDENTIALS_VARIABLE) != null) {
execInitializer.setThirdPartyCredentials((Map<String, String>) context.getAttribute(SchedulerConstants.CREDENTIALS_VARIABLE));
} else {
execInitializer.setThirdPartyCredentials(Collections.<String, String>emptyMap());
}
if (context.getAttribute(SchedulerConstants.MULTI_NODE_TASK_NODESURL_BINDING_NAME) != null) {
List<String> nodesURLs = (List<String>) context.getAttribute(SchedulerConstants.MULTI_NODE_TASK_NODESURL_BINDING_NAME);
execInitializer.setNodesURL(nodesURLs);
} else {
execInitializer.setNodesURL(Collections.<String>emptyList());
}
javaExecutable.internalInit(execInitializer, context);
Serializable execute = javaExecutable.execute((TaskResult[]) context.getAttribute(SchedulerConstants.RESULTS_VARIABLE));
if (propagatedVariables != null) {
((Map<String, Serializable>) context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME)).putAll(javaExecutable.getVariables());
}
output.close();
error.close();
return execute;
} catch (Throwable e) {
throw new ScriptException(new TaskException(getStackTraceAsString(e), e));
}
}
Aggregations