Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Update to new beakerx API and display nothing when output is null #74

Merged
merged 2 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update to new beakerx API and display nothing when output is null
  • Loading branch information
hadim committed Jun 29, 2017
commit abaa806d82d5fd54ea195bdefcbf65c1a91a80a4
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<dependency>
<groupId>com.github.twosigma.beakerx</groupId>
<artifactId>beaker-kernel-base</artifactId>
<version>ec26621</version>
<version>d30a87d</version>
</dependency>

<!-- The package to convert images to PNG/JPEG -->
Expand Down
92 changes: 52 additions & 40 deletions src/main/java/org/scijava/jupyter/kernel/ScijavaKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
* limitations under the License.
* #L%
*/

package org.scijava.jupyter.kernel;

import com.twosigma.beakerx.handler.KernelHandler;
import com.twosigma.beakerx.kernel.Kernel;
import com.twosigma.beakerx.kernel.KernelParameters;
import com.twosigma.beakerx.kernel.KernelSocketsFactory;
import com.twosigma.beakerx.kernel.handler.CommOpenHandler;
import com.twosigma.beakerx.message.Message;
import java.util.HashMap;
import java.util.Map;

import net.imagej.table.process.ResultsPostprocessor;

Expand Down Expand Up @@ -57,64 +59,74 @@ public class ScijavaKernel extends Kernel {
private final ScijavaEvaluator evaluator;

public ScijavaKernel(final Context context, final String id, final ScijavaEvaluator evaluator,
ScijavaKernelConfigurationFile config, KernelSocketsFactory kernelSocketsFactory) {
ScijavaKernelConfigurationFile config, KernelSocketsFactory kernelSocketsFactory) {

super(id, evaluator, kernelSocketsFactory);
this.context = context;
this.context.inject(this);
this.config = config;
this.evaluator = evaluator;
super(id, evaluator, kernelSocketsFactory);
this.context = context;
this.context.inject(this);
this.config = config;
this.evaluator = evaluator;

// Don't show output when it is null
Kernel.showNullExecutionResult = false;

this.setLogLevel(config.getLogLevel());
log.info("Log level used is : " + this.config.getLogLevel());
this.setLogLevel(config.getLogLevel());
log.info("Log level used is : " + this.config.getLogLevel());

log.info("Scijava Kernel is started and ready to use.");
log.info("Scijava Kernel is started and ready to use.");
}

@Override
public CommOpenHandler getCommOpenHandler(Kernel kernel) {
return new ScijavaCommOpenHandler(kernel);
return new ScijavaCommOpenHandler(kernel);
}

@Override
public KernelHandler<Message> getKernelInfoHandler(Kernel kernel) {
return new ScijavaKernelInfoHandler(kernel);
return new ScijavaKernelInfoHandler(kernel);
}

private void setLogLevel(String logLevel) {
switch (logLevel) {
case "debug":
this.log.setLevel(LogService.DEBUG);
break;
case "error":
this.log.setLevel(LogService.ERROR);
break;
case "info":
this.log.setLevel(LogService.INFO);
break;
case "none":
this.log.setLevel(LogService.NONE);
break;
default:
this.log.setLevel(LogService.INFO);
break;
}
switch (logLevel) {
case "debug":
this.log.setLevel(LogService.DEBUG);
break;
case "error":
this.log.setLevel(LogService.ERROR);
break;
case "info":
this.log.setLevel(LogService.INFO);
break;
case "none":
this.log.setLevel(LogService.NONE);
break;
default:
this.log.setLevel(LogService.INFO);
break;
}
}

@Override
public KernelParameters getKernelParameters() {
Map<String, Object> kernelParameters = new HashMap<>();
return new KernelParameters(kernelParameters);
}

public static void main(String... args) {
final Context context = new Context();
final Context context = new Context();

// Remove the Display and Results post-processors to prevent output
// windows from being displayed
final PluginService pluginService = context.service(PluginService.class);
final PluginInfo<SciJavaPlugin> display = pluginService.getPlugin(DisplayPostprocessor.class);
final PluginInfo<SciJavaPlugin> results = pluginService.getPlugin(ResultsPostprocessor.class);
pluginService.removePlugin(display);
pluginService.removePlugin(results);
// Remove the Display and Results post-processors to prevent output
// windows from being displayed
final PluginService pluginService = context.service(PluginService.class);
final PluginInfo<SciJavaPlugin> display = pluginService.getPlugin(DisplayPostprocessor.class);
final PluginInfo<SciJavaPlugin> results = pluginService.getPlugin(ResultsPostprocessor.class);
pluginService.removePlugin(display);
pluginService.removePlugin(results);

JupyterService jupyter = context.service(JupyterService.class);
jupyter.runKernel(args);
JupyterService jupyter = context.service(JupyterService.class);
jupyter.runKernel(args);

context.dispose();
context.dispose();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import com.twosigma.beakerx.handler.Handler;
import com.twosigma.beakerx.kernel.KernelFunctionality;
import com.twosigma.beakerx.kernel.comm.GetCodeCellsHandler;
import com.twosigma.beakerx.kernel.comm.KernelControlCommandListHandler;
import com.twosigma.beakerx.kernel.comm.KernelControlInterrupt;
import com.twosigma.beakerx.kernel.comm.KernelControlSetShellHandler;
import com.twosigma.beakerx.kernel.comm.TargetNamesEnum;
import com.twosigma.beakerx.kernel.handler.CommOpenHandler;
import com.twosigma.beakerx.message.Message;
Expand All @@ -34,23 +34,26 @@
*/
public class ScijavaCommOpenHandler extends CommOpenHandler {

private final Handler<?>[] KERNEL_CONTROL_CHANNEL_HANDLERS = {
new KernelControlSetShellHandler(kernel),
new ScijavaCommKernelControlSetShellHandler(kernel),
new KernelControlInterrupt(kernel),
new KernelControlCommandListHandler(kernel)
};
private final Handler<?>[] KERNEL_CONTROL_CHANNEL_HANDLERS = {
new KernelControlInterrupt(kernel),
new KernelControlCommandListHandler(kernel)};

public ScijavaCommOpenHandler(KernelFunctionality kernel) {
super(kernel);
}
private final Handler<?>[] KERNEL_GET_CODECELLS_CHANNEL_HANDLER = {
new GetCodeCellsHandler(kernel)};

public ScijavaCommOpenHandler(KernelFunctionality kernel) {
super(kernel);
}

@Override
public Handler<Message>[] getKernelControlChanelHandlers(String targetName) {
if (TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)) {
return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS;
}
return (Handler<Message>[]) new Handler<?>[0];
@Override
public Handler<Message>[] getKernelControlChanelHandlers(String targetName) {
if (TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)) {
return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS;
} else if (TargetNamesEnum.BEAKER_GETCODECELLS.getTargetName().equalsIgnoreCase(targetName)) {
return (Handler<Message>[]) KERNEL_GET_CODECELLS_CHANNEL_HANDLER;
} else {
return (Handler<Message>[]) new Handler<?>[0];
}
}

}
Loading