*/
public class Core extends AbstractService {
+ /**
+ * Enumeration for the possible states of a {@link Sone}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ 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);
/** Sone inserters. */
private final Map<Sone, SoneInserter> soneInserters = new HashMap<Sone, SoneInserter>();
+ /** The Sones’ statuses. */
+ private final Map<Sone, SoneStatus> soneStatuses = new HashMap<Sone, SoneStatus>();
+
/* various caches follow here. */
/** Cache for all known Sones. */
if (!soneCache.containsKey(soneId)) {
Sone sone = new Sone(soneId);
soneCache.put(soneId, sone);
+ setSoneStatus(sone, SoneStatus.idle);
}
return soneCache.get(soneId);
}
}
/**
+ * 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
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;
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);
}
/*