-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BXC-4780 - Handling hung kakadu processes (#28)
* Allow commands to timeout. Read output and error in parallel to waiting, otherwise it can deadlock. Add specialized command exceptions and adjust error handling * Add special case handling of images that are grayscale alpha but contain rgb data, which was causing kakadu to hang forever * Trim imageType * fix tests * Move trim --------- Co-authored-by: krwong <krwong@email.unc.edu>
- Loading branch information
Showing
9 changed files
with
211 additions
and
52 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/JP2ImageConverter/errors/CommandException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package JP2ImageConverter.errors; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author bbpennel | ||
*/ | ||
public class CommandException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
private final int exitCode; | ||
private final String output; | ||
private final List<String> command; | ||
|
||
public CommandException(String message, List<String> command, String output, Throwable cause) { | ||
this(message, command, output, -1, cause); | ||
} | ||
|
||
public CommandException(String message, List<String> command, String output, int exitCode) { | ||
this(message, command, output, exitCode, null); | ||
} | ||
|
||
public CommandException(String message, List<String> command, String output, int exitCode, Throwable cause) { | ||
super(message, cause); | ||
this.exitCode = exitCode; | ||
this.output = output; | ||
this.command = command; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
var message = super.getMessage() | ||
+ System.lineSeparator() + "Command: " + String.join(" ", getCommand()); | ||
if (getExitCode() != -1) { | ||
message += System.lineSeparator() + " with exit code: " + getExitCode(); | ||
} | ||
if (getOutput() != null) { | ||
message += System.lineSeparator() + " with output: " + getOutput(); | ||
} | ||
return message; | ||
} | ||
|
||
public int getExitCode() { | ||
return exitCode; | ||
} | ||
|
||
public String getOutput() { | ||
return output; | ||
} | ||
|
||
public List<String> getCommand() { | ||
return command; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/JP2ImageConverter/errors/CommandTimeoutException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package JP2ImageConverter.errors; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author bbpennel | ||
*/ | ||
public class CommandTimeoutException extends CommandException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public CommandTimeoutException(String message, List<String> command, String output) { | ||
super(message, command, output, -1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.