From: David ‘Bombe’ Roden Date: Fri, 1 Aug 2014 00:19:06 +0000 (+0200) Subject: Use a supplier to generate insert tokens for images. X-Git-Tag: 0.9-rc1^2~3^2~185 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=916a38a274bcddc755c06fe21bdbc41d494b1825;p=Sone.git Use a supplier to generate insert tokens for images. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index b6a0a90..d0fa28a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -220,7 +220,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, this.freenetInterface = freenetInterface; this.identityManager = identityManager; this.soneDownloader = new SoneDownloader(this, freenetInterface); - this.imageInserter = new ImageInserter(freenetInterface); + this.imageInserter = new ImageInserter(freenetInterface, freenetInterface.new InsertTokenSupplier()); this.updateChecker = new UpdateChecker(eventBus, freenetInterface); this.webOfTrustUpdater = webOfTrustUpdater; this.eventBus = eventBus; diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index abac508..9ccf5fc 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -35,6 +35,8 @@ import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.util.logging.Logging; import com.db4o.ObjectContainer; + +import com.google.common.base.Function; import com.google.common.eventbus.EventBus; import com.google.inject.Inject; @@ -494,4 +496,13 @@ public class FreenetInterface { } + public class InsertTokenSupplier implements Function { + + @Override + public InsertToken apply(Image image) { + return new InsertToken(image); + } + + } + } diff --git a/src/main/java/net/pterodactylus/sone/core/ImageInserter.java b/src/main/java/net/pterodactylus/sone/core/ImageInserter.java index 791663f..d0dc31a 100644 --- a/src/main/java/net/pterodactylus/sone/core/ImageInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/ImageInserter.java @@ -31,6 +31,8 @@ import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.util.logging.Logging; +import com.google.common.base.Function; + /** * The image inserter is responsible for inserting images using * {@link FreenetInterface#insertImage(TemporaryImage, Image, InsertToken)} and @@ -46,6 +48,7 @@ public class ImageInserter { /** The freenet interface. */ private final FreenetInterface freenetInterface; + private final Function insertTokenSupplier; /** The tokens of running inserts. */ private final Map insertTokens = Collections.synchronizedMap(new HashMap()); @@ -55,9 +58,12 @@ public class ImageInserter { * * @param freenetInterface * The freenet interface + * @param insertTokenSupplier + * The supplier for insert tokens */ - public ImageInserter(FreenetInterface freenetInterface) { + public ImageInserter(FreenetInterface freenetInterface, Function insertTokenSupplier) { this.freenetInterface = freenetInterface; + this.insertTokenSupplier = insertTokenSupplier; } /** @@ -73,7 +79,7 @@ public class ImageInserter { checkNotNull(image, "image must not be null"); checkArgument(image.getId().equals(temporaryImage.getId()), "image IDs must match"); try { - InsertToken insertToken = freenetInterface.new InsertToken(image); + InsertToken insertToken = insertTokenSupplier.apply(image); insertTokens.put(image.getId(), insertToken); freenetInterface.insertImage(temporaryImage, image, insertToken); } catch (SoneException se1) {