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; }
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; }
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); }
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; }