Author: toad
Date: 2008-06-16 22:21:35 +0000 (Mon, 16 Jun 2008)
New Revision: 20388

Modified:
   branches/db4o/freenet/src/freenet/client/async/ClientCallback.java
   branches/db4o/freenet/src/freenet/client/async/ClientContext.java
   branches/db4o/freenet/src/freenet/client/async/ClientGetter.java
   branches/db4o/freenet/src/freenet/client/async/ClientPutter.java
   branches/db4o/freenet/src/freenet/client/async/SimpleManifestPutter.java
Log:
Add ObjectContainer to most of the ClientCallback's.
The clients are within the same VM, and often need transactions (e.g. FCP).

Modified: branches/db4o/freenet/src/freenet/client/async/ClientCallback.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientCallback.java  
2008-06-16 22:16:29 UTC (rev 20387)
+++ branches/db4o/freenet/src/freenet/client/async/ClientCallback.java  
2008-06-16 22:21:35 UTC (rev 20388)
@@ -3,6 +3,8 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.client.async;

+import com.db4o.ObjectContainer;
+
 import freenet.client.FetchException;
 import freenet.client.FetchResult;
 import freenet.client.InsertException;
@@ -15,13 +17,13 @@
  */
 public interface ClientCallback {

-       public void onSuccess(FetchResult result, ClientGetter state);
+       public void onSuccess(FetchResult result, ClientGetter state, 
ObjectContainer container);

-       public void onFailure(FetchException e, ClientGetter state);
+       public void onFailure(FetchException e, ClientGetter state, 
ObjectContainer container);

-       public void onSuccess(BaseClientPutter state);
+       public void onSuccess(BaseClientPutter state, ObjectContainer 
container);

-       public void onFailure(InsertException e, BaseClientPutter state);
+       public void onFailure(InsertException e, BaseClientPutter state, 
ObjectContainer container);

        public void onGeneratedURI(FreenetURI uri, BaseClientPutter state);


Modified: branches/db4o/freenet/src/freenet/client/async/ClientContext.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientContext.java   
2008-06-16 22:16:29 UTC (rev 20387)
+++ branches/db4o/freenet/src/freenet/client/async/ClientContext.java   
2008-06-16 22:21:35 UTC (rev 20388)
@@ -60,7 +60,7 @@
                                        try {
                                                inserter.start(earlyEncode, 
false, container, context);
                                        } catch (InsertException e) {
-                                               inserter.client.onFailure(e, 
inserter);
+                                               inserter.client.onFailure(e, 
inserter, container);
                                        }
                                }

@@ -78,7 +78,7 @@
                                        try {
                                                getter.start(container, 
context);
                                        } catch (FetchException e) {
-                                               
getter.clientCallback.onFailure(e, getter);
+                                               
getter.clientCallback.onFailure(e, getter, container);
                                        }
                                }

@@ -96,7 +96,7 @@
                                        try {
                                                inserter.start(container, 
context);
                                        } catch (InsertException e) {
-                                               inserter.cb.onFailure(e, 
inserter);
+                                               inserter.cb.onFailure(e, 
inserter, container);
                                        }
                                }


Modified: branches/db4o/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientGetter.java    
2008-06-16 22:16:29 UTC (rev 20387)
+++ branches/db4o/freenet/src/freenet/client/async/ClientGetter.java    
2008-06-16 22:21:35 UTC (rev 20388)
@@ -153,20 +153,8 @@
                        if(returnBucket != null && 
Logger.shouldLog(Logger.MINOR, this))
                                Logger.minor(this, "client.async returned data 
in returnBucket");
                }
