[debugger] allow clients to specify poll timeout

This commit is contained in:
Daniil Ovchinnikov
2016-06-05 23:51:26 +03:00
parent f60d30f4b9
commit 35fc56af81
4 changed files with 44 additions and 14 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,8 @@ import org.jetbrains.annotations.Nullable;
*/
public interface DebugEnvironment {
int LOCAL_START_TIMEOUT = 30000;
@Nullable
ExecutionResult createExecutionResult() throws ExecutionException;
@@ -38,7 +40,17 @@ public interface DebugEnvironment {
RemoteConnection getRemoteConnection();
boolean isPollConnection();
/**
* @deprecated use {@link #getPollTimeout()}
*/
default boolean isPollConnection() {
return false;
}
default long getPollTimeout() {
//noinspection deprecation
return isPollConnection() ? LOCAL_START_TIMEOUT : 0;
}
String getSessionName();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,16 +27,23 @@ import org.jetbrains.annotations.NotNull;
public class DefaultDebugEnvironment implements DebugEnvironment {
private final GlobalSearchScope mySearchScope;
private final RemoteConnection myRemoteConnection;
private final boolean myPollConnection;
private final long myPollTimeout;
private final ExecutionEnvironment environment;
private final RunProfileState state;
private final boolean myNeedParametersSet;
public DefaultDebugEnvironment(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state, RemoteConnection remoteConnection, boolean pollConnection) {
this(environment, state, remoteConnection, pollConnection ? LOCAL_START_TIMEOUT : 0);
}
public DefaultDebugEnvironment(@NotNull ExecutionEnvironment environment,
@NotNull RunProfileState state,
RemoteConnection remoteConnection,
long pollTimeout) {
this.environment = environment;
this.state = state;
myRemoteConnection = remoteConnection;
myPollConnection = pollConnection;
myPollTimeout = pollTimeout;
mySearchScope = SearchScopeProvider.createSearchScope(environment.getProject(), environment.getRunProfile());
myNeedParametersSet = remoteConnection.isServerMode() && remoteConnection.isUseSockets() && "0".equals(remoteConnection.getAddress());
@@ -72,8 +79,8 @@ public class DefaultDebugEnvironment implements DebugEnvironment {
}
@Override
public boolean isPollConnection() {
return myPollConnection;
public long getPollTimeout() {
return myPollTimeout;
}
@Override
@@ -129,7 +129,6 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
private final SuspendManagerImpl mySuspendManager = new SuspendManagerImpl(this);
protected CompoundPositionManager myPositionManager = null;
private final DebuggerManagerThreadImpl myDebuggerManagerThread;
private static final int LOCAL_START_TIMEOUT = 30000;
private final Semaphore myWaitFor = new Semaphore();
private final AtomicBoolean myIsFailed = new AtomicBoolean(false);
@@ -1839,7 +1838,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
myState.set(State.INITIAL);
myConnection = environment.getRemoteConnection();
getManagerThread().restartIfNeeded();
createVirtualMachine(environment.getSessionName(), environment.isPollConnection());
createVirtualMachine(environment);
});
}
});
@@ -1856,7 +1855,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
myConnection = environment.getRemoteConnection();
createVirtualMachine(environment.getSessionName(), environment.isPollConnection());
createVirtualMachine(environment);
ExecutionResult executionResult;
try {
@@ -1919,7 +1918,9 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
}
}
private void createVirtualMachine(final String sessionName, final boolean pollConnection) {
private void createVirtualMachine(final DebugEnvironment environment) {
final String sessionName = environment.getSessionName();
final long pollTimeout = environment.getPollTimeout();
final Semaphore semaphore = new Semaphore();
semaphore.down();
@@ -1943,13 +1944,13 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
try {
final long time = System.currentTimeMillis();
while (System.currentTimeMillis() - time < LOCAL_START_TIMEOUT) {
do {
try {
vm = createVirtualMachineInt();
break;
}
catch (final ExecutionException e) {
if (pollConnection && !myConnection.isServerMode() && e.getCause() instanceof IOException) {
if (pollTimeout > 0 && !myConnection.isServerMode() && e.getCause() instanceof IOException) {
synchronized (this) {
try {
wait(500);
@@ -1973,6 +1974,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
}
}
}
while (System.currentTimeMillis() - time < pollTimeout);
}
finally {
semaphore.up();
@@ -100,7 +100,16 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner<GenericDeb
@NotNull ExecutionEnvironment env,
RemoteConnection connection,
boolean pollConnection) throws ExecutionException {
DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollConnection);
return attachVirtualMachine(state, env, connection, pollConnection ? DebugEnvironment.LOCAL_START_TIMEOUT : 0);
}
@Nullable
protected RunContentDescriptor attachVirtualMachine(RunProfileState state,
@NotNull ExecutionEnvironment env,
RemoteConnection connection,
long pollTimeout) throws ExecutionException {
DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollTimeout);
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
if (debuggerSession == null) {
return null;