X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserter.java;h=05e36008a11ae686b69bf43dcd1b9f783202031d;hb=b29cf0908e6dfd2b55220a3a7e44200f2fe5b19e;hp=c2e0cc6e3e670986655abf617d0531d052978f7b;hpb=6e08990d7764f321237a896f55c517c9cbd98815;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index c2e0cc6..05e3600 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -57,6 +57,9 @@ public class SoneInserter extends AbstractService { /** The logger. */ private static final Logger logger = Logging.getLogger(SoneInserter.class); + /** The insertion delay (in seconds). */ + private static volatile int insertionDelay = 60; + /** The template factory used to create the templates. */ private static final DefaultTemplateFactory templateFactory = new DefaultTemplateFactory(); @@ -95,6 +98,21 @@ public class SoneInserter extends AbstractService { } // + // ACCESSORS + // + + /** + * Changes the insertion delay, i.e. the time the Sone inserter waits after + * it has noticed a Sone modification before it starts the insert. + * + * @param insertionDelay + * The insertion delay (in seconds) + */ + public static void setInsertionDelay(int insertionDelay) { + SoneInserter.insertionDelay = insertionDelay; + } + + // // SERVICE METHODS // @@ -115,9 +133,9 @@ public class SoneInserter extends AbstractService { modificationCounter = sone.getModificationCounter(); lastModificationTime = System.currentTimeMillis(); sone.setTime(lastModificationTime); - logger.log(Level.FINE, "Sone %s has been modified, waiting 60 seconds before inserting.", new Object[] { sone.getName() }); + logger.log(Level.FINE, "Sone %s has been modified, waiting %d seconds before inserting.", new Object[] { sone.getName(), insertionDelay }); } - if ((lastModificationTime > 0) && ((System.currentTimeMillis() - lastModificationTime) > (60 * 1000))) { + if ((lastModificationTime > 0) && ((System.currentTimeMillis() - lastModificationTime) > (insertionDelay * 1000))) { insertInformation = new InsertInformation(sone); } } @@ -128,8 +146,8 @@ public class SoneInserter extends AbstractService { boolean success = false; try { core.setSoneStatus(sone, SoneStatus.inserting); - FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setDocName("Sone-" + sone.getName()).setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html"); - sone.updateUris(finalUri); + FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html"); + sone.updateUris(finalUri.getEdition()); success = true; logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri }); } catch (SoneException se1) {