use of com.github.cameltooling.idea.runner.debugger.stack.CamelMessageInfo in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerRunner method attachVM.
private RunContentDescriptor attachVM(final RunProfileState state, @NotNull final ExecutionEnvironment env, RemoteConnection connection, boolean pollConnection) throws ExecutionException {
LOG.debug("Attaching VM...");
DefaultDebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollConnection);
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
final CamelDebuggerSession camelDebuggerSession = new CamelDebuggerSession();
if (debuggerSession == null) {
return null;
} else {
final DebugProcessImpl debugProcess = debuggerSession.getProcess();
if (!debugProcess.isDetached() && !debugProcess.isDetaching()) {
if (environment.isRemote()) {
debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
}
return XDebuggerManager.getInstance(env.getProject()).startSession(env, new XDebugProcessStarter() {
@NotNull
public XDebugProcess start(@NotNull XDebugSession session) {
final XDebugSessionImpl sessionImpl = (XDebugSessionImpl) session;
final ExecutionResult executionResult = debugProcess.getExecutionResult();
final Map<String, XDebugProcess> context = new HashMap<>();
final ContextAwareDebugProcess contextAwareDebugProcess = new ContextAwareDebugProcess(session, executionResult.getProcessHandler(), context, JAVA_CONTEXT);
camelDebuggerSession.addMessageReceivedListener(new MessageReceivedListener() {
@Override
public void onNewMessageReceived(CamelMessageInfo camelMessageInfo) {
contextAwareDebugProcess.setContext(CAMEL_CONTEXT);
}
});
debuggerSession.getContextManager().addListener((newContext, event) -> contextAwareDebugProcess.setContext(JAVA_CONTEXT));
// Init Java Debug Process
sessionImpl.addExtraActions(executionResult.getActions());
if (executionResult instanceof DefaultExecutionResult) {
sessionImpl.addRestartActions(((DefaultExecutionResult) executionResult).getRestartActions());
// sessionImpl.addExtraStopActions(((DefaultExecutionResult) executionResult).getAdditionalStopActions());
}
final JavaDebugProcess javaDebugProcess = JavaDebugProcess.create(session, debuggerSession);
// Init Camel Debug Process
final CamelDebugProcess camelDebugProcess = new CamelDebugProcess(session, camelDebuggerSession, javaDebugProcess.getProcessHandler());
// Register All Processes
context.put(JAVA_CONTEXT, javaDebugProcess);
context.put(CAMEL_CONTEXT, camelDebugProcess);
return contextAwareDebugProcess;
}
}).getRunContentDescriptor();
} else {
debuggerSession.dispose();
camelDebuggerSession.dispose();
return null;
}
}
}
use of com.github.cameltooling.idea.runner.debugger.stack.CamelMessageInfo in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method stepOut.
public void stepOut(XSourcePosition position) {
try {
Map<String, PsiElement> breakpointElement = createBreakpointElementFromPosition(position);
if (breakpointElement == null) {
// TODO Log warning
return;
}
String breakpointId = breakpointElement.keySet().iterator().next();
// Get the route of the current tag
Element routeElement = getParentRouteId(breakpointId);
String routeId = routeElement.getAttribute("id");
// Get current stack and find the caller in the stack
List<CamelMessageInfo> stack = getStack(breakpointId, backlogDebugger.dumpTracedMessagesAsXml(breakpointId));
CamelMessageInfo callerStackFrame = stack.stream().filter(info -> !info.getRouteId().equals(routeId) && info.getProcessorId().startsWith("to")).findFirst().orElse(null);
if (callerStackFrame == null) {
// This is the top route
resume();
} else {
String newTemporaryBreakpointId = getSiblingId(callerStackFrame.getProcessorId());
if (newTemporaryBreakpointId != null) {
// Add temporary breakpoint
backlogDebugger.addBreakpoint(newTemporaryBreakpointId);
// Run to that breakpoint
backlogDebugger.resumeBreakpoint(breakpointId);
if (temporaryBreakpointId != null && !explicitBreakpointIDs.contains(temporaryBreakpointId) && !temporaryBreakpointId.equals(newTemporaryBreakpointId)) {
// Remove previous temporary breakpoint
backlogDebugger.removeBreakpoint(temporaryBreakpointId);
}
temporaryBreakpointId = newTemporaryBreakpointId;
} else {
// This was the last one
resume();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.github.cameltooling.idea.runner.debugger.stack.CamelMessageInfo in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method checkSuspendedBreakpoints.
private void checkSuspendedBreakpoints() {
while (isConnected()) {
try {
Collection<String> suspendedBreakpointIDs = (Collection<String>) serverConnection.invoke(this.debuggerMBeanObjectName, "getSuspendedBreakpointNodeIds", new Object[] {}, new String[] {});
if (suspendedBreakpointIDs != null && !suspendedBreakpointIDs.isEmpty()) {
// Fire notifications here, we need to display the exchange, stack etc
for (String id : suspendedBreakpointIDs) {
String xml = backlogDebugger.dumpTracedMessagesAsXml(id);
try {
// If the Camel version is 3.15 or later, the exchange properties are included
xml = (String) serverConnection.invoke(this.debuggerMBeanObjectName, "dumpTracedMessagesAsXml", new Object[] { id, true }, new String[] { "java.lang.String", "boolean" });
} catch (Exception e) {
// TODO log this or display warning
}
final String suspendedMessage = xml;
ApplicationManager.getApplication().runReadAction(() -> {
for (MessageReceivedListener listener : messageReceivedListeners) {
try {
CamelBreakpoint breakpoint = breakpoints.get(id);
if (breakpoint == null) {
// find tag and source position based on ID
breakpoint = getCamelBreakpointById(id);
breakpoints.put(id, breakpoint);
}
List<CamelMessageInfo> stack = getStack(id, suspendedMessage);
// We only need stack for the top frame
CamelMessageInfo info = stack.get(0);
info.setStack(stack);
listener.onNewMessageReceived(info);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
} finally {
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.github.cameltooling.idea.runner.debugger.stack.CamelMessageInfo in project camel-idea-plugin by camel-tooling.
the class CamelDebugProcess method init.
public void init() {
camelDebuggerSession.setXDebugSession(this.getSession());
camelDebuggerSession.connect(javaProcessHandler);
camelDebuggerSession.addMessageReceivedListener(new MessageReceivedListener() {
@Override
public void onNewMessageReceived(CamelMessageInfo camelMessageInfo) {
XSourcePosition topPosition = getSession().getTopFramePosition();
if (forceRefresh || topPosition == null || !topPosition.equals(camelMessageInfo.getXSourcePosition())) {
forceRefresh = false;
// List frames
List<CamelStackFrame> stackFrames = new ArrayList<CamelStackFrame>();
for (CamelMessageInfo info : camelMessageInfo.getStack()) {
CamelStackFrame nextFrame = new CamelStackFrame(getSession().getProject(), camelDebuggerSession, info);
stackFrames.add(nextFrame);
}
getSession().positionReached(new CamelSuspendContext(stackFrames.toArray(new CamelStackFrame[stackFrames.size()])));
}
}
});
}
use of com.github.cameltooling.idea.runner.debugger.stack.CamelMessageInfo in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method getStack.
private List<CamelMessageInfo> getStack(String breakpointId, String suspendedMessage) throws Exception {
List<CamelMessageInfo> stack = new ArrayList<>();
// Use new operation to retrieve message history
String messageHistory = (String) serverConnection.invoke(this.debuggerMBeanObjectName, "messageHistoryOnBreakpointAsXml", new Object[] { breakpointId }, new String[] { "java.lang.String" });
InputStream targetStream = new ByteArrayInputStream(messageHistory.getBytes());
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(targetStream);
NodeList historyEntries = document.getElementsByTagName("messageHistoryEntry");
for (int i = 0; i < historyEntries.getLength(); i++) {
Element nextEntry = (Element) historyEntries.item(i);
String routeId = nextEntry.getAttribute("routeId");
String processorId = nextEntry.getAttribute("processorId");
String processor = nextEntry.getAttribute("processor");
CamelBreakpoint breakpoint = breakpoints.get(processorId);
if (breakpoint == null) {
// find tag and source position based on ID
breakpoint = getCamelBreakpointById(processorId);
}
if (breakpoint != null) {
breakpoints.put(processorId, breakpoint);
CamelMessageInfo info = new CamelMessageInfo(suspendedMessage, breakpoint.getXSourcePosition(), breakpoint.getBreakpointTag(), routeId, processorId, processor, null);
stack.add(info);
}
}
Collections.reverse(stack);
return stack;
}
Aggregations