Search in sources :

Example 51 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject 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);
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) MagicCommandOutcomeItem(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem)

Example 52 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class ExecutionResultSender method update.

@Override
public synchronized void update(Observable o, Object arg) {
    SimpleEvaluationObject seo = (SimpleEvaluationObject) o;
    if (seo != null) {
        List<MessageHolder> message = MessageCreator.createMessage(seo);
        message.forEach(job -> {
            if (SocketEnum.IOPUB_SOCKET.equals(job.getSocketType())) {
                kernel.publish(singletonList(job.getMessage()));
            } else if (SocketEnum.SHELL_SOCKET.equals(job.getSocketType())) {
                kernel.send(job.getMessage());
            }
        });
    }
}
Also used : MessageHolder(com.twosigma.beakerx.kernel.msg.MessageHolder) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)

Example 53 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class CompiledCodeRunner method runCompiledCodeAndPublish.

public static void runCompiledCodeAndPublish(Message message, ExecuteCompiledCode handler, Object... params) {
    final SimpleEvaluationObject seo = initOutput(message);
    InternalVariable.setValue(seo);
    KernelManager.get().publish(singletonList(MessageCreator.buildClearOutput(message, true)));
    try {
        Object result = handler.executeCode(params);
        if (result != null) {
            List<MIMEContainer> resultString = MIMEContainerFactory.createMIMEContainers(result);
            KernelManager.get().publish(singletonList(MessageCreator.buildDisplayData(message, resultString)));
        }
    } catch (Exception e) {
        printError(message, seo, e);
    }
    seo.clrOutputHandler();
}
Also used : MIMEContainer(com.twosigma.beakerx.mimetype.MIMEContainer) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)

Example 54 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class CompiledCodeRunner method runCompiledCode.

public static void runCompiledCode(Message message, ExecuteCompiledCode handler, Object... params) {
    final SimpleEvaluationObject seo = initOutput(message);
    InternalVariable.setValue(seo);
    try {
        Object result = handler.executeCode(params);
        if (result != null) {
            MIMEContainerFactory.createMIMEContainers(result);
        }
    } catch (Exception e) {
        printError(message, seo, e);
    }
    seo.clrOutputHandler();
}
Also used : SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)

Example 55 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class GroovyEvaluatorProgressReportingTest method progressReporting.

@Test
public void progressReporting() throws Exception {
    // given
    String code = "for ( int i = 0 ; i<5; i++) {\n" + "  " + BEAKER_VARIABLE_NAME + ".showProgressUpdate(\"msg\"+i, i)\n" + "}\n" + "\"finished\"";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = groovyEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isEqualTo("finished");
    verifyProgressReporting(groovyKernel.getPublishedMessages());
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Aggregations

SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)57 TryResult (com.twosigma.beakerx.TryResult)37 Test (org.junit.Test)33 Message (com.twosigma.beakerx.message.Message)9 KernelTest (com.twosigma.beakerx.KernelTest)7 PlainCode.createSimpleEvaluationObject (com.twosigma.beakerx.kernel.PlainCode.createSimpleEvaluationObject)5 HashMap (java.util.HashMap)4 EvaluatorParameters (com.twosigma.beakerx.kernel.EvaluatorParameters)3 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 Plot (com.twosigma.beakerx.chart.xychart.Plot)2 MagicCommandOutcomeItem (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem)2 MessageHolder (com.twosigma.beakerx.kernel.msg.MessageHolder)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 Before (org.junit.Before)2 AutocompleteResult (com.twosigma.beakerx.autocomplete.AutocompleteResult)1 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)1 Code (com.twosigma.beakerx.kernel.Code)1 KernelFunctionality (com.twosigma.beakerx.kernel.KernelFunctionality)1