Add status for Sones.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index a6cbc82..7a0ec9c 100644 (file)
@@ -52,6 +52,23 @@ import freenet.keys.FreenetURI;
  */
 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);
 
@@ -70,6 +87,9 @@ public class Core extends AbstractService {
        /** 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. */
@@ -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