From: David ‘Bombe’ Roden Date: Thu, 11 Apr 2013 05:28:25 +0000 (+0200) Subject: Send events from the DCC receiver. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=907f0d44b3905788e3984f4d19d79a444eafe9f2;p=xudocci.git Send events from the DCC receiver. --- diff --git a/src/main/java/net/pterodactylus/irc/DccReceiver.java b/src/main/java/net/pterodactylus/irc/DccReceiver.java index e58fed3..56a3853 100644 --- a/src/main/java/net/pterodactylus/irc/DccReceiver.java +++ b/src/main/java/net/pterodactylus/irc/DccReceiver.java @@ -26,9 +26,12 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; +import net.pterodactylus.irc.event.DccDownloadFailed; +import net.pterodactylus.irc.event.DccDownloadFinished; import net.pterodactylus.irc.event.DccSendReceived; import net.pterodactylus.xdcc.util.io.BandwidthCountingInputStream; +import com.google.common.eventbus.EventBus; import com.google.common.io.Closeables; import com.google.common.util.concurrent.AbstractExecutionThreadService; @@ -42,6 +45,9 @@ public class DccReceiver extends AbstractExecutionThreadService { /** The logger. */ private static final Logger logger = Logger.getLogger(DccReceiver.class.getName()); + /** The event bus. */ + private final EventBus eventBus; + /** The address to connect to. */ private final InetAddress inetAddress; @@ -78,7 +84,8 @@ public class DccReceiver extends AbstractExecutionThreadService { * @param outputStream * The output stream to write the file to */ - public DccReceiver(InetAddress inetAddress, int port, String filename, long size, OutputStream outputStream) { + public DccReceiver(EventBus eventBus, InetAddress inetAddress, int port, String filename, long size, OutputStream outputStream) { + this.eventBus = eventBus; this.inetAddress = inetAddress; this.port = port; this.filename = filename; @@ -160,8 +167,10 @@ public class DccReceiver extends AbstractExecutionThreadService { progress += r; } outputStream.flush(); + eventBus.post(new DccDownloadFinished(this)); } catch (IOException ioe1) { logger.log(Level.WARNING, "I/O error while receiving DCC!", ioe1); + eventBus.post(new DccDownloadFailed(this, ioe1)); } finally { Closeables.close(inputStream, true); socket.close(); diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index d253148..36768a4 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -328,7 +328,7 @@ public class Core extends AbstractIdleService { logger.info(String.format("Starting download of %s.", dccSendReceived.filename())); try { OutputStream fileOutputStream = new FileOutputStream(new File("/home/bombe/Temp", dccSendReceived.filename())); - DccReceiver dccReceiver = new DccReceiver(dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream); + DccReceiver dccReceiver = new DccReceiver(eventBus, dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream); dccReceivers.add(dccReceiver); dccReceiver.start(); } catch (FileNotFoundException fnfe1) {