Search in sources :

Example 1 with CommandDTO

use of org.ballerinalang.util.debugger.dto.CommandDTO in project ballerina by ballerina-lang.

the class DebugMsgUtil method buildCommandDTO.

/**
 * Method to build CommandDTO instance with given json msg.
 *
 * @param json msg String.
 * @return object instance.
 */
public static CommandDTO buildCommandDTO(String json) {
    JsonNode node = JsonParser.parse(json);
    CommandDTO commandDTO = new CommandDTO();
    commandDTO.setCommand(node.get(COMMAND) == null ? null : node.get(COMMAND).stringValue());
    commandDTO.setThreadId(node.get(THREAD_ID) == null ? null : node.get(THREAD_ID).stringValue());
    commandDTO.setPoints(buildBreakPoints(node.get(POINTS)));
    return commandDTO;
}
Also used : JsonNode(org.ballerinalang.model.util.JsonNode) CommandDTO(org.ballerinalang.util.debugger.dto.CommandDTO)

Example 2 with CommandDTO

use of org.ballerinalang.util.debugger.dto.CommandDTO in project ballerina by ballerina-lang.

the class Debugger method processCommand.

private void processCommand(String json) {
    CommandDTO command;
    try {
        command = DebugMsgUtil.buildCommandDTO(json);
    } catch (Exception e) {
        // invalid message will be passed
        throw new DebugException(DebugConstants.MSG_INVALID);
    }
    switch(command.getCommand()) {
        case DebugConstants.CMD_RESUME:
            resume(command.getThreadId());
            break;
        case DebugConstants.CMD_STEP_OVER:
            stepOver(command.getThreadId());
            break;
        case DebugConstants.CMD_STEP_IN:
            stepIn(command.getThreadId());
            break;
        case DebugConstants.CMD_STEP_OUT:
            stepOut(command.getThreadId());
            break;
        case DebugConstants.CMD_STOP:
            // When stopping the debug session, it will clear all debug points and resume all threads.
            stopDebugging();
            break;
        case DebugConstants.CMD_SET_POINTS:
            // we expect { "command": "SET_POINTS", points: [{ "fileName": "sample.bal", "lineNumber" : 5 },{...}]}
            addDebugPoints(command.getPoints());
            sendAcknowledge("Debug points updated");
            break;
        case DebugConstants.CMD_START:
            // Client needs to explicitly start the execution once connected.
            // This will allow client to set the breakpoints before starting the execution.
            sendAcknowledge("Debug started.");
            startDebug();
            break;
        default:
            throw new DebugException(DebugConstants.MSG_INVALID);
    }
}
Also used : CommandDTO(org.ballerinalang.util.debugger.dto.CommandDTO)

Aggregations

CommandDTO (org.ballerinalang.util.debugger.dto.CommandDTO)2 JsonNode (org.ballerinalang.model.util.JsonNode)1