Java Code Examples for com.twosigma.beakerx.message.Message#setIdentities()

The following examples show how to use com.twosigma.beakerx.message.Message#setIdentities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommCloseHandler.java    From beakerx with Apache License 2.0 6 votes vote down vote up
private void handleMsg(Message message) {
  logger.debug("Processing CommCloseHandler");
  Map<String, Serializable> commMap = message.getContent();

  String targetName =
          (kernel.getComm(getString(commMap, COMM_ID)) != null)
                  ? kernel.getComm(getString(commMap, COMM_ID)).getTargetName()
                  : "";
  kernel.removeComm(getString(commMap, COMM_ID));

  Message reply = new Message(new Header(COMM_CLOSE, message.getHeader().getSession()));
  HashMap<String, Serializable> map = new HashMap<>();
  map.put(DATA, new HashMap<>());
  reply.setContent(map);
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  send(reply);
  logger.debug("Comm closed, target name = " + targetName);
}
 
Example 2
Source File: CommInfoHandler.java    From beakerx with Apache License 2.0 6 votes vote down vote up
private void handleMsg(Message message) {
  logger.debug("Processing CommInfoHandler");
  Message reply = new Message(new Header(COMM_INFO_REPLY, message.getHeader().getSession()));
  HashMap<String, Serializable> content = new HashMap<>();
  content.put(COMMS, new HashMap<String, Serializable>());

  String target = getMessageTarget(message);
  kernel.getCommHashSet().stream()
          .map(hash -> kernel.getComm(hash))
          .filter(comm -> target == null || target.isEmpty() || comm.getTargetName().equals(target))
          .forEach(comm -> {
            HashMap<String, Serializable> commRepDetails = new HashMap<>();
            commRepDetails.put(TARGET_NAME, comm.getTargetName());
            ((HashMap<String, Serializable>) content.get(COMMS)).put(comm.getCommId(), commRepDetails);
          });
  reply.setContent(content);
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  send(reply);
}
 
Example 3
Source File: KernelInfoHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private void handleMsg(Message message) {
  logger.debug("Processing kernel info request");
  Message reply = new Message(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession()));
  reply.setContent(content());
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  send(reply);
}
 
Example 4
Source File: JupyterHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private static Message executeRequestMessage() {
  Message message = new Message(initHeader(JupyterMessages.EXECUTE_REQUEST));
  message.setIdentities(Arrays.asList("identities".getBytes()));
  message.setParentHeader(null);
  message.setMetadata(new LinkedHashMap<>());
  return message;
}
 
Example 5
Source File: JupyterHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public static Message initOpenMessage() {
  Map<String, Serializable> content = new LinkedHashMap<>();
  content.put(DATA, new HashMap<>());
  content.put(COMM_ID, "commId");
  content.put(TARGET_NAME, "targetName");
  content.put(TARGET_MODULE, "targetModule");

  Message message = new Message(initHeader(JupyterMessages.COMM_OPEN));
  message.setIdentities(Arrays.asList("identities".getBytes()));
  message.setContent(content);
  return message;
}
 
Example 6
Source File: JupyterHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public static Message initCloseMessage() {
  Map<String, Serializable> content = new LinkedHashMap<>();
  content.put(DATA, new HashMap<>());
  content.put(COMM_ID, "commId");
  content.put(TARGET_NAME, "targetName");
  content.put(TARGET_MODULE, "targetModule");

  Message message = new Message(initHeader(JupyterMessages.COMM_CLOSE));
  message.setIdentities(Arrays.asList("identities".getBytes()));
  message.setContent(content);
  return message;
}
 
Example 7
Source File: InputRequestMessageFactoryImplTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void inputRequestMessage() {
  //given
  Message parent = new Message(new Header(EXECUTE_REQUEST, "session1"));
  List<byte[]> identities = Arrays.asList("MessageIdentities123".getBytes());
  parent.setIdentities(identities);
  //when
  Message message = inputRequestMessageFactory.create(parent);
  //then
  assertThat(message.getIdentities()).isEqualTo(identities);
  assertThat(message.type()).isEqualTo(JupyterMessages.INPUT_REQUEST);
}
 
Example 8
Source File: KernelMagicCommand.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private Message parseMessage(String stringJson) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode json = mapper.readTree(stringJson);
    Message msg = new Message(mapper.convertValue(json.get("header"), Header.class));
    msg.setContent(mapper.convertValue(json.get("content"), Map.class));
    msg.setMetadata(mapper.convertValue(json.get("metadata"), Map.class));
    msg.setBuffers(mapper.convertValue(json.get("buffers"), List.class));
    List<byte[]> identities = mapper.convertValue(json.get("comm_id"), List.class);
    msg.setIdentities(identities == null ? new ArrayList<>() : identities);
    return msg;
}
 
