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

The following examples show how to use com.twosigma.beakerx.message.Message#getContent() . 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: CommMsgHandler.java    From beakerx with Apache License 2.0 6 votes vote down vote up
private void handleMsg(Message message) {
  Map<String, Serializable> commMap = message.getContent();
  String commId = getString(commMap, COMM_ID);
  Comm comm = kernel.getComm(commId);
  logger.debug("Comm message handling, target name: " + (comm != null ? comm.getTargetName() : "undefined"));
  if (comm != null) {
    comm.handleMsg(message);
  } else {
    MagicKernelManager magicKernelManager = kernel.getManagerByCommId(commId);
    if (magicKernelManager != null) {
      List<Message> messages = magicKernelManager.handleMsg(message);
      if (!messages.isEmpty()) {
        kernel.publish(messages);
        return;
      }
    }
    logger.warn("No such comm: " + getString(commMap, COMM_ID));
  }
}
 
Example 2
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 3
Source File: DOMWidget.java    From beakerx with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Optional<Object> getSyncDataValue(Message msg) {
  Optional<Object> ret = Optional.empty();
  if (msg != null && msg.getContent() != null && msg.getContent().containsKey(DATA)) {
    Map<String, Serializable> data = (Map<String, Serializable>) msg.getContent().get(DATA);
    if (data.containsKey(SYNC_DATA)) {
      Map<String, Serializable> sync_data = (Map<String, Serializable>) data.get(SYNC_DATA);
      if (sync_data.containsKey(VALUE)) {
        ret = Optional.of(sync_data.get(VALUE));
      } else if (sync_data.containsKey(INDEX)) {
        ret = Optional.of(sync_data.get(INDEX));
      } else if (sync_data.containsKey("outputs")) {
        ret = Optional.of(sync_data.get("outputs"));
      }
    }
  }
  return ret;
}
 
Example 4
Source File: CompiledCodeRunner.java    From beakerx with Apache License 2.0 6 votes vote down vote up
static void runCommEvent(Message message, CommActions action, Widget.ActionPerformed handlerAction) {
  if (message.getContent() != null) {
    Serializable data = message.getContent().get("data");
    if (data != null && data instanceof LinkedHashMap) {
      Object contentObject = ((LinkedHashMap) data).get("content");
      if (contentObject instanceof LinkedHashMap) {
        HashMap content = (LinkedHashMap) contentObject;
        if (handlerAction != null) {
          final SimpleEvaluationObject seo = initOutput(message);
          handlerAction.executeAction(content, message);
          seo.clrOutputHandler();
        }
      }
    }
  }
}
 
Example 5
Source File: GroovyKernelInfoHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void handle_sentMessageHasLanguageInfo() throws Exception {
  //when
  handler.handle(message);
  //then
  Message sentMessage = kernel.getSentMessages().get(0);
  Map<String, Serializable> map = sentMessage.getContent();
  Assertions.assertThat(map).isNotNull();
  Assertions.assertThat(map.get("language_info")).isNotNull();
}
 
Example 6
Source File: BaseHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
protected Map<String, T> getData(Message message) {
  Map<String, T> ret = null;
  if (message != null) {
    Map<String, Serializable> commMap = message.getContent();
    ret = (HashMap<String, T>) commMap.get(DATA);
  } else {
    logger.info("Comm message contend is null");
  }
  return ret;
}
 
Example 7
Source File: GroovyExamplesSetupTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private boolean isWidget(Message message, String viewNameValue) {
  if (message.getContent() != null) {
    Map<String, Serializable> data = getState(message);
    if (data != null) {
      Serializable easyForm = data.get(Widget.VIEW_NAME);
      if (easyForm != null) {
        return easyForm.equals(viewNameValue);
      }
    }
  }
  return false;
}
 
Example 8
Source File: GroovyKernelInfoHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void handle_messageContentHasGroovyLabel() throws Exception {
  //when
  handler.handle(message);
  //then
  Message sentMessage = kernel.getSentMessages().get(0);
  Map<String, Serializable> map = sentMessage.getContent();
  Assertions.assertThat(map).isNotNull();
  Assertions.assertThat(map.get("implementation")).isEqualTo("groovy");
}
 
Example 9
Source File: ScalaKernelInfoHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void handle_sentMessageHasLanguageInfo() throws Exception {
  //when
  handler.handle(message);
  //then
  Message sentMessage = kernel.getSentMessages().get(0);
  Map<String, Serializable> map = sentMessage.getContent();
  Assertions.assertThat(map).isNotNull();
  Assertions.assertThat(map.get("language_info")).isNotNull();
}
 
