X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloaderImpl.java;h=c50c852a476a39e79dc858565a15ab6a8bd7d0d2;hp=3ae137147b39cbc1d51db48c66659b0e51ff6675;hb=35deb522de06ba7d97160445683375cf87529e8d;hpb=43740d6a1dfc686ab54d0aebd4a5b1bce75b9ed6 diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java index 3ae1371..c50c852 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java @@ -1,5 +1,5 @@ /* - * Sone - SoneDownloader.java - Copyright © 2010–2013 David Roden + * Sone - SoneDownloaderImpl.java - Copyright © 2010–2016 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ package net.pterodactylus.sone.core; +import static freenet.support.io.Closer.close; import static java.lang.String.format; import static java.lang.System.currentTimeMillis; import static java.util.concurrent.TimeUnit.DAYS; @@ -28,10 +29,10 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import net.pterodactylus.sone.core.FreenetInterface.Fetched; +import javax.inject.Inject; + import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; -import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.service.AbstractService; import freenet.client.FetchResult; @@ -41,9 +42,6 @@ import freenet.keys.FreenetURI; import freenet.keys.USK; import freenet.node.RequestStarter; import freenet.support.api.Bucket; -import com.db4o.ObjectContainer; - -import com.google.common.annotations.VisibleForTesting; /** * The Sone downloader is responsible for download Sones as they are updated. @@ -53,7 +51,7 @@ import com.google.common.annotations.VisibleForTesting; public class SoneDownloaderImpl extends AbstractService implements SoneDownloader { /** The logger. */ - private static final Logger logger = getLogger("Sone.Downloader"); + private static final Logger logger = getLogger(SoneDownloaderImpl.class.getName()); /** The maximum protocol version. */ private static final int MAX_PROTOCOL_VERSION = 0; @@ -75,21 +73,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; @@ -117,7 +103,6 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade @Override @SuppressWarnings("synthetic-access") public void onFoundEdition(long edition, USK key, - ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { @@ -126,7 +111,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(); } } @@ -154,22 +139,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); } /** @@ -237,28 +208,28 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade } catch (Exception e1) { logger.log(Level.WARNING, String.format("Could not parse Sone from %s!", requestUri), e1); } finally { - Closer.close(soneInputStream); - soneBucket.free(); + close(soneInputStream); + close(soneBucket); } return null; } @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); } }; }