diff --git a/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoder.java b/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoder.java index acc88f53..d46c01da 100644 --- a/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoder.java +++ b/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoder.java @@ -4,9 +4,9 @@ import org.apollo.util.ThreadUtil; import java.util.Arrays; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; + +import static java.util.stream.Collectors.toList; /** * A composite decoder that executes each child in parallel. @@ -44,11 +44,22 @@ public final class SynchronousDecoder { * Starts this SynchronousDecoder. * * @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 { - runnables.forEach(executor::submit); + public void block() throws InterruptedException, SynchronousDecoderException { + List futureList = runnables.stream() + .map(executor::submit) + .collect(toList()); + executor.shutdown(); 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()); + } + } + } } \ No newline at end of file diff --git a/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoderException.java b/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoderException.java new file mode 100644 index 00000000..96a63264 --- /dev/null +++ b/game/src/main/org/apollo/game/fs/decoder/SynchronousDecoderException.java @@ -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); + } +}