Example 10
Source File: ClojureKernelInfoHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void handle_sentMessageHasLanguageInfo() throws Exception {
  //when
  handler.handle(message);
  //then
  Message sentMessage = kernel.getSentMessages().get(0);
  Map<String, Serializable> map = sentMessage.getContent();
  Assertions.assertThat(map).isNotNull();
  Assertions.assertThat(map.get("language_info")).isNotNull();
}
 
Example 11
Source File: MessageCreatorTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void createBusyMessage_messageHasExecutionStateIsBusy() {
  //when
  Message message = MessageCreator.createBusyMessage(commMsg());
  //then
  Map data = message.getContent();
  assertThat(data.get(MessageCreator.EXECUTION_STATE)).isEqualTo(MessageCreator.BUSY);
}
 
Example 12
Source File: MessageCreatorTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void createIdleMessage_messageHasExecutionStateIsIdle() {
  //when
  Message message = MessageCreator.createIdleMessage(commMsg());
  //then
  Map data = message.getContent();
  assertThat(data.get(MessageCreator.EXECUTION_STATE)).isEqualTo(MessageCreator.IDLE);
}
 
Example 13
Source File: KotlinKernelInfoHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void handle_messageContentHasKotlinLabel() throws Exception {
  //when
  handler.handle(message);
  //then
  Message sentMessage = kernel.getSentMessages().get(0);
  Map<String, Serializable> map = sentMessage.getContent();
  Assertions.assertThat(map).isNotNull();
  Assertions.assertThat(map.get("implementation")).isEqualTo("kotlin");
}
 
Example 14
Source File: StateRequestMsgCallbackHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Message message) {
  if (message.getContent()!= null && message.getContent().containsKey("data")) {
    Map data = (Map) message.getContent().get("data");
    if (data.containsKey("method")) {
      String method = (String) data.get("method");
      if (method.equals("request_state")) {
        action.execute();
      }
    }
  }
}
 
Example 15
Source File: ValueChangeMsgCallbackHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public Optional<Property> getSyncDataValue(Message msg) {
  Optional<Property> ret = Optional.empty();
  if (msg != null && msg.getContent() != null && msg.getContent().containsKey("data")) {
    Map<String, Serializable> data = (Map<String, Serializable>) msg.getContent().get("data");
    if (data.containsKey("state")) {
      Map<String, Serializable> sync_data = (Map<String, Serializable>) data.get("state");
      if (sync_data.containsKey("loadMoreRows")) {
        ret = Optional.of(new Property("loadMoreRows", sync_data.get("loadMoreRows")));
      }
    }
  }
  return ret;
}
 
Example 16
Source File: GroovyCompleteHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private void verifyAutocompleteMsg(Message reply, int expectedCursorStart, int expectedCursorEnd) {
  Map<String, Serializable> content = reply.getContent();
  int cursorStart = (int) content.get(CompleteHandler.CURSOR_START);
  assertThat(cursorStart).isEqualTo(expectedCursorStart);
  int cursorEnd = (int) content.get(CompleteHandler.CURSOR_END);
  assertThat(cursorEnd).isEqualTo(expectedCursorEnd);
  Object[] matches = (Object[]) content.get(CompleteHandler.MATCHES);
  assertThat(matches).isNotEmpty();
}
 
Example 17
Source File: ClojureKernelInfoHandlerTest.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Test
public void handle_messageContentHasClojureLabel() throws Exception {
  //when
  handler.handle(message);
  //then
  Message sentMessage = kernel.getSentMessages().get(0);
  Map<String, Serializable> map = sentMessage.getContent();
  Assertions.assertThat(map).isNotNull();
  Assertions.assertThat(map.get("implementation")).isEqualTo("clojure");
}
 
Example 18
Source File: MagicCommandAssertions.java    From beakerx with Apache License 2.0 4 votes vote down vote up
private static boolean isStderr(Message message) {
  return message.getContent() != null &&
          message.getContent().get("name") != null && message.getContent().get("name").equals("stderr") &&
          message.getContent().get("text") != null;
}
 
Example 19
Source File: MessageAssertions.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public static boolean isIdleMessage(Message message) {
  return message.getContent() != null &&
          message.getContent().get("execution_state") != null &&
          message.getContent().get("execution_state").equals("idle");
}
 
Example 20
Source File: MessageAssertions.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public static boolean isBusyMessage(Message message) {
  return  message.getContent() != null &&
          message.getContent().get("execution_state") != null &&
          message.getContent().get("execution_state").equals("busy");
}