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;
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;
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;
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);
}
/** All properties of the Sone, copied for thread safety. */
private final Map<String, Object> soneProperties = new HashMap<String, Object>();
+ private final Set<Bucket> buckets = new HashSet<Bucket>();
/**
* Creates a new insert information container.
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()));
return manifestEntries;
}
+ public void freeBuckets() {
+ for (Bucket bucket : buckets) {
+ bucket.free();
+ }
+ }
+
//
// PRIVATE METHODS
//
return null;
} finally {
Closer.close(writer);
- if (bucket != null) {
- bucket.free();
- }
}
}