-               final FetchResult res = result;
-               context.mainExecutor.execute(new PrioRunnable() {
-                       public void run() {
-                               clientCallback.onSuccess(res, 
ClientGetter.this);
-                       }
-
-                       public int getPriority() {
-                               if(getPriorityClass() <= 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS)
-                                       return NativeThread.NORM_PRIORITY;
-                               else
-                                       return NativeThread.LOW_PRIORITY;
-                       }
-               }, "ClientGetter onSuccess callback for "+this);
-               
+               FetchResult res = result;
+               clientCallback.onSuccess(res, ClientGetter.this, container);
        }

        public void onFailure(FetchException e, ClientGetState state, 
ObjectContainer container, ClientContext context) {
@@ -204,18 +192,7 @@
                                e = new FetchException(e, 
FetchException.ALL_DATA_NOT_FOUND);
                        Logger.minor(this, "onFailure("+e+", "+state+") on 
"+this+" for "+uri, e);
                        final FetchException e1 = e;
-                       context.mainExecutor.execute(new PrioRunnable() {
-                               public void run() {
-                                       clientCallback.onFailure(e1, 
ClientGetter.this);
-                               }
-                               public int getPriority() {
-                                       if(getPriorityClass() <= 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS)
-                                               return 
NativeThread.NORM_PRIORITY;
-                                       else
-                                               return 
NativeThread.LOW_PRIORITY;
-                               }
-                       }, "ClientGetter onFailure callback");
-                       
+                       clientCallback.onFailure(e1, ClientGetter.this, 
container);
                        return;
                }
        }

Modified: branches/db4o/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientPutter.java    
2008-06-16 22:16:29 UTC (rev 20387)
+++ branches/db4o/freenet/src/freenet/client/async/ClientPutter.java    
2008-06-16 22:21:35 UTC (rev 20388)
@@ -141,7 +141,7 @@
                        }
                        // notify the client that the insert could not even be 
started
                        if (this.client!=null) {
-                               this.client.onFailure(e, this);
+                               this.client.onFailure(e, this, container);
                        }
                } catch (IOException e) {
                        Logger.error(this, "Failed to start insert: "+e, e);
@@ -152,7 +152,7 @@
                        }
                        // notify the client that the insert could not even be 
started
                        if (this.client!=null) {
-                               this.client.onFailure(new 
InsertException(InsertException.BUCKET_ERROR, e, null), this);
+                               this.client.onFailure(new 
InsertException(InsertException.BUCKET_ERROR, e, null), this, container);
                        }
                } catch (BinaryBlobFormatException e) {
                        Logger.error(this, "Failed to start insert: "+e, e);
@@ -163,7 +163,7 @@
                        }
                        // notify the client that the insert could not even be 
started
                        if (this.client!=null) {
-                               this.client.onFailure(new 
InsertException(InsertException.BINARY_BLOB_FORMAT_ERROR, e, null), this);
+                               this.client.onFailure(new 
InsertException(InsertException.BINARY_BLOB_FORMAT_ERROR, e, null), this, 
container);
                        }
                } 
                if(Logger.shouldLog(Logger.MINOR, this))
@@ -182,7 +182,7 @@
                                        ", Successful blocks: 
"+successfulBlocks+", Total blocks: "+totalBlocks+" but success?! on "+this+" 
from "+state,
                                        new Exception("debug"));
                }
-               client.onSuccess(this);
+               client.onSuccess(this, container);
        }

        public void onFailure(InsertException e, ClientPutState state, 
ObjectContainer container, ClientContext context) {
@@ -191,7 +191,7 @@
                        currentState = null;
                        oldProgress = null;
                }
-               client.onFailure(e, this);
+               client.onFailure(e, this, container);
        }

        public void onMajorProgress() {

Modified: 
branches/db4o/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2008-06-16 22:16:29 UTC (rev 20387)
+++ branches/db4o/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2008-06-16 22:21:35 UTC (rev 20388)
@@ -94,13 +94,13 @@
                                        return;
                                }
                        }
