Skip to content

Commit

Permalink
make start(), and waitFor.. methods return self
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Apr 10, 2019
1 parent 4360cac commit 07f2511
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/main/java/ch/vorburger/exec/ManagedProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.List;
Expand All @@ -40,7 +39,6 @@
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.ProcessDestroyer;
import org.apache.commons.exec.PumpStreamHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -152,9 +150,10 @@ protected BufferedInputStream buffer(final InputStream inputStream) {
*
* @throws ManagedProcessException if the process could not be started
*/
public synchronized void start() throws ManagedProcessException {
public synchronized ManagedProcess start() throws ManagedProcessException {
startPreparation();
startExecute();
return this;
}

protected synchronized void startPreparation() throws ManagedProcessException {
Expand Down Expand Up @@ -231,7 +230,6 @@ protected synchronized void startExecute() throws ManagedProcessException {
* @param messageInConsole text to wait for in the STDOUT/STDERR of the external process
* @param maxWaitUntilReturning maximum time to wait, in milliseconds, until returning, if
* message wasn't seen
* @return true if message was seen in console; false if message didn't occur and we're
* returning due to max. wait timeout
* @throws ManagedProcessException for problems such as if the process already exited (without
* the message ever appearing in the Console)
Expand Down Expand Up @@ -463,14 +461,15 @@ protected int waitForExitMaxMsWithoutLog(long maxWaitUntilReturning)
* @throws ManagedProcessException see above
*/
@Override
public void waitForExitMaxMsOrDestroy(long maxWaitUntilDestroyTimeout)
public ManagedProcess waitForExitMaxMsOrDestroy(long maxWaitUntilDestroyTimeout)
throws ManagedProcessException {
waitForExitMaxMs(maxWaitUntilDestroyTimeout);
if (isAlive()) {
logger.info("Process didn't exit within max. {}ms, so going to destroy it now: {}",
maxWaitUntilDestroyTimeout, getProcLongName());
destroy();
}
return this;
}

protected void assertWaitForIsValid() throws ManagedProcessException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/vorburger/exec/ManagedProcessState.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ boolean startAndWaitForConsoleMessageMaxMs(String messageInConsole,

int waitForExitMaxMs(long maxWaitUntilReturning) throws ManagedProcessException;

void waitForExitMaxMsOrDestroy(long maxWaitUntilDestroyTimeout)
ManagedProcess waitForExitMaxMsOrDestroy(long maxWaitUntilDestroyTimeout)
throws ManagedProcessException;

String getConsole();
Expand Down

0 comments on commit 07f2511

Please sign in to comment.