From 0f1d38f9011a73939437b6158b8c8bdd1a3dc5eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 19 Oct 2010 09:01:37 +0200 Subject: [PATCH] Set status of Sone when downloading, prepare for fetch result being null. --- src/main/java/net/pterodactylus/sone/core/Core.java | 20 ++++++++++++++++---- .../net/pterodactylus/sone/core/SoneDownloader.java | 20 +++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 7a0ec9c..76881ef 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -399,6 +399,9 @@ public class Core extends AbstractService { try { FreenetURI realRequestUri = new FreenetURI(requestUri).setMetaString(new String[] { "sone.xml" }); FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri); + if (fetchResult == null) { + return; + } Sone parsedSone = soneDownloader.parseSone(null, fetchResult, realRequestUri); if (parsedSone != null) { if (insertUri != null) { @@ -428,10 +431,19 @@ public class Core extends AbstractService { @SuppressWarnings("synthetic-access") public void run() { FreenetURI realRequestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" }); - FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri); - Sone parsedSone = soneDownloader.parseSone(sone, fetchResult, realRequestUri); - if (parsedSone != null) { - addSone(parsedSone); + setSoneStatus(sone, SoneStatus.downloading); + try { + FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri); + if (fetchResult == null) { + /* TODO - mark Sone as bad. */ + return; + } + Sone parsedSone = soneDownloader.parseSone(sone, fetchResult, realRequestUri); + if (parsedSone != null) { + addSone(parsedSone); + } + } finally { + setSoneStatus(sone, SoneStatus.idle); } } }, "Sone Downloader").start(); diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 04fc37f..07a3755 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -24,6 +24,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import net.pterodactylus.sone.core.Core.SoneStatus; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; @@ -111,11 +112,20 @@ public class SoneDownloader extends AbstractService { public void fetchSone(Sone sone) { logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, sone.getRequestUri().setMetaString(new String[] { "sone.xml" }) }); FreenetURI requestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" }); - FetchResult fetchResult = freenetInterface.fetchUri(requestUri); - logger.log(Level.FINEST, "Got %d bytes back.", fetchResult.size()); - Sone parsedSone = parseSone(sone, fetchResult, requestUri); - if (parsedSone != null) { - core.addSone(parsedSone); + core.setSoneStatus(sone, SoneStatus.downloading); + try { + FetchResult fetchResult = freenetInterface.fetchUri(requestUri); + if (fetchResult == null) { + /* TODO - mark Sone as bad. */ + return; + } + logger.log(Level.FINEST, "Got %d bytes back.", fetchResult.size()); + Sone parsedSone = parseSone(sone, fetchResult, requestUri); + if (parsedSone != null) { + core.addSone(parsedSone); + } + } finally { + core.setSoneStatus(sone, SoneStatus.idle); } } -- 2.7.4