X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FFcpReplySequence.java;h=ea5d084eefa214b3fae58df7979db10985d146cf;hb=0c86b219616126f1a020e3b6a312156cad7c46ee;hp=2c2dfe1eb3464b0ba597b9d1ecd7681c56982009;hpb=05ad35b5401d5cf36e2436b353d9bc0f81a2f248;p=jFCPlib.git diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/FcpReplySequence.java b/src/main/java/net/pterodactylus/fcp/quelaton/FcpReplySequence.java index 2c2dfe1..ea5d084 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/FcpReplySequence.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/FcpReplySequence.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.Objects; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; @@ -66,6 +67,7 @@ public abstract class FcpReplySequence implements AutoCloseable, FcpListener private final FcpConnection fcpConnection; private final Queue messages = new ConcurrentLinkedQueue<>(); private final AtomicReference identifier = new AtomicReference<>(); + private final AtomicReference connectionFailureReason = new AtomicReference<>(); public FcpReplySequence(ExecutorService executorService, FcpConnection fcpConnection) { this.executorService = MoreExecutors.listeningDecorator(executorService); @@ -84,17 +86,21 @@ public abstract class FcpReplySequence implements AutoCloseable, FcpListener messages.add(fcpMessage); return executorService.submit(() -> { synchronized (syncObject) { - while (!isFinished() || !messages.isEmpty()) { + while ((connectionFailureReason.get() == null) && (!isFinished() || !messages.isEmpty())) { while (messages.peek() != null) { FcpMessage message = messages.poll(); fcpConnection.sendMessage(message); } - if (isFinished()) { + if (isFinished() || (connectionFailureReason.get() != null)) { continue; } syncObject.wait(); } } + Throwable throwable = connectionFailureReason.get(); + if (throwable != null) { + throw new ExecutionException(throwable); + } return getResult(); }); } @@ -136,14 +142,12 @@ public abstract class FcpReplySequence implements AutoCloseable, FcpListener } private void consumeUnknown(FcpMessage fcpMessage) { - if (Objects.equals(fcpMessage.getField("Identifier"), identifier.get())) { - consumeUnknownMessage(fcpMessage); - notifySyncObject(); - } + consumeUnknownMessage(fcpMessage); + notifySyncObject(); } private void consumeClose(Throwable throwable) { - consumeConnectionClosed(throwable); + connectionFailureReason.set(throwable); notifySyncObject(); } @@ -423,6 +427,4 @@ public abstract class FcpReplySequence implements AutoCloseable, FcpListener consumeClose(throwable); } - protected void consumeConnectionClosed(Throwable throwable) { } - }