Use fetch action instead of custom Runnable.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / FreenetInterface.java
index abac508..5dd8fbf 100644 (file)
@@ -35,8 +35,11 @@ import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.util.logging.Logging;
 
 import com.db4o.ObjectContainer;
+
+import com.google.common.base.Function;
 import com.google.common.eventbus.EventBus;
 import com.google.inject.Inject;
+import com.google.inject.Singleton;
 
 import freenet.client.ClientMetadata;
 import freenet.client.FetchException;
@@ -64,6 +67,7 @@ import freenet.support.io.ArrayBucket;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
+@Singleton
 public class FreenetInterface {
 
        /** The logger. */
@@ -198,13 +202,7 @@ public class FreenetInterface {
                                        logger.log(Level.FINE, String.format("Found USK update for Sone “%s” at %s, new known good: %s, new slot too: %s.", sone, key, newKnownGood, newSlotToo));
                                        if (edition > sone.getLatestEdition()) {
                                                sone.setLatestEdition(edition);
-                                               new Thread(new Runnable() {
-
-                                                       @Override
-                                                       public void run() {
-                                                               soneDownloader.fetchSone(sone);
-                                                       }
-                                               }, "Sone Downloader").start();
+                                               new Thread(soneDownloader.fetchSoneAction(sone), "Sone Downloader").start();
                                        }
                                }
 
@@ -494,4 +492,13 @@ public class FreenetInterface {
 
        }
 
+       public class InsertTokenSupplier implements Function<Image, InsertToken> {
+
+               @Override
+               public InsertToken apply(Image image) {
+                       return new InsertToken(image);
+               }
+
+       }
+
 }