From f083ad3957357d2f861e87128ee355e842c70762 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Jul 2011 09:02:18 +0200 Subject: [PATCH] Fire Sone insert events in Sone inserter. --- .../net/pterodactylus/sone/core/SoneInserter.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index aa2062c..d4f53c1 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -83,6 +83,9 @@ public class SoneInserter extends AbstractService { /** The Sone to insert. */ private final Sone sone; + /** The insert listener manager. */ + private SoneInsertListenerManager soneInsertListenerManager; + /** Whether a modification has been detected. */ private volatile boolean modified = false; @@ -104,6 +107,31 @@ public class SoneInserter extends AbstractService { this.core = core; this.freenetInterface = freenetInterface; this.sone = sone; + this.soneInsertListenerManager = new SoneInsertListenerManager(sone); + } + + // + // LISTENER MANAGEMENT + // + + /** + * Adds a listener for Sone insert events. + * + * @param soneInsertListener + * The Sone insert listener + */ + public void addSoneInsertListener(SoneInsertListener soneInsertListener) { + soneInsertListenerManager.addListener(soneInsertListener); + } + + /** + * Removes a listener for Sone insert events. + * + * @param soneInsertListener + * The Sone insert listener + */ + public void removeSoneInsertListener(SoneInsertListener soneInsertListener) { + soneInsertListenerManager.removeListener(soneInsertListener); } // @@ -206,7 +234,9 @@ public class SoneInserter extends AbstractService { core.setSoneStatus(sone, SoneStatus.inserting); long insertTime = System.currentTimeMillis(); insertInformation.setTime(insertTime); + soneInsertListenerManager.fireInsertStarted(); FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri(), insertInformation.generateManifestEntries(), "index.html"); + soneInsertListenerManager.fireInsertFinished(System.currentTimeMillis() - insertTime); /* at this point we might already be stopped. */ if (shouldStop()) { /* if so, bail out, don’t change anything. */ @@ -218,6 +248,7 @@ public class SoneInserter extends AbstractService { success = true; logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri }); } catch (SoneException se1) { + soneInsertListenerManager.fireInsertAborted(se1); logger.log(Level.WARNING, "Could not insert Sone “" + sone.getName() + "”!", se1); } finally { core.setSoneStatus(sone, SoneStatus.idle); -- 2.7.4