Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cardamon committed Mar 6, 2023
1 parent 204b4bd commit 71d6ce7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ch/vorburger/exec/ManagedProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class ManagedProcess implements ManagedProcessState {

private final CommandLine commandLine;
private final Executor executor = new DefaultExecutor();
private final ExecuteWatchdog watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
private final StopCheckExecuteWatchdog watchDog = new StopCheckExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
private final ProcessDestroyer shutdownHookProcessDestroyer = new LoggingShutdownHookProcessDestroyer();
private final Map<String, String> environment;
private final CompositeExecuteResultHandler resultHandler;
Expand Down Expand Up @@ -473,7 +473,7 @@ public ManagedProcess waitForExitMaxMsOrDestroy(long maxWaitUntilDestroyTimeout)
}

protected void assertWaitForIsValid() throws ManagedProcessException {
if (!isAlive() && !resultHandler.hasResult()) {
if (!watchDog.isStopped() && !isAlive() && !resultHandler.hasResult()) {
throw new ManagedProcessException("Asked to waitFor " + getProcLongName()
+ ", but it was never even start()'ed!");
}
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/ch/vorburger/exec/StopCheckExecuteWatchdog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* #%L
* ch.vorburger.exec
* %%
* Copyright (C) 2012 - 2018 Michael Vorburger
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

package ch.vorburger.exec;

import org.apache.commons.exec.ExecuteWatchdog;

public class StopCheckExecuteWatchdog extends ExecuteWatchdog {
private volatile boolean stopped = false;

/**
* Creates a new watchdog with a given timeout.
*
* @param timeout
* the timeout for the process in milliseconds. It must be
* greater than 0 or 'INFINITE_TIMEOUT'
*/
public StopCheckExecuteWatchdog(long timeout) {
super(timeout);
}

/**
* {@inheritDoc}
*/
@Override
public synchronized void stop() {
super.stop();
stopped = true;
}

public boolean isStopped() {
return stopped;
}
}

0 comments on commit 71d6ce7

Please sign in to comment.