From b584221876cab479852500065558f5780f766b99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 6 Jun 2013 06:34:22 +0200 Subject: [PATCH] Let the real exception propagate. --- .../net/pterodactylus/sonitus/data/Pipeline.java | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/data/Pipeline.java b/src/main/java/net/pterodactylus/sonitus/data/Pipeline.java index c63b272..3fb2810 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Pipeline.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Pipeline.java @@ -317,6 +317,9 @@ public class Pipeline implements Iterable { /** The number of copied bytes. */ private long counter; + /** The exception that was encountered, if any. */ + private Optional ioException = Optional.absent(); + /** * Creates a new connection. * @@ -377,6 +380,17 @@ public class Pipeline implements Iterable { return counter; } + /** + * Returns the I/O exception that was encountered while processing this + * connection. + * + * @return The I/O exception that occured, or {@link Optional#absent()} if no + * exception occured + */ + public Optional ioException() { + return ioException; + } + // // ACTIONS // @@ -396,13 +410,9 @@ public class Pipeline implements Iterable { while (!stopped.get()) { try { final DataPacket dataPacket; - try { - logger.finest(String.format("Getting %d bytes from %s...", 4096, source.name())); - dataPacket = source.get(4096); - logger.finest(String.format("Got %d bytes from %s.", dataPacket.buffer().length, source.name())); - } catch (IOException ioe1) { - throw new IOException(String.format("I/O error while reading from %s.", source.name()), ioe1); - } + logger.finest(String.format("Getting %d bytes from %s...", 4096, source.name())); + dataPacket = source.get(4096); + logger.finest(String.format("Got %d bytes from %s.", dataPacket.buffer().length, source.name())); List> futures = executorService.invokeAll(FluentIterable.from(sinks).transform(new Function>() { @Override @@ -411,13 +421,9 @@ public class Pipeline implements Iterable { @Override public Void call() throws Exception { - try { - logger.finest(String.format("Sending %d bytes to %s.", dataPacket.buffer().length, sink.name())); - sink.process(dataPacket); - logger.finest(String.format("Sent %d bytes to %s.", dataPacket.buffer().length, sink.name())); - } catch (IOException ioe1) { - throw new IOException(String.format("I/O error while writing to %s", sink.name()), ioe1); - } + logger.finest(String.format("Sending %d bytes to %s.", dataPacket.buffer().length, sink.name())); + sink.process(dataPacket); + logger.finest(String.format("Sent %d bytes to %s.", dataPacket.buffer().length, sink.name())); return null; } }; @@ -429,8 +435,7 @@ public class Pipeline implements Iterable { } counter += dataPacket.buffer().length; } catch (IOException e) { - /* TODO */ - e.printStackTrace(); + ioException = Optional.of(e); break; } catch (InterruptedException e) { /* TODO */ -- 2.7.4