X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserter.java;h=9f45e2e1610433acd9e8c85669fc5ad4f6777d21;hp=eb74dc0132b5567d2fa5745b537ec195af34fc73;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=43a21f859e9fec31096c1540148bdd44a8e3702f diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index eb74dc0..9f45e2e 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -27,11 +27,11 @@ import java.util.Map; 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.PostReply; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.Sone.SoneStatus; import net.pterodactylus.sone.freenet.StringBucket; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.util.collection.ListBuilder; @@ -190,6 +190,7 @@ public class SoneInserter extends AbstractService { @Override protected void serviceRun() { long lastModificationTime = 0; + String lastInsertedFingerprint = lastInsertFingerprint; String lastFingerprint = ""; while (!shouldStop()) { try { /* check every seconds. */ @@ -199,7 +200,7 @@ public class SoneInserter extends AbstractService { if (core.isLocked(sone)) { /* trigger redetection when the Sone is unlocked. */ synchronized (sone) { - modified = !sone.getFingerprint().equals(lastInsertFingerprint); + modified = !sone.getFingerprint().equals(lastInsertedFingerprint); } lastFingerprint = ""; lastModificationTime = 0; @@ -210,29 +211,29 @@ public class SoneInserter extends AbstractService { synchronized (sone) { String fingerprint = sone.getFingerprint(); if (!fingerprint.equals(lastFingerprint)) { - if (fingerprint.equals(lastInsertFingerprint)) { + if (fingerprint.equals(lastInsertedFingerprint)) { modified = false; lastModificationTime = 0; - logger.log(Level.FINE, "Sone %s has been reverted to last insert state.", sone); + logger.log(Level.FINE, String.format("Sone %s has been reverted to last insert state.", sone)); } else { lastModificationTime = System.currentTimeMillis(); modified = true; - logger.log(Level.FINE, "Sone %s has been modified, waiting %d seconds before inserting.", new Object[] { sone.getName(), insertionDelay }); + logger.log(Level.FINE, String.format("Sone %s has been modified, waiting %d seconds before inserting.", sone.getName(), insertionDelay)); } lastFingerprint = fingerprint; } if (modified && (lastModificationTime > 0) && ((System.currentTimeMillis() - lastModificationTime) > (insertionDelay * 1000))) { - lastInsertFingerprint = fingerprint; + lastInsertedFingerprint = fingerprint; insertInformation = new InsertInformation(sone); } } if (insertInformation != null) { - logger.log(Level.INFO, "Inserting Sone “%s”…", new Object[] { sone.getName() }); + logger.log(Level.INFO, String.format("Inserting Sone “%s”…", sone.getName())); boolean success = false; try { - core.setSoneStatus(sone, SoneStatus.inserting); + sone.setStatus(SoneStatus.inserting); long insertTime = System.currentTimeMillis(); insertInformation.setTime(insertTime); soneInsertListenerManager.fireInsertStarted(); @@ -247,12 +248,12 @@ public class SoneInserter extends AbstractService { sone.setLatestEdition(finalUri.getEdition()); core.touchConfiguration(); success = true; - logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri }); + logger.log(Level.INFO, String.format("Inserted Sone “%s” at %s.", sone.getName(), finalUri)); } catch (SoneException se1) { soneInsertListenerManager.fireInsertAborted(se1); - logger.log(Level.WARNING, "Could not insert Sone “" + sone.getName() + "”!", se1); + logger.log(Level.WARNING, String.format("Could not insert Sone “%s”!", sone.getName()), se1); } finally { - core.setSoneStatus(sone, SoneStatus.idle); + sone.setStatus(SoneStatus.idle); } /* @@ -261,9 +262,11 @@ public class SoneInserter extends AbstractService { */ if (success) { synchronized (sone) { - if (lastInsertFingerprint.equals(sone.getFingerprint())) { - logger.log(Level.FINE, "Sone “%s” was not modified further, resetting counter…", new Object[] { sone }); + if (lastInsertedFingerprint.equals(sone.getFingerprint())) { + logger.log(Level.FINE, String.format("Sone “%s” was not modified further, resetting counter…", sone)); lastModificationTime = 0; + lastInsertFingerprint = lastInsertedFingerprint; + core.touchConfiguration(); modified = false; } } @@ -373,7 +376,7 @@ public class SoneInserter extends AbstractService { templateInputStreamReader = new InputStreamReader(getClass().getResourceAsStream(templateName), utf8Charset); template = TemplateParser.parse(templateInputStreamReader); } catch (TemplateException te1) { - logger.log(Level.SEVERE, "Could not parse template “" + templateName + "”!", te1); + logger.log(Level.SEVERE, String.format("Could not parse template “%s”!", templateName), te1); return null; } finally { Closer.close(templateInputStreamReader); @@ -391,7 +394,7 @@ public class SoneInserter extends AbstractService { bucket = new StringBucket(writer.toString(), utf8Charset); return new ManifestElement(name, bucket, contentType, bucket.size()); } catch (TemplateException te1) { - logger.log(Level.SEVERE, "Could not render template “" + templateName + "”!", te1); + logger.log(Level.SEVERE, String.format("Could not render template “%s”!", templateName), te1); return null; } finally { Closer.close(writer);