mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 00:38:18 +00:00
Handle errors thrown by SynchronousDecoder tasks
Check for errors thrown execution of any SynchronousDecoder tasks, and rethrow any ExecutionExceptions as SynchronousDecoderExceptions.
This commit is contained in:
@@ -4,9 +4,9 @@ import org.apollo.util.ThreadUtil;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A composite decoder that executes each child in parallel.
|
* A composite decoder that executes each child in parallel.
|
||||||
@@ -44,11 +44,21 @@ public final class SynchronousDecoder {
|
|||||||
* Starts this SynchronousDecoder.
|
* Starts this SynchronousDecoder.
|
||||||
*
|
*
|
||||||
* @throws InterruptedException If a decoder is still running after {@link #TIMEOUT} ms.
|
* @throws InterruptedException If a decoder is still running after {@link #TIMEOUT} ms.
|
||||||
|
* @throws SynchronousDecoderException If a decoder failed to complete successfully.
|
||||||
*/
|
*/
|
||||||
public void block() throws InterruptedException {
|
public void block() throws InterruptedException, SynchronousDecoderException {
|
||||||
runnables.forEach(executor::submit);
|
List<Future> futureList = runnables.stream()
|
||||||
executor.shutdown();
|
.map(executor::submit)
|
||||||
executor.awaitTermination(TIMEOUT, TimeUnit.MILLISECONDS);
|
.collect(toList());
|
||||||
}
|
|
||||||
|
|
||||||
|
executor.awaitTermination(TIMEOUT, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
for (Future future : futureList) {
|
||||||
|
try {
|
||||||
|
future.get();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new SynchronousDecoderException("Unable to run all decoder tasks", e.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.apollo.game.fs.decoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception thrown when a {@link SynchronousDecoder} fails to complete successfully.
|
||||||
|
*
|
||||||
|
* @author garyttierney
|
||||||
|
*/
|
||||||
|
public class SynchronousDecoderException extends Exception {
|
||||||
|
public SynchronousDecoderException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SynchronousDecoderException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user