Only free bucket after the insert is done
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 11 Jun 2015 21:35:49 +0000 (23:35 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 11 Jun 2015 21:35:49 +0000 (23:35 +0200)
pom.xml
src/main/java/net/pterodactylus/sone/core/FreenetInterface.java

diff --git a/pom.xml b/pom.xml
index fac0f31..4309f05 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
                <dependency>
                        <groupId>org.freenetproject</groupId>
                        <artifactId>fred</artifactId>
-                       <version>0.7.5.1467.99.1</version>
+                       <version>0.7.5.1467.99.3</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
index e3a215a..cfc1309 100644 (file)
@@ -161,6 +161,7 @@ public class FreenetInterface {
                FreenetURI targetUri = key.getInsertURI().setDocName(filenameHint);
                InsertContext insertContext = client.getInsertContext(true);
                RandomAccessBucket bucket = new ArrayBucket(temporaryImage.getImageData());
+               insertToken.setBucket(bucket);
                ClientMetadata metadata = new ClientMetadata(temporaryImage.getMimeType());
                InsertBlock insertBlock = new InsertBlock(bucket, metadata, targetUri);
                try {
@@ -168,8 +169,6 @@ public class FreenetInterface {
                        insertToken.setClientPutter(clientPutter);
                } catch (InsertException ie1) {
                        throw new SoneInsertException("Could not start image insert.", ie1);
-               } finally {
-                       bucket.free();
                }
        }
 
@@ -406,6 +405,7 @@ public class FreenetInterface {
 
                /** The client putter. */
                private ClientPutter clientPutter;
+               private Bucket bucket;
 
                /** The final URI. */
                private volatile FreenetURI resultingUri;
@@ -437,6 +437,10 @@ public class FreenetInterface {
                        eventBus.post(new ImageInsertStartedEvent(image));
                }
 
+               public void setBucket(Bucket bucket) {
+                       this.bucket = bucket;
+               }
+
                //
                // ACTIONS
                //
@@ -475,6 +479,7 @@ public class FreenetInterface {
                        } else {
                                eventBus.post(new ImageInsertFailedEvent(image, insertException));
                        }
+                       bucket.free();
                }
 
                /**
@@ -508,6 +513,7 @@ public class FreenetInterface {
                @SuppressWarnings("synthetic-access")
                public void onSuccess(BaseClientPutter clientPutter) {
                        eventBus.post(new ImageInsertFinishedEvent(image, resultingUri));
+                       bucket.free();
                }
 
        }