-                       insertedAllFiles();
+                       insertedAllFiles(container);
                }

                public void onFailure(InsertException e, ClientPutState state, 
ObjectContainer container, ClientContext context) {
                        logMINOR = Logger.shouldLog(Logger.MINOR, this);
                        if(logMINOR) Logger.minor(this, "Failed: "+this+" - 
"+e, e);
-                       fail(e);
+                       fail(e, container);
                }

                public void onEncode(BaseClientKey key, ClientPutState state, 
ObjectContainer container, ClientContext context) {
@@ -346,7 +346,7 @@
                if(defaultName != null) {
                        Metadata meta = (Metadata) 
namesToByteArrays.get(defaultName);
                        if(meta == null) {
-                               fail(new 
InsertException(InsertException.INVALID_URI, "Default name "+defaultName+" does 
not exist", null));
+                               fail(new 
InsertException(InsertException.INVALID_URI, "Default name "+defaultName+" does 
not exist", null), container);
                                return;
                        }
                        namesToByteArrays.put("", meta);
@@ -376,16 +376,16 @@
                                bucket = 
BucketTools.makeImmutableBucket(ctx.bf, baseMetadata.writeToByteArray());
                                break;
                        } catch (IOException e) {
-                               fail(new 
InsertException(InsertException.BUCKET_ERROR, e, null));
+                               fail(new 
InsertException(InsertException.BUCKET_ERROR, e, null), container);
                                return;
                        } catch (MetadataUnresolvedException e) {
                                try {
                                        resolve(e, container, context);
                                } catch (IOException e1) {
-                                       fail(new 
InsertException(InsertException.BUCKET_ERROR, e, null));
+                                       fail(new 
InsertException(InsertException.BUCKET_ERROR, e, null), container);
                                        return;
                                } catch (InsertException e2) {
-                                       fail(e2);
+                                       fail(e2, container);
                                        return;
                                }
                        }
@@ -442,10 +442,10 @@
                                isMetadata = false;
                                insertAsArchiveManifest = true;
                        } catch (ZipException e) {
-                               fail(new 
InsertException(InsertException.INTERNAL_ERROR, e, null));
+                               fail(new 
InsertException(InsertException.INTERNAL_ERROR, e, null), container);
                                return;
                        } catch (IOException e) {
-                               fail(new 
InsertException(InsertException.BUCKET_ERROR, e, null));
+                               fail(new 
InsertException(InsertException.BUCKET_ERROR, e, null), container);
                                return;
                        }
                } else
@@ -458,7 +458,7 @@
                        metadataPuttersUnfetchable.put(baseMetadata, 
metadataInserter);
                        metadataInserter.start(null, container, context);
                } catch (InsertException e) {
-                       fail(e);
+                       fail(e, container);
                }
        }

@@ -508,7 +508,7 @@
                }
        }

-       private void insertedAllFiles() {
+       private void insertedAllFiles(ObjectContainer container) {
                if(logMINOR) Logger.minor(this, "Inserted all files");
                synchronized(this) {
                        insertedAllFiles = true;
@@ -522,18 +522,18 @@
                        }
                        finished = true;
                }
-               complete();
+               complete(container);
        }

-       private void complete() {
-               cb.onSuccess(this);
+       private void complete(ObjectContainer container) {
+               cb.onSuccess(this, container);
        }

-       private void fail(InsertException e) {
+       private void fail(InsertException e, ObjectContainer container) {
                // Cancel all, then call the callback
                cancelAndFinish();

-               cb.onFailure(e, this);
+               cb.onFailure(e, this, container);
        }

        /**
@@ -552,9 +552,9 @@
                }
        }

-       public void cancel() {
+       public void cancel(ObjectContainer container) {
                super.cancel();
-               fail(new InsertException(InsertException.CANCELLED));
+               fail(new InsertException(InsertException.CANCELLED), container);
        }

        public void onSuccess(ClientPutState state, ObjectContainer container, 
ClientContext context) {
@@ -577,12 +577,12 @@
                        }
                        finished = true;
                }
-               complete();
+               complete(container);
        }

        public void onFailure(InsertException e, ClientPutState state, 
ObjectContainer container, ClientContext context) {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
-               fail(e);
+               fail(e, container);
        }

        public void onEncode(BaseClientKey key, ClientPutState state, 
ObjectContainer container, ClientContext context) {


Reply via email to