From: David ‘Bombe’ Roden Date: Tue, 19 Oct 2010 07:01:00 +0000 (+0200) Subject: Add status for Sones. X-Git-Tag: 0.1-RC1~202 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4d0705ef1773ee51717911bf5a1bc8f6ca71d339;p=Sone.git Add status for Sones. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index a6cbc82..7a0ec9c 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -52,6 +52,23 @@ import freenet.keys.FreenetURI; */ public class Core extends AbstractService { + /** + * Enumeration for the possible states of a {@link Sone}. + * + * @author David ‘Bombe’ Roden + */ + public enum SoneStatus { + + /** The Sone is idle, i.e. not being downloaded or inserted. */ + idle, + + /** The Sone is currently being inserted. */ + inserting, + + /** The Sone is currently being downloaded. */ + downloading, + } + /** The logger. */ private static final Logger logger = Logging.getLogger(Core.class); @@ -70,6 +87,9 @@ public class Core extends AbstractService { /** Sone inserters. */ private final Map soneInserters = new HashMap(); + /** The Sones’ statuses. */ + private final Map soneStatuses = new HashMap(); + /* various caches follow here. */ /** Cache for all known Sones. */ @@ -139,6 +159,7 @@ public class Core extends AbstractService { if (!soneCache.containsKey(soneId)) { Sone sone = new Sone(soneId); soneCache.put(soneId, sone); + setSoneStatus(sone, SoneStatus.idle); } return soneCache.get(soneId); } @@ -169,6 +190,29 @@ public class Core extends AbstractService { } /** + * Returns the status of the given Sone. + * + * @param sone + * The Sone to get the status for + * @return The status of the Sone + */ + public SoneStatus getSoneStatus(Sone sone) { + return soneStatuses.get(sone); + } + + /** + * Sets the status of the Sone. + * + * @param sone + * The Sone to set the status for + * @param soneStatus + * The status of the Sone + */ + public void setSoneStatus(Sone sone, SoneStatus soneStatus) { + soneStatuses.put(sone, soneStatus); + } + + /** * Creates a new post and adds it to the given Sone. * * @param sone diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index ba6f437..839c216 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; +import net.pterodactylus.sone.core.Core.SoneStatus; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.StringBucket; import net.pterodactylus.util.filter.Filter; @@ -117,12 +118,15 @@ public class SoneInserter extends AbstractService { boolean success = false; try { + core.setSoneStatus(sone, SoneStatus.inserting); FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setDocName("Sone-" + sone.getName()).setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html"); sone.updateUris(finalUri); success = true; logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri }); } catch (SoneException se1) { logger.log(Level.WARNING, "Could not insert Sone “" + sone.getName() + "”!", se1); + } finally { + core.setSoneStatus(sone, SoneStatus.idle); } /*