boolean isEnabled() { ProcessHandler processHandler = myDescriptor.getProcessHandler(); boolean isTerminating = processHandler != null && processHandler.isProcessTerminating(); boolean isStarting = ExecutorRegistry.getInstance() .isStarting(myEnvironment.getProject(), myExecutor.getId(), myRunner.getRunnerId()); return !isStarting && !isTerminating; }
public static void restartIfActive(@NotNull RunContentDescriptor descriptor) { ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler != null && processHandler.isStartNotified() && !processHandler.isProcessTerminating() && !processHandler.isProcessTerminated()) { restart(descriptor); } }
private static void stop(@Nullable RunContentDescriptor descriptor) { ProcessHandler processHandler = descriptor != null ? descriptor.getProcessHandler() : null; if (processHandler == null) { return; } if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) { ((KillableProcess) processHandler).killProcess(); return; } if (!processHandler.isProcessTerminated()) { if (processHandler.detachIsDefault()) { processHandler.detachProcess(); } else { processHandler.destroyProcess(); } } }
private boolean closeQuery() { final RunContentDescriptor descriptor = getRunContentDescriptorByContent(myContent); if (descriptor == null) { return true; } final ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) { return true; } final boolean destroyProcess; if (processHandler.isSilentlyDestroyOnClose() || Boolean.TRUE.equals( processHandler.getUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE))) { destroyProcess = true; } else { // todo[nik] this is a temporary solution for the following problem: some configurations // should not allow user to choose between 'terminating' and 'detaching' final boolean useDefault = Boolean.TRUE.equals( processHandler.getUserData(ALWAYS_USE_DEFAULT_STOPPING_BEHAVIOUR_KEY)); final TerminateRemoteProcessDialog terminateDialog = new TerminateRemoteProcessDialog( myProject, descriptor.getDisplayName(), processHandler.detachIsDefault(), useDefault); terminateDialog.show(); if (terminateDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return false; destroyProcess = terminateDialog.forceTermination(); } if (destroyProcess) { processHandler.destroyProcess(); } else { processHandler.detachProcess(); } waitForProcess(descriptor); return true; }
@Override public void startRunProfile( @NotNull final RunProfileStarter starter, @NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) { final Project project = environment.getProject(); RunContentDescriptor reuseContent = getContentManager().getReuseContent(environment); if (reuseContent != null) { reuseContent.setExecutionId(environment.getExecutionId()); environment.setContentToReuse(reuseContent); } final Executor executor = environment.getExecutor(); project .getMessageBus() .syncPublisher(EXECUTION_TOPIC) .processStartScheduled(executor.getId(), environment); Runnable startRunnable; startRunnable = () -> { if (project.isDisposed()) { return; } RunProfile profile = environment.getRunProfile(); boolean started = false; try { project .getMessageBus() .syncPublisher(EXECUTION_TOPIC) .processStarting(executor.getId(), environment); final RunContentDescriptor descriptor = starter.execute(state, environment); if (descriptor != null) { final Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity = Trinity.create( descriptor, environment.getRunnerAndConfigurationSettings(), executor); myRunningConfigurations.add(trinity); Disposer.register(descriptor, () -> myRunningConfigurations.remove(trinity)); getContentManager() .showRunContent(executor, descriptor, environment.getContentToReuse()); final ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler != null) { if (!processHandler.isStartNotified()) { processHandler.startNotify(); } project .getMessageBus() .syncPublisher(EXECUTION_TOPIC) .processStarted(executor.getId(), environment, processHandler); started = true; ProcessExecutionListener listener = new ProcessExecutionListener( project, executor.getId(), environment, processHandler, descriptor); processHandler.addProcessListener(listener); // Since we cannot guarantee that the listener is added before process handled is // start notified, // we have to make sure the process termination events are delivered to the clients. // Here we check the current process state and manually deliver events, while // the ProcessExecutionListener guarantees each such event is only delivered once // either by this code, or by the ProcessHandler. boolean terminating = processHandler.isProcessTerminating(); boolean terminated = processHandler.isProcessTerminated(); if (terminating || terminated) { listener.processWillTerminate( new ProcessEvent(processHandler), false /*doesn't matter*/); if (terminated) { //noinspection ConstantConditions int exitCode = processHandler.getExitCode(); listener.processTerminated(new ProcessEvent(processHandler, exitCode)); } } } environment.setContentToReuse(descriptor); } } catch (ProcessCanceledException e) { LOG.info(e); } catch (ExecutionException e) { ExecutionUtil.handleExecutionError(project, executor.getToolWindowId(), profile, e); LOG.info(e); } finally { if (!started) { project .getMessageBus() .syncPublisher(EXECUTION_TOPIC) .processNotStarted(executor.getId(), environment); } } }; if (ApplicationManager.getApplication().isUnitTestMode() && !myForceCompilationInTests) { startRunnable.run(); } else { compileAndRun( () -> TransactionGuard.submitTransaction(project, startRunnable), environment, state, () -> { if (!project.isDisposed()) { project .getMessageBus() .syncPublisher(EXECUTION_TOPIC) .processNotStarted(executor.getId(), environment); } }); } }
private boolean isProcessTerminated() { return myServerProcessHandler.isProcessTerminating() || myServerProcessHandler.isProcessTerminated(); }