From 92f9a141ed1d027d68a49029fc7cc5e249ad98dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 24 Oct 2010 00:29:16 +0200 Subject: [PATCH] Change inserter logic to wait 60 seconds after each modification. --- .../net/pterodactylus/sone/core/SoneInserter.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 136c1e3..4bb4868 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -104,21 +104,24 @@ public class SoneInserter extends AbstractService { @Override protected void serviceRun() { long modificationCounter = 0; - boolean restartNow = true; + long lastModificationTime = 0; while (!shouldStop()) { - if (!restartNow) { - logger.log(Level.FINEST, "Waiting 60 seconds before checking Sone “" + sone.getName() + "”."); - sleep(60 * 1000); - } - restartNow = false; + /* check every seconds. */ + sleep(1000); + InsertInformation insertInformation = null; synchronized (sone) { - modificationCounter = sone.getModificationCounter(); - if (modificationCounter > 0) { - sone.setTime(System.currentTimeMillis()); - insertInformation = new InsertInformation(sone); + if (sone.getModificationCounter() > modificationCounter) { + 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() }); + if ((System.currentTimeMillis() - lastModificationTime) > (60 * 1000)) { + insertInformation = new InsertInformation(sone); + } } } + if (insertInformation != null) { logger.log(Level.INFO, "Inserting Sone “%s”…", new Object[] { sone.getName() }); @@ -144,9 +147,7 @@ public class SoneInserter extends AbstractService { if (sone.getModificationCounter() == modificationCounter) { logger.log(Level.FINE, "Sone “%s” was not modified further, resetting counter…", new Object[] { sone }); sone.setModificationCounter(0); - } else { - logger.log(Level.FINE, "Sone “%s” was modified since the insert started, starting another insert…", new Object[] { sone }); - restartNow = true; + modificationCounter = 0; } } } -- 2.7.4