use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugGlobalPoller method pollForChanges.
/**
* pollForChanges sends a synchronous, hanging query to the server and compares the result to see
* if there are changes from the current state. Explanation of <a
* href="https://en.wikipedia.org/wiki/Push_technology#Long_polling">hanging query (a.k.a. long
* poll)</a>
*
* @param state represents the target debuggee to query
*/
void pollForChanges(@NotNull final CloudDebugProcessState state) {
final Debugger client = CloudDebuggerClient.getShortTimeoutClient(state);
if (client == null) {
if (state.isListenInBackground()) {
// state is supposed to listen, but does not have access to the backend
LOG.warn("CloudDebugProcessState is listening in the background but no debugger client " + "could be retrieved => stop listening");
handleBreakpointQueryError(state, GctBundle.message("clouddebug.background.listener.access.error.message", state.getProject().getName()));
return;
} else {
// We should poll only states that listen in the background, reaching this branch is
// unexpected
LOG.error("Polling changes for a debug state that is not set to listen in the background");
return;
}
}
boolean changed = false;
try {
String oldToken = state.getWaitToken();
queryServerForBreakpoints(state, client);
String responseWaitToken = state.getWaitToken();
if (!Strings.isNullOrEmpty(responseWaitToken)) {
changed = oldToken == null || !responseWaitToken.equals(oldToken);
} else {
changed = !Strings.isNullOrEmpty(oldToken);
}
} catch (SocketTimeoutException ex) {
// noop, this is expected behavior.
} catch (GoogleJsonResponseException ex) {
// a result is available (which will be retrieved via the subsequent query)
if (ex.getStatusCode() != HttpURLConnection.HTTP_CONFLICT) {
handleBreakpointQueryError(state, ex);
}
} catch (IOException ex) {
LOG.warn("exception listing breakpoints", ex);
handleBreakpointQueryError(state, ex);
return;
} catch (Exception ex) {
LOG.error("exception listing breakpoints", ex);
handleBreakpointQueryError(state, ex);
return;
}
if (changed) {
fireBreakpointsChanged(state);
}
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method waitForChanges.
/**
* Package protected for test purposes only.
*/
void waitForChanges() {
if (state == null) {
LOG.error("no state available attempting to checkForChanges");
return;
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.info("no client available attempting to checkForChanges");
return;
}
String tokenToSend = state.getWaitToken();
List<Breakpoint> currentList;
try {
currentList = queryServerForBreakpoints(state, client, tokenToSend);
} catch (SocketTimeoutException ex) {
// Timeout is expected on a hanging get.
return;
} catch (GoogleJsonResponseException ex) {
// we need to requery.
if (ex.getDetails().getCode() == 409) {
try {
currentList = queryServerForBreakpoints(state, client, tokenToSend);
} catch (IOException ioException) {
LOG.warn("exception listing breakpoints", ioException);
return;
}
} else {
LOG.warn("exception listing breakpoints", ex);
return;
}
} catch (IOException ex) {
LOG.warn("exception listing breakpoints", ex);
return;
}
if (!isBackgroundListening()) {
return;
}
// to do pruning.
if (!Strings.isNullOrEmpty(tokenToSend)) {
pruneBreakpointCache(currentList);
fireBreakpointsChanged();
}
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandler method cloneToNewBreakpoints.
/**
* Called when the user "reactivates" an existing snapshot to create a new breakpoint, this clones
* state into a new breakpoint. It is different from "createIdeRepresentationsIfNecessary" in the
* following respects:
*
* <p>
*
* <ul>
* <li>It only operates on final state breakpoints.
* <li>It always clones them into a new IDE breakpoint.
* <li>It does not set "created by server = true", so when control flow comes back into
* register, it will register with the server.
* </ul>
*/
public void cloneToNewBreakpoints(@NotNull final List<Breakpoint> serverBreakpoints) {
for (Breakpoint serverBreakpoint : serverBreakpoints) {
if (!Boolean.TRUE.equals(serverBreakpoint.getIsFinalState())) {
continue;
}
Project currentProject = process.getXDebugSession().getProject();
final XBreakpointManager manager = XDebuggerManager.getInstance(process.getXDebugSession().getProject()).getBreakpointManager();
if (serverBreakpoint.getLocation() == null) {
LOG.warn("attempted to clone a breakpoint without a source location: " + StringUtil.notNullize(serverBreakpoint.getId()));
continue;
}
String path = serverBreakpoint.getLocation().getPath();
if (Strings.isNullOrEmpty(path)) {
continue;
}
final VirtualFile file = fileResolver.getFileFromPath(currentProject, path);
final int line = serverBreakpoint.getLocation().getLine() - 1;
if (file == null) {
LOG.warn("attempted to clone a breakpoint whose file doesn't exist locally: " + StringUtil.notNullize(serverBreakpoint.getLocation().getPath()));
continue;
}
final XLineBreakpoint existing = manager.findBreakpointAtLine(CloudLineBreakpointType.getInstance(), file, line);
if (existing != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
manager.removeBreakpoint(existing);
}
});
}
final CloudLineBreakpointProperties properties = new CloudLineBreakpointProperties();
final Breakpoint finalserverBreakpoint = serverBreakpoint;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (finalserverBreakpoint.getExpressions() != null && finalserverBreakpoint.getExpressions().size() > 0) {
properties.setWatchExpressions(finalserverBreakpoint.getExpressions().toArray(new String[finalserverBreakpoint.getExpressions().size()]));
}
XLineBreakpoint<CloudLineBreakpointProperties> newxIdeBreakpoint = manager.addLineBreakpoint(CloudLineBreakpointType.getInstance(), file.getUrl(), line, properties);
// Condition, watches.
if (!Strings.isNullOrEmpty(finalserverBreakpoint.getCondition())) {
newxIdeBreakpoint.setCondition(finalserverBreakpoint.getCondition());
}
}
});
}
UsageTrackerProvider.getInstance().trackEvent(GctTracking.CLOUD_DEBUGGER_CLONE_BREAKPOINTS).ping();
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugGlobalPollerTest method setupCloudDebuggerBackendMockWithException.
private void setupCloudDebuggerBackendMockWithException(String userEmail, IOException e) throws IOException {
Breakpoints breakpoints = mock(Breakpoints.class);
when(breakpoints.list(anyString())).thenThrow(e);
Debuggees debuggees = mock(Debuggees.class);
when(debuggees.breakpoints()).thenReturn(breakpoints);
Debugger debugger = mock(Debugger.class);
when(debugger.debuggees()).thenReturn(debuggees);
CloudDebuggerClient.setClient(userEmail + CloudDebuggerClient.SHORT_CONNECTION_TIMEOUT_MS, debugger);
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessary.
public void testCreateIdeRepresentationsIfNecessary() {
List<Breakpoint> breakpoints = ImmutableList.of(new Breakpoint().setId("expected_path").setLocation(new SourceLocation().setLine(1).setPath("app/mod/src/main/java/b/f/pkg/Class.java")), new Breakpoint().setId("unexpected_path").setLocation(new SourceLocation().setLine(2).setPath("app/mod/src/m/j/a/b/c/Class.java")), new Breakpoint().setId("unexpected_path_2").setLocation(new SourceLocation().setLine(3).setPath("b/f/pkg/Class.java")));
when(breakpointManager.findBreakpointAtLine(isA(XLineBreakpointType.class), isA(VirtualFile.class), anyInt())).thenReturn(null);
XLineBreakpoint mockLineBreakpoint = mock(XLineBreakpoint.class);
when(breakpointManager.addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(CloudLineBreakpointProperties.class))).thenReturn(mockLineBreakpoint);
when(mockLineBreakpoint.getProperties()).thenReturn(new CloudLineBreakpointProperties());
VirtualFile projectDir = mock(VirtualFile.class);
when(projectDir.getPath()).thenReturn("/project/dir");
project.setBaseDir(projectDir);
VirtualFile classFile = mock(VirtualFile.class);
when(classFile.getUrl()).thenReturn("file:///URL");
when(fileResolver.getFileFromPath(isA(Project.class), eq("app/mod/src/main/java/b/f/pkg/Class.java"))).thenReturn(classFile);
handler.createIdeRepresentationsIfNecessary(breakpoints);
verify(breakpointManager, times(1)).addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(XBreakpointProperties.class));
}
Aggregations