Use database instead of Core in Sone parser
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloaderImpl.java
index a859106..f3d5068 100644 (file)
@@ -29,6 +29,8 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.inject.Inject;
+
 import net.pterodactylus.sone.core.FreenetInterface.Fetched;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.SoneStatus;
@@ -42,8 +44,6 @@ import freenet.keys.USK;
 import freenet.node.RequestStarter;
 import freenet.support.api.Bucket;
 
-import com.google.common.annotations.VisibleForTesting;
-
 /**
  * The Sone downloader is responsible for download Sones as they are updated.
  *
@@ -74,21 +74,9 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
         *              The core
         * @param freenetInterface
         *              The Freenet interface
-        */
-       public SoneDownloaderImpl(Core core, FreenetInterface freenetInterface) {
-               this(core, freenetInterface, new SoneParser(core));
-       }
-
-       /**
-        * Creates a new Sone downloader.
-        *
-        * @param core
-        *              The core
-        * @param freenetInterface
-        *              The Freenet interface
         * @param soneParser
         */
-       @VisibleForTesting
+       @Inject
        SoneDownloaderImpl(Core core, FreenetInterface freenetInterface, SoneParser soneParser) {
                super("Sone Downloader", false);
                this.core = core;
@@ -124,7 +112,7 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
                                                sone, key, newKnownGood, newSlotToo));
                                if (edition > sone.getLatestEdition()) {
                                        sone.setLatestEdition(edition);
-                                       new Thread(fetchSoneAction(sone),
+                                       new Thread(fetchSoneAsSskAction(sone),
                                                        "Sone Downloader").start();
                                }
                        }
@@ -152,22 +140,8 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
                return (currentTimeMillis() - sone.getTime()) < DAYS.toMillis(7);
        }
 
-       private void fetchSone(Sone sone) {
-               fetchSone(sone, sone.getRequestUri().sskForUSK());
-       }
-
-       /**
-        * Fetches the updated Sone. This method can be used to fetch a Sone from a
-        * specific URI.
-        *
-        * @param sone
-        *              The Sone to fetch
-        * @param soneUri
-        *              The URI to fetch the Sone from
-        */
-       @Override
-       public void fetchSone(Sone sone, FreenetURI soneUri) {
-               fetchSone(sone, soneUri, false);
+       private void fetchSoneAsSsk(Sone sone) {
+               fetchSone(sone, sone.getRequestUri().sskForUSK(), false);
        }
 
        /**
@@ -242,21 +216,21 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
        }
 
        @Override
-       public Runnable fetchSoneWithUriAction(final Sone sone) {
+       public Runnable fetchSoneAsUskAction(final Sone sone) {
                return new Runnable() {
                        @Override
                        public void run() {
-                               fetchSone(sone, sone.getRequestUri());
+                               fetchSone(sone, sone.getRequestUri(), false);
                        }
                };
        }
 
        @Override
-       public Runnable fetchSoneAction(final Sone sone) {
+       public Runnable fetchSoneAsSskAction(final Sone sone) {
                return new Runnable() {
                        @Override
                        public void run() {
-                               fetchSone(sone);
+                               fetchSoneAsSsk(sone);
                        }
                };
        }