From 48ac9dedd81abd3d2ef58110e39e09a91fa3c659 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 1 Mar 2014 14:14:47 +0100 Subject: [PATCH] Free all buckets after the insert has finished. --- src/main/java/net/pterodactylus/sone/core/SoneInserter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 8e253ee..04254d4 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -28,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; @@ -55,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; @@ -254,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); } @@ -290,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. @@ -355,6 +359,12 @@ public class SoneInserter extends AbstractService { return manifestEntries; } + public void freeBuckets() { + for (Bucket bucket : buckets) { + bucket.free(); + } + } + // // PRIVATE METHODS // @@ -400,9 +410,6 @@ public class SoneInserter extends AbstractService { return null; } finally { Closer.close(writer); - if (bucket != null) { - bucket.free(); - } } } -- 2.7.4