use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class MagicCommand method executeLastFrame.
@Override
public void executeLastFrame(Code code, KernelFunctionality kernel, Message message, int executionCount) {
MagicCommandOutcomeItem execute = execute(code, executionCount, true);
sendRepliesWithStatus(singletonList(execute), kernel, message, executionCount);
TryResult result = execute.getResult();
SimpleEvaluationObject seo = execute.getSimpleEvaluationObject();
handleResult(seo, result);
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class BeakerCellExecutor method executeTask.
@Override
public TryResult executeTask(Callable<TryResult> tsk) {
Future<TryResult> ret;
try {
theLock.lock();
ret = worker.submit(tsk);
} catch (Throwable t) {
t.printStackTrace();
return TryResult.createError(t.getMessage());
} finally {
theLock.unlock();
}
TryResult o = null;
try {
o = ret.get();
} catch (Exception e) {
e.printStackTrace();
return TryResult.createError(e.getMessage());
}
if (ret.isCancelled())
return TryResult.createError("Cancelled");
return o;
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class ClojureWorkerThread method call.
@Override
public TryResult call() throws Exception {
TryResult r = null;
try {
j.outputObject.started();
r = clojureEvaluator.executeTask(new ClojureCodeRunner(clojureEvaluator, j.codeToBeExecuted, j.outputObject));
} catch (Throwable e) {
logger.error(e.getMessage());
r = TryResult.createError(e.getLocalizedMessage());
}
return r;
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class GroovyCodeRunner method call.
@Override
public TryResult call() throws Exception {
ClassLoader oldld = Thread.currentThread().getContextClassLoader();
TryResult either;
String scriptName = SCRIPT_NAME;
try {
Object result = null;
theOutput.setOutputHandler();
Thread.currentThread().setContextClassLoader(groovyEvaluator.getGroovyClassLoader());
scriptName += System.currentTimeMillis();
Class<?> parsedClass = groovyEvaluator.getGroovyClassLoader().parseClass(theCode, scriptName);
Script instance = (Script) parsedClass.newInstance();
if (GroovyEvaluator.LOCAL_DEV) {
groovyEvaluator.getScriptBinding().setVariable(Evaluator.BEAKER_VARIABLE_NAME, new HashMap<String, Object>());
} else {
groovyEvaluator.getScriptBinding().setVariable(Evaluator.BEAKER_VARIABLE_NAME, NamespaceClient.getBeaker(groovyEvaluator.getSessionId()));
}
instance.setBinding(groovyEvaluator.getScriptBinding());
InternalVariable.setValue(theOutput);
result = instance.run();
if (GroovyEvaluator.LOCAL_DEV) {
logger.info("Result: {}", result);
logger.info("Variables: {}", groovyEvaluator.getScriptBinding().getVariables());
}
either = TryResult.createResult(result);
} catch (Throwable e) {
if (GroovyEvaluator.LOCAL_DEV) {
logger.warn(e.getMessage());
e.printStackTrace();
}
// unwrap ITE
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
if (e instanceof InterruptedException || e instanceof InvocationTargetException || e instanceof ThreadDeath) {
either = TryResult.createError(INTERUPTED_MSG);
} else {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
StackTraceUtils.sanitize(e).printStackTrace(pw);
String value = sw.toString();
value = printStacktrace(scriptName, value);
either = TryResult.createError(value);
}
} finally {
theOutput.clrOutputHandler();
Thread.currentThread().setContextClassLoader(oldld);
}
return either;
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class GroovyWorkerThread method call.
@Override
public TryResult call() throws Exception {
NamespaceClient nc = null;
TryResult r;
try {
if (!GroovyEvaluator.LOCAL_DEV) {
nc = NamespaceClient.getBeaker(groovyEvaluator.getSessionId());
nc.setOutputObj(j.outputObject);
}
j.outputObject.started();
String code = j.codeToBeExecuted;
r = groovyEvaluator.executeTask(new GroovyCodeRunner(groovyEvaluator, code, j.outputObject));
if (nc != null) {
nc.setOutputObj(null);
nc = null;
}
} catch (Throwable e) {
if (e instanceof GroovyNotFoundException) {
logger.warn(e.getLocalizedMessage());
r = TryResult.createError(e.getLocalizedMessage());
} else {
e.printStackTrace();
r = TryResult.createError(e.getLocalizedMessage());
}
} finally {
if (nc != null) {
nc.setOutputObj(null);
nc = null;
}
}
return r;
}
Aggregations