X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloaderImpl.java;h=55c816715fde7cbcc62496889c520cc73ac1c17e;hb=a01e3b29a9dab0f8db0fbbdf718747229300781b;hp=c50c852a476a39e79dc858565a15ab6a8bd7d0d2;hpb=35deb522de06ba7d97160445683375cf87529e8d;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java
index c50c852..55c8167 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 - SoneDownloaderImpl.java - Copyright © 2010â2016 David Roden
+ * Sone - SoneDownloaderImpl.java - Copyright © 2010â2019 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
@@ -45,8 +45,6 @@ import freenet.support.api.Bucket;
/**
* The Sone downloader is responsible for download Sones as they are updated.
- *
- * @author David âBombeâ Roden
*/
public class SoneDownloaderImpl extends AbstractService implements SoneDownloader {
@@ -57,28 +55,19 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
private static final int MAX_PROTOCOL_VERSION = 0;
/** The core. */
- private final Core core;
+ private final UpdatedSoneProcessor updatedSoneProcessor;
private final SoneParser soneParser;
/** The Freenet interface. */
private final FreenetInterface freenetInterface;
/** The sones to update. */
- private final Set sones = new HashSet();
+ private final Set sones = new HashSet<>();
- /**
- * Creates a new Sone downloader.
- *
- * @param core
- * The core
- * @param freenetInterface
- * The Freenet interface
- * @param soneParser
- */
@Inject
- SoneDownloaderImpl(Core core, FreenetInterface freenetInterface, SoneParser soneParser) {
+ SoneDownloaderImpl(UpdatedSoneProcessor updatedSoneProcessor, FreenetInterface freenetInterface, SoneParser soneParser) {
super("Sone Downloader", false);
- this.core = core;
+ this.updatedSoneProcessor = updatedSoneProcessor;
this.freenetInterface = freenetInterface;
this.soneParser = soneParser;
}
@@ -172,7 +161,7 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
if (parsedSone != null) {
if (!fetchOnly) {
parsedSone.setStatus((parsedSone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
- core.updateSone(parsedSone);
+ updatedSoneProcessor.updateSone(parsedSone);
addSone(parsedSone);
}
}
@@ -194,7 +183,7 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
* @return The parsed Sone, or {@code null} if the Sone could not be parsed
*/
private Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
- logger.log(Level.FINEST, String.format("Parsing FetchResult (%d bytes, %s) for %sâ¦", fetchResult.size(), fetchResult.getMimeType(), originalSone));
+ logger.finest(() -> format("Parsing FetchResult (%d bytes, %s) for %sâ¦", fetchResult.size(), fetchResult.getMimeType(), originalSone));
Bucket soneBucket = fetchResult.asBucket();
InputStream soneInputStream = null;
try {
@@ -202,11 +191,12 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
Sone parsedSone = soneParser.parseSone(originalSone,
soneInputStream);
if (parsedSone != null) {
+ logger.finer(() -> format("Sone %s was successfully parsed.", parsedSone));
parsedSone.setLatestEdition(requestUri.getEdition());
}
return parsedSone;
} catch (Exception e1) {
- logger.log(Level.WARNING, String.format("Could not parse Sone from %s!", requestUri), e1);
+ logger.log(Level.WARNING, e1, () -> format("Could not parse Sone from %s!", requestUri));
} finally {
close(soneInputStream);
close(soneBucket);