Example 9
Source File: ExecuteRequestHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private void announceTheCode(Message message, String code) {
  Message reply = new Message(new Header(EXECUTE_INPUT, message.getHeader().getSession()));
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  Map<String, Serializable> map1 = new HashMap<>(2);
  map1.put("execution_count", executionCount);
  map1.put("code", code);
  reply.setContent(map1);
  kernel.publish(singletonList(reply));
}
 
Example 10
Source File: MagicKernelManager.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private Message parseMessage(String stringJson) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  JsonNode json = mapper.readTree(stringJson);
  Message msg = new Message(mapper.convertValue(json.get("header"), Header.class));
  msg.setContent(mapper.convertValue(json.get("content"), Map.class));
  msg.setMetadata(mapper.convertValue(json.get("metadata"), Map.class));
  msg.setBuffers(mapper.convertValue(json.get("buffers"), List.class));
  List<byte[]> identities = mapper.convertValue(json.get("comm_id"), List.class);
  msg.setIdentities(identities == null ? new ArrayList<>() : identities);
  return msg;
}
 
Example 11
Source File: InspectHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private Message createMsg(Message message, InspectResult inspectResult) {
    Message reply = new Message(new Header(INSPECT_REPLY, message.getHeader().getSession()));
    reply.setIdentities(message.getIdentities());
    reply.setParentHeader(message.getHeader());
    Map<String, Serializable> content = new HashMap<>();
    content.put(STATUS, "ok");
    content.put(DATA, inspectResult.getData());
    //content.put(METADATA, {});
    content.put(FOUND, inspectResult.getFound());

    reply.setContent(content);
    return reply;
}
 
Example 12
Source File: CompleteHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private Message createMsg(Message message, int cursorPos, AutocompleteResult autocomplete) {
  Message reply = new Message(new Header(COMPLETE_REPLY, message.getHeader().getSession()));
  reply.setIdentities(message.getIdentities());
  reply.setParentHeader(message.getHeader());
  Map<String, Serializable> content = new HashMap<>();
  content.put(STATUS, "ok");
  content.put(MATCHES, autocomplete.getMatches().toArray());
  content.put(CURSOR_END, cursorPos);
  content.put(CURSOR_START, autocomplete.getStartIndex());

  reply.setContent(content);
  return reply;
}
 
Example 13
Source File: IsCompleteRequestHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private void handleMsg(Message message) {
  logger.debug("Processing is complete request");
  Message reply = new Message(new Header(IS_COMPLETE_REPLY, message.getHeader().getSession()));
  HashMap<String, Serializable> map = new HashMap<>();
  map.put("status", "complete");
  reply.setContent(map);
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  send(reply);
}
 
Example 14
Source File: ScijavaKernelInfoHandler.java    From scijava-jupyter-kernel with Apache License 2.0 5 votes vote down vote up
private void handleMsg(Message message) {

        Message reply = new Message();

        HashMap<String, Serializable> map = new HashMap<>(6);
        map.put("protocol_version", "5.0");
        map.put("implementation", "scijava");
        map.put("implementation_version", "1.0");

        HashMap<String, Serializable> map1 = new HashMap<>(7);
        map1.put("name", "scijava");
        map1.put("version", "1.0");
        map1.put("mimetype", "");
        map1.put("file_extension", "");
        map1.put("pygments_lexer", "groovy");
        map1.put("codemirror_mode", "groovy");
        map1.put("nbconverter_exporter", "");

        map.put("language_info", map1);
        String banner = "SciJava Jupyter Kernel v" + getClass().getPackage().getSpecificationVersion() + " | ";
        map.put("banner", banner);
        map.put("beakerx", true);

        List<String> helpLinks = new ArrayList<>();
        helpLinks.add("https://imagej.net/Jupyter");
        helpLinks.add("https://github.com/scijava/scijava-jupyter-kernel");
        map.put("help_links", (Serializable) helpLinks);

        reply.setContent(map);
        reply.setHeader(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession()));
        reply.setParentHeader(message.getHeader());
        reply.setIdentities(message.getIdentities());
        send(reply);
    }
 
Example 15
Source File: MessageCreator.java    From beakerx with Apache License 2.0 4 votes vote down vote up
private static Message initMessage(JupyterMessages type, Message message) {
  Message reply = new Message(new Header(type, message.getHeader().getSession()));
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  return reply;
}
 
Example 16
Source File: JupyterHandlerTest.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public static Message initCommMessage(Map<String, Serializable> content) {
  Message message = new Message(initHeader(JupyterMessages.COMM_MSG));
  message.setIdentities(Arrays.asList("identities".getBytes()));
  message.setContent(content);
  return message;
}
 
Example 17
Source File: JupyterHandlerTest.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public static Message initInfoMessage() {
  Message message = new Message(initHeader(JupyterMessages.COMM_INFO_REQUEST));
  message.setIdentities(Arrays.asList("identities".getBytes()));
  return message;
}
 
Example 18
Source File: MessageFactorTest.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public static Message msg(JupyterMessages type) {
  Message msg1 = new Message(new Header(type, "session1"));
  msg1.setIdentities(MESSAGE_IDENTITIES);
  return msg1;
}