Skip to content

Commit

Permalink
Use a (simpler) CompletableFuture-based implementation (#126)
Browse files Browse the repository at this point in the history
See code review discussion on #126 for full details about:

* sketch of a more invasive CompletableFuture patch
* deleted AERHTest
* got tests working
* more specific exception

Co-authored-by: Moses Nakamura <moses.nakamura@airbnb.com>
Co-authored-by: Michael Vorburger <mike@vorburger.ch>
  • Loading branch information
3 people committed Jun 16, 2024
1 parent f841fbd commit c45060e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 369 deletions.
121 changes: 0 additions & 121 deletions src/main/java/ch/vorburger/exec/AtomicExecuteResultHandler.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,35 @@
*/
package ch.vorburger.exec;

import java.util.concurrent.CompletableFuture;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteResultHandler;

/**
* Extends {@link AtomicExecuteResultHandler} with a listener.
*/
class ProcessResultHandler extends AtomicExecuteResultHandler {
private final ManagedProcessListener listener;
class CompletableFutureExecuteResultHandler implements ExecuteResultHandler {

private final CompletableFuture<Integer> asyncResult;

ProcessResultHandler(ManagedProcessListener listener) {
if (listener == null) {
//set internal listener
this.listener = new ManagedProcessListenerInternal();
} else {
this.listener = listener;
}
public CompletableFutureExecuteResultHandler(CompletableFuture<Integer> asyncResult) {
this.asyncResult = asyncResult;
}

/**
* The asynchronous execution completed.
*
* @param exitValue the exit value of the sub-process
*/
@Override
public void onProcessComplete(int exitValue) {
super.onProcessComplete(exitValue);
listener.onProcessComplete(exitValue);
asyncResult.complete(exitValue);
}

/**
* The asynchronous execution failed.
*
* @param e the {@code ExecuteException} containing the root cause
*/
@Override
public void onProcessFailed(ExecuteException processFailedException) {
super.onProcessFailed(processFailedException);
listener.onProcessFailed(processFailedException.getExitValue(), processFailedException);
public void onProcessFailed(ExecuteException e) {
asyncResult.completeExceptionally(e);
}
}
68 changes: 0 additions & 68 deletions src/main/java/ch/vorburger/exec/CompositeExecuteResultHandler.java

This file was deleted.

57 changes: 0 additions & 57 deletions src/main/java/ch/vorburger/exec/LoggingExecuteResultHandler.java

This file was deleted.

Loading

0 comments on commit c45060e

Please sign in to comment.