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;
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;
}
+ public class InsertTokenSupplier implements Function<Image, InsertToken> {
+
+ @Override
+ public InsertToken apply(Image image) {
+ return new InsertToken(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
/** The freenet interface. */
private final FreenetInterface freenetInterface;
+ private final Function<Image, InsertToken> insertTokenSupplier;
/** The tokens of running inserts. */
private final Map<String, InsertToken> insertTokens = Collections.synchronizedMap(new HashMap<String, InsertToken>());
*
* @param freenetInterface
* The freenet interface
+ * @param insertTokenSupplier
+ * The supplier for insert tokens
*/
- public ImageInserter(FreenetInterface freenetInterface) {
+ public ImageInserter(FreenetInterface freenetInterface, Function<Image, InsertToken> insertTokenSupplier) {
this.freenetInterface = freenetInterface;
+ this.insertTokenSupplier = insertTokenSupplier;
}
/**
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) {