[java] explicit destroying of process proxy instances

This commit is contained in:
Roman Shevchenko
2016-10-27 10:36:47 +02:00
parent b52c2380cd
commit 2af7d092bb
3 changed files with 36 additions and 20 deletions
@@ -72,7 +72,7 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner {
}
@Override
protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult;
@@ -80,11 +80,25 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner {
if (state instanceof JavaCommandLine) {
final JavaParameters parameters = ((JavaCommandLine)state).getJavaParameters();
patch(parameters, env.getRunnerSettings(), env.getRunProfile(), true);
final ProcessProxy proxy = ProcessProxyFactory.getInstance().createCommandLineProxy((JavaCommandLine)state);
ProcessProxy proxy = ProcessProxyFactory.getInstance().createCommandLineProxy((JavaCommandLine)state);
executionResult = state.execute(env.getExecutor(), this);
if (proxy != null && executionResult != null) {
proxy.attach(executionResult.getProcessHandler());
if (proxy != null) {
ProcessHandler handler = executionResult != null ? executionResult.getProcessHandler() : null;
if (handler != null) {
proxy.attach(handler);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
proxy.destroy();
}
});
}
else {
proxy.destroy();
}
}
if (state instanceof JavaCommandLineState && !((JavaCommandLineState)state).shouldAddJavaProgramRunnerActions()) {
shouldAddDefaultActions = false;
}
@@ -248,4 +262,4 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner {
public static ProgramRunner getInstance() {
return RunnerRegistry.getInstance().findRunnerById(DEFAULT_JAVA_RUNNER_ID);
}
}
}
@@ -17,6 +17,7 @@ package com.intellij.execution.runners;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -73,17 +74,7 @@ class ProcessProxyImpl implements ProcessProxy {
}
@Override
@SuppressWarnings("FinalizeDeclaration")
protected synchronized void finalize() throws Throwable {
if (myWriter != null) {
myWriter.close();
}
ourUsedSockets[myPortNumber - SOCKET_NUMBER_START] = false;
super.finalize();
}
@Override
public void attach(final ProcessHandler processHandler) {
public void attach(@NotNull ProcessHandler processHandler) {
processHandler.putUserData(KEY, this);
}
@@ -113,4 +104,12 @@ class ProcessProxyImpl implements ProcessProxy {
public void sendStop() {
writeLine("STOP");
}
@Override
public synchronized void destroy() {
if (myWriter != null) {
myWriter.close();
}
ourUsedSockets[myPortNumber - SOCKET_NUMBER_START] = false;
}
}