Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] #7388 fix foldout for mvn added jars #7390

Merged
merged 2 commits into from
May 22, 2018
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
Prev Previous commit
#7388: sending session in headers
  • Loading branch information
jaroslawmalekcodete committed May 22, 2018
commit 5e0224cb4a058dd27dc3b53d4cf5ed58b09bf8a7
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public void handle(Message message) {

private void handleMsg(Message message) {
logger.debug("Processing kernel info request");
Message reply = new Message();
Message reply = new Message(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession()));
reply.setContent(content());
reply.setHeader(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession()));
reply.setParentHeader(message.getHeader());
reply.setIdentities(message.getIdentities());
send(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public BaseEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolde
}

protected TryResult evaluate(SimpleEvaluationObject seo, Callable<TryResult> callable) {
InternalVariable.setValue(seo);
Future<TryResult> submit = executorService.submit(callable);
TryResult either = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ private void handleMsg(Message message) {
}

private Message createMsg(Message message, int cursorPos, AutocompleteResult autocomplete) {
Message reply = new Message();
reply.setHeader(new Header(COMPLETE_REPLY, message.getHeader().getSession()));
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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ private void handleMsg(Message message) {
}

private Message createMsg(Message message, InspectResult inspectResult) {
Message reply = new Message();
reply.setHeader(new Header(INSPECT_REPLY, message.getHeader().getSession()));
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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ public void handle(Message message) {

private void handleMsg(Message message) {
logger.debug("Processing is complete request");
Message reply = new Message();
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.setHeader(new Header(IS_COMPLETE_REPLY, message.getHeader().getSession()));
reply.setParentHeader(message.getHeader());
reply.setIdentities(message.getIdentities());
send(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,13 @@ private List<Message> getIopubMessages() throws IOException {

private Message parseMessage(String stringJson) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Message msg = new Message();
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);
msg.setHeader(mapper.convertValue(json.get("header"), Header.class));
return msg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ protected T getValueFromData(Message message, String key) {
protected Message createReplyMessage(Message message, Serializable responceData) {
Message ret = null;
if (message != null) {
ret = new Message();
ret = new Message(new Header(COMM_MSG, message.getHeader().getSession()));
Map<String, Serializable> commMap = message.getContent();
ret.setHeader(new Header(COMM_MSG, message.getHeader().getSession()));
HashMap<String, Serializable> map = new HashMap<>();
map.put(COMM_ID, getString(commMap, COMM_ID));
map.put(DATA, responceData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.twosigma.beakerx.kernel.msg.JupyterMessages;
import com.twosigma.beakerx.message.Header;
import com.twosigma.beakerx.message.Message;
import com.twosigma.beakerx.util.Preconditions;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -34,6 +35,7 @@
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.COMM_CLOSE;
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.COMM_MSG;
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.COMM_OPEN;
import static com.twosigma.beakerx.util.Preconditions.checkNotNull;
import static java.util.Collections.EMPTY_LIST;
import static java.util.Collections.singletonList;

Expand Down Expand Up @@ -140,15 +142,12 @@ public void open(Comm.Buffer buffer) {

public void open(Message parentMessage) {
getParentMessageStrategy = () -> parentMessage;
open();
doOpen(parentMessage, Buffer.EMPTY);
}

private void doOpen(Message parentMessage, Buffer buffer) {
Message message = new Message();
message.setHeader(new Header(COMM_OPEN, parentMessage != null ? parentMessage.getHeader().getSession() : null));
if (parentMessage != null) {
message.setParentHeader(parentMessage.getHeader());
}
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());
Expand Down Expand Up @@ -178,8 +177,7 @@ public void close() {
handler.handle(parentMessage);
}
}
Message message = new Message();
message.setHeader(new Header(COMM_CLOSE, parentMessage != null ? parentMessage.getHeader().getSession() : null));
Message message = new Message(new Header(COMM_CLOSE, parentMessage.getHeader().getSession()));
if (parentMessage != null) {
message.setParentHeader(parentMessage.getHeader());
}
Expand Down Expand Up @@ -207,6 +205,16 @@ public void send(JupyterMessages type, Comm.Buffer buffer, Comm.Data data) {
kernel.publish(singletonList(message));
}

public Message createMessage(JupyterMessages type, Buffer buffer, Comm.Data data, Message parent) {
HashMap<String, Serializable> map = new HashMap<>(6);
if (type != JupyterMessages.DISPLAY_DATA) {
map.put(COMM_ID, getCommId());
}
map.put(DATA, data.getData());
map.put(METADATA, metadata);
return create(type, buffer, map, parent);
}

public Message createMessage(JupyterMessages type, Buffer buffer, Comm.Data data) {
HashMap<String, Serializable> map = new HashMap<>(6);
if (type != JupyterMessages.DISPLAY_DATA) {
Expand All @@ -217,17 +225,18 @@ public Message createMessage(JupyterMessages type, Buffer buffer, Comm.Data data
return create(type, buffer, map);
}

private Message create(JupyterMessages type, Comm.Buffer buffer, Map<String, Serializable> content, Message parent) {
return messageMessage(type, buffer, content, parent);
}

private Message create(JupyterMessages type, Comm.Buffer buffer, Map<String, Serializable> content) {
Message parentMessage = getParentMessage();
return messageMessage(type, buffer, content, parentMessage);
return messageMessage(type, buffer, content, getParentMessage());
}

public static Message messageMessage(JupyterMessages type, Buffer buffer, Map<String, Serializable> content, Message parentMessage) {
Message message = new Message();
message.setHeader(new Header(type, parentMessage != null ? parentMessage.getHeader().getSession() : null));
if (parentMessage != null) {
message.setParentHeader(parentMessage.getHeader());
}
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()) {
Expand Down Expand Up @@ -258,6 +267,21 @@ public void sendUpdate(final String propertyName, final Object value) {
kernel.publish(singletonList(message));
}

public void sendUpdate(final String propertyName, final Object value, Message parent) {
Message message = createUpdateMessage(propertyName, value, parent);
kernel.publish(singletonList(message));
}

public Message createUpdateMessage(String propertyName, Object value, Message parent) {
HashMap<String, Serializable> content = new HashMap<>();
content.put(METHOD, UPDATE);
HashMap<Object, Object> state = new HashMap<>();
state.put(propertyName, value);
content.put(STATE, state);
content.put(BUFFER_PATHS, new HashMap<>());
return this.createMessage(COMM_MSG, Buffer.EMPTY, new Comm.Data(content), parent);
}

public Message createUpdateMessage(String propertyName, Object value) {
HashMap<String, Serializable> content = new HashMap<>();
content.put(METHOD, UPDATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private void handleMsg(Message message) {
: "";
kernel.removeComm(getString(commMap, COMM_ID));

Message reply = new Message();
reply.setHeader(new Header(COMM_CLOSE, message.getHeader().getSession()));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void handle(Message message) {

private void handleMsg(Message message) {
logger.debug("Processing CommInfoHandler");
Message reply = new Message();
reply.setHeader(new Header(COMM_INFO_REPLY, message.getHeader().getSession()));
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>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ public void handle(Message message) {

private void handleMsg(Message message) {
logger.debug("Processing CommOpenHandler");
Message reply = new Message();
Message reply = null;
HashMap<String, Serializable> map = new HashMap<>(6);

Map<String, Serializable> commMap = message.getContent();
Comm newComm = null;
if (isValidMessage(commMap)) {
newComm = readComm(commMap);
reply.setHeader(new Header(COMM_OPEN, message.getHeader().getSession()));
reply = new Message(new Header(COMM_OPEN, message.getHeader().getSession()));
map.put(COMM_ID, newComm.getCommId());
map.put(TARGET_NAME, newComm.getTargetName());
map.put(DATA, new HashMap<>());
map.put(TARGET_MODULE, newComm.getTargetModule());
} else {
reply.setHeader(new Header(COMM_CLOSE, message.getHeader().getSession()));
reply = new Message(new Header(COMM_CLOSE, message.getHeader().getSession()));
map.put(DATA, new HashMap<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.twosigma.beakerx.kernel.handler;


import com.twosigma.beakerx.handler.KernelHandler;
import com.twosigma.beakerx.jvm.object.SimpleEvaluationObject;
import com.twosigma.beakerx.kernel.Code;
Expand Down Expand Up @@ -83,10 +82,9 @@ private String takeCodeFrom(Message message) {
}

private void announceTheCode(Message message, String code) {
Message reply = new Message();
Message reply = new Message(new Header(EXECUTE_INPUT, message.getHeader().getSession()));
reply.setParentHeader(message.getHeader());
reply.setIdentities(message.getIdentities());
reply.setHeader(new Header(EXECUTE_INPUT, message.getHeader().getSession()));
Map<String, Serializable> map1 = new HashMap<>(2);
map1.put("execution_count", executionCount);
map1.put("code", code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.twosigma.beakerx.kernel.KernelFunctionality;
import com.twosigma.beakerx.kernel.magic.command.MagicCommandFunctionality;
import com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput;
import com.twosigma.beakerx.message.Header;
import com.twosigma.beakerx.message.Message;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -113,7 +114,7 @@ protected MagicCommandOutput timeIt(TimeItOption timeItOption, String codeToExec
if (timeItOption.getNumber() < 0) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "Number of execution must be bigger then 0");
}
int number = timeItOption.getNumber() == 0 ? getBestNumber(codeToExecute, showResult) : timeItOption.getNumber();
int number = timeItOption.getNumber() == 0 ? getBestNumber(codeToExecute, showResult,message) : timeItOption.getNumber();

if (timeItOption.getRepeat() == 0) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "Repeat value must be bigger then 0");
Expand Down Expand Up @@ -211,15 +212,15 @@ private Options createForTimeIt() {
return options;
}

private int getBestNumber(String codeToExecute, boolean showResult) {
private int getBestNumber(String codeToExecute, boolean showResult, Message message) {
for (int value = 0; value < 10; ) {
Double numberOfExecution = Math.pow(10, value);
CompletableFuture<Boolean> keepLooking = new CompletableFuture<>();

Long startTime = System.nanoTime();
IntStream.range(0, numberOfExecution.intValue()).forEach(indexOfExecution -> {

SimpleEvaluationObject simpleEvaluationObject = createSimpleEvaluationObject(codeToExecute, kernel, new Message(), 0);
SimpleEvaluationObject simpleEvaluationObject = createSimpleEvaluationObject(
codeToExecute, kernel, new Message(new Header(message.type(), message.getHeader().getSession())), 0);
if (!showResult) {
simpleEvaluationObject.noResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ protected boolean validateCommandFormat(MagicCommandExecutionParam param) {

private Message parseMessage(String stringJson) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Message msg = new Message();
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);
msg.setHeader(mapper.convertValue(json.get("header"), Header.class));
return msg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ private MessageCreator() {
}

private static Message initMessage(JupyterMessages type, Message message) {
Message reply = new Message();
Message reply = new Message(new Header(type, message.getHeader().getSession()));
reply.setParentHeader(message.getHeader());
reply.setIdentities(message.getIdentities());
reply.setHeader(new Header(type, message.getHeader().getSession()));
return reply;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.twosigma.beakerx.kernel.Utils.timestamp;
import static com.twosigma.beakerx.kernel.Utils.uuid;
import static com.twosigma.beakerx.util.Preconditions.checkNotNull;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
Expand All @@ -36,15 +37,16 @@ public class Header {
private JupyterMessages type;
private String version;

public Header() {
private Header(){
//only for jackson
}

public Header(JupyterMessages type, String session) {
date = timestamp();
id = uuid();
username = "kernel";
this.type = type;
this.session = session;
this.session = checkNotNull(session);
this.version = "5.3";
}

Expand Down Expand Up @@ -80,10 +82,6 @@ public String getSession() {
return session;
}

public void setSession(String session) {
this.session = session;
}

public String getType() {
return type != null ? type.getName() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.twosigma.beakerx.message;

import static com.twosigma.beakerx.kernel.Utils.timestamp;
import static com.twosigma.beakerx.util.Preconditions.checkNotNull;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -25,6 +26,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.twosigma.beakerx.kernel.msg.JupyterMessages;
import com.twosigma.beakerx.util.Preconditions;

@JsonPropertyOrder({"identities", "header", "parentHeader", "metadata", "content"})
public class Message {
Expand All @@ -37,8 +39,8 @@ public class Message {
private Map<String, Serializable> content;
private List<byte[]> buffers = new ArrayList<>();

public Message() {
header = new Header();
public Message(Header header) {
this.header = checkNotNull(header);
header.setDate(timestamp());
}

Expand All @@ -58,10 +60,6 @@ public Header getHeader() {
return header;
}

public void setHeader(Header header) {
this.header = header;
}

public Header getParentHeader() {
return parentHeader;
}
Expand Down
Loading