X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserter.java;h=04254d491c1ab17b4c741ef32696ce3369f6a321;hb=48ac9dedd81abd3d2ef58110e39e09a91fa3c659;hp=12abc53ce3a1157242442bb5e39dfc32948b84dd;hpb=9f9834453e9555175e4771932d9521209bd7188c;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 12abc53..04254d4 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.core; import static com.google.common.base.Preconditions.checkArgument; import static net.pterodactylus.sone.data.Album.NOT_EMPTY; import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI; +import static net.pterodactylus.sone.data.Sone.TO_INSERT_URI; import java.io.InputStreamReader; import java.io.StringWriter; @@ -27,6 +28,7 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -54,6 +56,7 @@ import net.pterodactylus.util.template.XmlFilter; import freenet.client.async.ManifestElement; import freenet.keys.FreenetURI; +import freenet.support.api.Bucket; import com.google.common.collect.FluentIterable; import com.google.common.collect.Ordering; @@ -253,6 +256,7 @@ public class SoneInserter extends AbstractService { eventBus.post(new SoneInsertAbortedEvent(sone, se1)); logger.log(Level.WARNING, String.format("Could not insert Sone “%s”!", sone.getName()), se1); } finally { + insertInformation.freeBuckets(); sone.setStatus(SoneStatus.idle); } @@ -289,6 +293,7 @@ public class SoneInserter extends AbstractService { /** All properties of the Sone, copied for thread safety. */ private final Map soneProperties = new HashMap(); + private final Set buckets = new HashSet(); /** * Creates a new insert information container. @@ -301,6 +306,7 @@ public class SoneInserter extends AbstractService { soneProperties.put("name", sone.getName()); soneProperties.put("time", sone.getTime()); soneProperties.put("requestUri", TO_FREENET_URI.apply(sone)); + soneProperties.put("insertUri", TO_INSERT_URI.apply(sone)); soneProperties.put("profile", sone.getProfile()); soneProperties.put("posts", Ordering.from(Post.TIME_COMPARATOR).sortedCopy(sone.getPosts())); soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies())); @@ -353,6 +359,12 @@ public class SoneInserter extends AbstractService { return manifestEntries; } + public void freeBuckets() { + for (Bucket bucket : buckets) { + bucket.free(); + } + } + // // PRIVATE METHODS // @@ -398,9 +410,6 @@ public class SoneInserter extends AbstractService { return null; } finally { Closer.close(writer); - if (bucket != null) { - bucket.free(); - } } }