Java Code Examples for com.twosigma.beakerx.message.Message#setContent()
The following examples show how to use
com.twosigma.beakerx.message.Message#setContent() .
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: TableDisplayActionsTest.java From beakerx with Apache License 2.0 | 6 votes |
private Message actionDetailsMessage() { Message message = new Message(initHeader(JupyterMessages.COMM_MSG)); Map<String, Serializable> content = new LinkedHashMap<>(); content.put(COMM_ID, tableDisplay.getComm().getCommId()); Map<String, Serializable> dataContent = new LinkedHashMap<>(); dataContent.put("event", CommActions.ACTIONDETAILS.getAction()); Map<String, Serializable> params = new LinkedHashMap<>(); params.put("actionType", CONTEXT_MENU_CLICK.getAction()); params.put("row", 1); params.put("col", 1); params.put("contextMenuItem", "run print cell"); Map<String, Serializable> data = new LinkedHashMap<>(); content.put("data", (Serializable) data); data.put("content", (Serializable) dataContent); dataContent.put("params", (Serializable) params); message.setContent(content); return message; }
Example 2
Source File: CommInfoHandler.java From beakerx with Apache License 2.0 | 6 votes |
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: CommCloseHandler.java From beakerx with Apache License 2.0 | 6 votes |
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 4
Source File: BxComm.java From beakerx with Apache License 2.0 | 6 votes |
public void close() { Message parentMessage = getParentMessage(); if (this.getCloseCallbackList() != null && !this.getCloseCallbackList().isEmpty()) { for (Handler<Message> handler : getCloseCallbackList()) { handler.handle(parentMessage); } } Message message = new Message(new Header(COMM_CLOSE, parentMessage.getHeader().getSession())); if (parentMessage != null) { message.setParentHeader(parentMessage.getHeader()); } HashMap<String, Serializable> map = new HashMap<>(); map.put(COMM_ID, getCommId()); map.put(DATA, new HashMap<>()); map.put(METADATA, new HashMap<>()); message.setContent(map); message.setMetadata(buildMetadata()); kernel.removeComm(getCommId()); kernel.publish(singletonList(message)); }
Example 5
Source File: BxComm.java From beakerx with Apache License 2.0 | 6 votes |
private void doOpen(Message parentMessage, Buffer buffer) { Preconditions.checkNotNull(parentMessage, "parent message can not be null"); Message message = new Message(new Header(COMM_OPEN, parentMessage.getHeader().getSession())); message.setParentHeader(parentMessage.getHeader()); HashMap<String, Serializable> map = new HashMap<>(); map.put(COMM_ID, getCommId()); map.put(TARGET_NAME, getTargetName()); HashMap<String, Serializable> state = new HashMap<>(); state.put(STATE, data.getData()); state.put(METHOD, (Serializable) data.getData().get(METHOD)); if (!buffer.isEmpty()) { state.put(BUFFER_PATHS, buffer.getBufferPaths()); message.setBuffers(buffer.getBuffers()); } map.put(DATA, state); map.put(METADATA, metadata); map.put(TARGET_MODULE, getTargetModule()); message.setContent(map); message.setMetadata(buildMetadata()); kernel.publish(singletonList(message)); kernel.addComm(getCommId(), this); }
Example 6
Source File: SparkUITest.java From beakerx with Apache License 2.0 | 6 votes |
@NotNull private Message saveProfilesMsg(HashMap<String, Serializable> profiles) { HashMap<String, Serializable> dataContent = new HashMap<String, Serializable>() { { put("content", profiles); } }; HashMap<String, Serializable> content = new HashMap<String, Serializable>() { { put("data", dataContent); } }; Message message = new Message(new Header(JupyterMessages.COMM_OPEN, "s1")); message.setContent(content); return message; }
Example 7
Source File: TableDisplayActionsTest.java From beakerx with Apache License 2.0 | 6 votes |
private Message contextMenuMessage() { Message message = new Message(initHeader(JupyterMessages.COMM_MSG)); Map<String, Serializable> content = new LinkedHashMap<>(); content.put(COMM_ID, tableDisplay.getComm().getCommId()); Map<String, Serializable> dataContent = new LinkedHashMap<>(); dataContent.put("event", CONTEXT_MENU_CLICK.getAction()); dataContent.put("row", 1); dataContent.put("column", 1); dataContent.put("itemKey", "tag1ByClosure"); Map<String, Serializable> data = new LinkedHashMap<>(); data.put("content", (Serializable) dataContent); content.put("data", (Serializable) data); message.setContent(content); return message; }
Example 8
Source File: TableDisplayActionsTest.java From beakerx with Apache License 2.0 | 6 votes |
private Message doubleClickActionMessage() { Message message = new Message(initHeader(JupyterMessages.COMM_MSG)); Map<String, Serializable> content = new LinkedHashMap<>(); content.put(COMM_ID, tableDisplay.getComm().getCommId()); Map<String, Serializable> dataContent = new LinkedHashMap<>(); dataContent.put("event", DOUBLE_CLICK.getAction()); dataContent.put("row", 1); dataContent.put("column", 1); dataContent.put("itemKey", "tag1ByClosure"); Map<String, Serializable> data = new LinkedHashMap<>(); data.put("content", (Serializable) dataContent); content.put("data", (Serializable) data); message.setContent(content); return message; }
Example 9
Source File: MessageCreator.java From beakerx with Apache License 2.0 | 5 votes |
public static Message buildClearOutput(Message message, boolean wait) { Message reply = initMessage(CLEAR_OUTPUT, message); reply.setContent(new HashMap<>()); reply.getContent().put("wait", wait); reply.getContent().put("metadata", new HashMap<>()); return reply; }
Example 10
Source File: ExecuteRequestHandlerTest.java From beakerx with Apache License 2.0 | 5 votes |
private static Message copyMessage(Message origin) { String header = toJson(origin.getHeader()); Message copy = new Message(parse(header, Header.class)); for (byte[] list : origin.getIdentities()) { copy.getIdentities().add(list.clone()); } String parent = toJson(origin.getParentHeader()); String metadata = toJson(origin.getMetadata()); String content = toJson(origin.getContent()); copy.setParentHeader(parse(parent, Header.class)); copy.setMetadata(parse(metadata, LinkedHashMap.class)); copy.setContent(parse(content, LinkedHashMap.class)); return copy; }
Example 11
Source File: JupyterHandlerTest.java From beakerx with Apache License 2.0 | 5 votes |
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 12
Source File: MessageCreator.java From beakerx with Apache License 2.0 | 5 votes |
public static Message buildOutputMessage(Message message, String text, boolean hasError) { Message reply = initMessage(STREAM, message); reply.setContent(new HashMap<>()); reply.getContent().put(NAME, hasError ? STDERR : STDOUT); reply.getContent().put(TEXT, text); logger.debug("Console output:", "Error: " + hasError, text); return reply; }
Example 13
Source File: MessageCreator.java From beakerx with Apache License 2.0 | 5 votes |
private static Message getExecutionStateMessage(Message parentMessage, String state) { Map<String, Serializable> map1 = new HashMap<String, Serializable>(1); map1.put(EXECUTION_STATE, state); Message reply = initMessage(STATUS, parentMessage); reply.setContent(map1); return reply; }
Example 14
Source File: IsCompleteRequestHandler.java From beakerx with Apache License 2.0 | 5 votes |
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 15
Source File: JupyterHandlerTest.java From beakerx with Apache License 2.0 | 5 votes |
public static Message createExecuteRequestMessage(String code) { Message message = executeRequestMessage(); Map<String, Serializable> content = new LinkedHashMap<>(); content.put("code", code); message.setContent(content); return message; }
Example 16
Source File: BxComm.java From beakerx with Apache License 2.0 | 5 votes |
public static Message messageMessage(JupyterMessages type, Buffer buffer, Map<String, Serializable> content, Message parentMessage) { Message message = new Message(new Header(type, parentMessage.getHeader().getSession())); checkNotNull(parentMessage); message.setParentHeader(parentMessage.getHeader()); message.setContent(content); message.setMetadata(buildMetadata()); if (!buffer.isEmpty()) { message.setBuffers(buffer.getBuffers()); } return message; }
Example 17
Source File: GroovyKernelTest.java From beakerx with Apache License 2.0 | 5 votes |
private Message outputWidgetUpdateMessage(String outputCommId) { Message message = msg(JupyterMessages.COMM_MSG); HashMap<String, Serializable> content = new HashMap<>(); HashMap<String, Serializable> data = new HashMap<>(); data.put("method", "update"); HashMap<String, Serializable> state = new HashMap<>(); state.put("outputs", new ArrayList<>()); data.put("state", state); content.put("comm_id", outputCommId); content.put("data", data); message.setContent(content); return message; }
Example 18
Source File: KernelSocketsZMQ.java From beakerx with Apache License 2.0 | 5 votes |
private void handleControlMsg() { Message message = readMessage(controlSocket); JupyterMessages type = message.getHeader().getTypeEnum(); if (type.equals(SHUTDOWN_REQUEST)) { Message reply = new Message(new Header(SHUTDOWN_REPLY, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setContent(message.getContent()); sendMsg(controlSocket, Collections.singletonList(reply)); shutdown(); } }
Example 19
Source File: JupyterHandlerTest.java From beakerx with Apache License 2.0 | 4 votes |
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 20
Source File: JupyterHandlerTest.java From beakerx with Apache License 2.0 | 4 votes |
public static void initMessage(Message message) { message.getIdentities().add("identityStr".getBytes()); message.setParentHeader(message.getHeader()); message.setMetadata(new LinkedHashMap<>()); message.setContent(new LinkedHashMap<>()); }