Any particular reason to make it blocking? You could free the bucket in the 
callback (and also if something is thrown when scheduling in a finally{} 
block, set a flag and check for it).

On Monday 01 September 2008 22:06, saces at freenetproject.org wrote:
> Author: saces
> Date: 2008-09-01 21:06:50 +0000 (Mon, 01 Sep 2008)
> New Revision: 22321
> 
> Modified:
>    trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java
> Log:
> change insert code, ensure temp bucket is freed.
> 
> Modified: trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java
> ===================================================================
> --- trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java      2008-09-01 
> 21:05:09 
UTC (rev 22320)
> +++ trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java      2008-09-01 
> 21:06:50 
UTC (rev 22321)
> @@ -37,7 +37,7 @@
>   * @author Julien Cornuwel (batosai at freenetproject.org)
>   *
>   */
> -public class IdentityInserter implements ClientCallback, Runnable {
> +public class IdentityInserter implements Runnable {
>       
>       WoT wot;
>       ObjectContainer db;
> @@ -84,63 +84,30 @@
>               isRunning = false;
>       }
>       
> -     public void insert(OwnIdentity identity) throws 
TransformerConfigurationException, FileNotFoundException, 
ParserConfigurationException, TransformerException, IOException, 
InsertException, Db4oIOException, DatabaseClosedException, 
InvalidParameterException {
> +     public void insert(OwnIdentity identity) throws 
TransformerConfigurationException, FileNotFoundException, 
ParserConfigurationException, TransformerException, IOException, 
Db4oIOException, DatabaseClosedException, InvalidParameterException, 
InsertException {
>  
>               Bucket tempB = tBF.makeBucket(1);
> +             FreenetURI iURI;
> +             try {
>               // Create XML file to insert
> -             identity.exportToXML(db, tempB.getOutputStream());
> +                     identity.exportToXML(db, tempB.getOutputStream());
>               
> -             tempB.setReadOnly();
> +                     tempB.setReadOnly();
>               
> -             // Prepare the insert
> -             ClientMetadata cmd = new ClientMetadata("text/xml");
> -             InsertBlock ib = new 
> InsertBlock(tempB,cmd,identity.getInsertURI());
> -             client.getInsertContext(false);
> +                     // Prepare the insert
> +                     ClientMetadata cmd = new ClientMetadata("text/xml");
> +                     InsertBlock ib = new 
> InsertBlock(tempB,cmd,identity.getInsertURI());
>  
> -             // Insert
> -             client.insert(ib, false, "identity.xml", false, 
client.getInsertContext(false), this);
> -             
> -             // Logging
> -             Logger.debug(this, "Started insert of identity '" + 
identity.getNickName() + "'");
> +                     // Logging
> +                     Logger.debug(this, "Started insert of identity '" + 
identity.getNickName() + "'");
>  
> -             db.store(identity);
> -     }
> -
> -     public void onFailure(FetchException e, ClientGetter state) {
> -             
> -     }
> -
> -     public void onFailure(InsertException e, BaseClientPutter state) {
> -             
> -     }
> -
> -     public void onFetchable(BaseClientPutter state) {
> -             
> -     }
> -
> -     public void onGeneratedURI(FreenetURI uri, BaseClientPutter state) {
> -             
> -     }
> -
> -     public void onMajorProgress() {
> -             
> -     }
> -
> -     public void onSuccess(FetchResult result, ClientGetter state) {
> -             
> -     }
> -
> -     public void onSuccess(BaseClientPutter state) {
> -
> -             OwnIdentity identity;
> -             try {
> -                     identity = OwnIdentity.getByURI(db, state.getURI());
> -             } catch (Exception e) {
> -                     Logger.error(this, "Identity insert failed", e);
> -                     return;
> +                     // Blocking Insert
> +                     iURI = client.insert(ib, false, "identity.xml");
> +             } finally {
> +                     tempB.free();           
>               }
>               
> -             identity.setEdition(state.getURI().getSuggestedEdition());
> +             identity.setEdition(iURI.getSuggestedEdition());
>               identity.setLastInsert(new Date());
>               
>               db.store(identity);
> @@ -149,5 +116,4 @@
>               // Logging
>               Logger.debug(this, "Successful insert of identity '" + 
identity.getNickName() + "'");
>       }
> -
>  }
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080906/50ad70de/attachment.pgp>

Reply via email to