X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserter.java;h=843e9c4f90ff2c79a9d60dba3ba501cd652696f7;hb=bbdc7a081a8829e1f6483e3da549d1bd85c01537;hp=734847ae7e035b3eac8fe3379863438dbbea98d0;hpb=e89893822ee0b116f964b815b8515acc733ec512;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 734847a..843e9c4 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -99,6 +99,7 @@ public class SoneInserter extends AbstractService { private final FreenetInterface freenetInterface; private final SoneModificationDetector soneModificationDetector; + private final long delay; /** The Sone to insert. */ private volatile Sone sone; @@ -116,12 +117,18 @@ public class SoneInserter extends AbstractService { * The Sone to insert */ public SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone) { + this(core, eventBus, freenetInterface, sone, new SoneModificationDetector(core, sone, insertionDelay), 1000); + } + + @VisibleForTesting + SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone, SoneModificationDetector soneModificationDetector, long delay) { super("Sone Inserter for “" + sone.getName() + "”", false); this.core = core; this.eventBus = eventBus; this.freenetInterface = freenetInterface; this.sone = sone; - this.soneModificationDetector = new SoneModificationDetector(core, sone, insertionDelay); + this.soneModificationDetector = soneModificationDetector; + this.delay = delay; } // @@ -136,7 +143,7 @@ public class SoneInserter extends AbstractService { * @return This Sone inserter */ public SoneInserter setSone(Sone sone) { - checkArgument((this.sone == null) || sone.equals(this.sone), "Sone to insert can not be set to a different Sone"); + checkArgument(sone.equals(this.sone), "Sone to insert can not be set to a different Sone"); this.sone = sone; return this; } @@ -199,7 +206,7 @@ public class SoneInserter extends AbstractService { while (!shouldStop()) { try { /* check every second. */ - sleep(1000); + sleep(delay); if (soneModificationDetector.isEligibleForInsert()) { InsertInformation insertInformation = new InsertInformation(sone);