Skip to content

Commit

Permalink
sketch of a more invasive CompletableFuture patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mosesn committed May 15, 2023
1 parent d9cc4ce commit 1d99b98
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 294 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,33 @@
*/
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;
}

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

@Override
public void onProcessFailed(ExecuteException processFailedException) {
super.onProcessFailed(processFailedException);
listener.onProcessFailed(processFailedException.getExitValue(), processFailedException);
/**
* The asynchronous execution failed.
*
* @param e the {@code ExecuteException} containing the root cause
*/
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 1d99b98

Please sign in to comment.