Author: toad
Date: 2006-01-27 23:42:36 +0000 (Fri, 27 Jan 2006)
New Revision: 7960

Modified:
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/ClientPutter.java
   trunk/freenet/src/freenet/client/async/ClientRequest.java
   trunk/freenet/src/freenet/client/async/GetCompletionCallback.java
   trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
   trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
   trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java
Log:
411:
Add finalized-total flag to FCP and TMCI.
Use it on requests, so far. Inserts soon.
This will probably be useful to FCP client authors.

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-01-27 
21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-01-27 
23:42:36 UTC (rev 7960)
@@ -9,6 +9,7 @@
 import freenet.client.FetcherContext;
 import freenet.client.events.SplitfileProgressEvent;
 import freenet.keys.FreenetURI;
+import freenet.support.Logger;

 /**
  * A high level data request.
@@ -87,7 +88,12 @@
        }

        public void notifyClients() {
-               ctx.eventProducer.produceEvent(new 
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, 
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks));
+               ctx.eventProducer.produceEvent(new 
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, 
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, 
this.blockSetFinalized));
        }
+
+       public void onBlockSetFinished(ClientGetState state) {
+               Logger.minor(this, "Set finished", new Exception("debug"));
+               blockSetFinalized();
+       }

 }

Modified: trunk/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientPutter.java    2006-01-27 
21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/ClientPutter.java    2006-01-27 
23:42:36 UTC (rev 7960)
@@ -94,7 +94,7 @@
        }

        public void notifyClients() {
-               ctx.eventProducer.produceEvent(new 
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, 
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks));
+               ctx.eventProducer.produceEvent(new 
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, 
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, 
this.blockSetFinalized));
        }

 }

Modified: trunk/freenet/src/freenet/client/async/ClientRequest.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequest.java   2006-01-27 
21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/ClientRequest.java   2006-01-27 
23:42:36 UTC (rev 7960)
@@ -46,29 +46,49 @@
        protected int fatallyFailedBlocks;
        /** Minimum number of blocks required to succeed for success. */
        protected int minSuccessBlocks;
+       /** Has totalBlocks stopped growing? */
+       protected boolean blockSetFinalized;

+       public void blockSetFinalized() {
+               synchronized(this) {
+                       if(blockSetFinalized) return;
+                       blockSetFinalized = true;
+               }
+               notifyClients();
+       }
+       
        public synchronized void addBlock() {
+               if(blockSetFinalized)
+                       Logger.error(this, "addBlock() but set finalized! on 
"+this, new Exception("error"));
                totalBlocks++;
        }

        public synchronized void addBlocks(int num) {
+               if(blockSetFinalized)
+                       Logger.error(this, "addBlock() but set finalized! on 
"+this, new Exception("error"));
                totalBlocks+=num;
        }

-       public synchronized void completedBlock(boolean dontNotify) {
+       public void completedBlock(boolean dontNotify) {
                Logger.minor(this, "Completed block ("+dontNotify+")");
-               successfulBlocks++;
-               if(!dontNotify)
-                       notifyClients();
+               synchronized(this) {
+                       successfulBlocks++;
+                       if(dontNotify) return;
+               }
+               notifyClients();
        }

-       public synchronized void failedBlock() {
-               failedBlocks++;
+       public void failedBlock() {
+               synchronized(this) {
+                       failedBlocks++;
+               }
                notifyClients();
        }

-       public synchronized void fatallyFailedBlock() {
-               fatallyFailedBlocks++;
+       public void fatallyFailedBlock() {
+               synchronized(this) {
+                       fatallyFailedBlocks++;
+               }
                notifyClients();
        }


Modified: trunk/freenet/src/freenet/client/async/GetCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/GetCompletionCallback.java   
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/GetCompletionCallback.java   
2006-01-27 23:42:36 UTC (rev 7960)
@@ -13,4 +13,8 @@

        public void onFailure(FetchException e, ClientGetState state);

+       /** Called when the ClientGetState knows that it knows about
+        * all the blocks it will need to fetch.
+        */
+       public void onBlockSetFinished(ClientGetState state);
 }

Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-01-27 23:42:36 UTC (rev 7960)
@@ -318,7 +318,7 @@
        }

        public void notifyClients() {
-               ctx.eventProducer.produceEvent(new 
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, 
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks));
+               ctx.eventProducer.produceEvent(new 
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, 
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, 
this.blockSetFinalized));
        }

 }

Modified: trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleBlockInserter.java     
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/SingleBlockInserter.java     
2006-01-27 23:42:36 UTC (rev 7960)
@@ -230,7 +230,11 @@
        public void send(Node node) {
                try {
                        Logger.minor(this, "Starting request: "+this);
-                       node.realPut(getBlock(), ctx.cacheLocalRequests);
+                       ClientKeyBlock b = getBlock();
+                       if(b != null)
+                               node.realPut(b, ctx.cacheLocalRequests);
+                       else
+                               fail(new 
InserterException(InserterException.CANCELLED));
                } catch (LowLevelPutException e) {
                        onFailure(e);
                        Logger.minor(this, "Request failed: "+this+" for "+e);

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-01-27 23:42:36 UTC (rev 7960)
@@ -14,6 +14,7 @@
 import freenet.client.FetcherContext;
 import freenet.client.Metadata;
 import freenet.client.MetadataParseException;
+import freenet.keys.ClientCHK;
 import freenet.keys.ClientKey;
 import freenet.keys.ClientKeyBlock;
 import freenet.keys.FreenetURI;
@@ -251,7 +252,7 @@
                                                throw new 
FetchException(FetchException.BUCKET_ERROR, e);
                                        }
                                } else {
-                                       fetchArchive(); // will result in this 
function being called again
+                                       fetchArchive(false); // will result in 
this function being called again
                                        return;
                                }
                                continue;
@@ -271,7 +272,7 @@
                                        // Metadata cannot contain pointers to 
files which don't exist.
                                        // We enforce this in ArchiveHandler.
                                        // Therefore, the archive needs to be 
fetched.
-                                       fetchArchive();
+                                       fetchArchive(true);
                                        // Will call back into this function 
when it has been fetched.
                                        return;
                                }
@@ -298,6 +299,8 @@
                                } catch (MalformedURLException e) {
                                        throw new 
FetchException(FetchException.INVALID_URI, e);
                                }
+                               if(key instanceof ClientCHK && 
!((ClientCHK)key).isMetadata())
+                                       rcb.onBlockSetFinished(this);
                                LinkedList newMetaStrings = 
uri.listMetaStrings();

                                // Move any new meta strings to beginning of 
our list of remaining meta strings
@@ -330,6 +333,7 @@
                                SplitFileFetcher sf = new 
SplitFileFetcher(metadata, rcb, parent, ctx, 
                                                decompressors, clientMetadata, 
actx, recursionLevel);
                                sf.schedule();
+                               rcb.onBlockSetFinished(this);
                                // SplitFile will now run.
                                // Then it will return data to rcd.
                                // We are now out of the loop. Yay!
@@ -345,7 +349,7 @@
                decompressors.addLast(codec);
        }

-       private void fetchArchive() throws FetchException, 
MetadataParseException, ArchiveFailureException, ArchiveRestartException {
+       private void fetchArchive(boolean forData) throws FetchException, 
MetadataParseException, ArchiveFailureException, ArchiveRestartException {
                // Fetch the archive
                // How?
                // Spawn a separate SingleFileFetcher,
@@ -355,7 +359,7 @@
                Metadata newMeta = (Metadata) metadata.clone();
                newMeta.setSimpleRedirect();
                SingleFileFetcher f;
-               f = new SingleFileFetcher(this, newMeta, new 
ArchiveFetcherCallback(), new FetcherContext(ctx, 
FetcherContext.SET_RETURN_ARCHIVES));
+               f = new SingleFileFetcher(this, newMeta, new 
ArchiveFetcherCallback(forData), new FetcherContext(ctx, 
FetcherContext.SET_RETURN_ARCHIVES));
                f.handleMetadata();
                // When it is done (if successful), the ArchiveCallback will 
re-call this function.
                // Which will then discover that the metadata *is* available.
@@ -364,6 +368,12 @@

        class ArchiveFetcherCallback implements GetCompletionCallback {

+               private final boolean wasFetchingFinalData;
+               
+               ArchiveFetcherCallback(boolean wasFetchingFinalData) {
+                       this.wasFetchingFinalData = wasFetchingFinalData;
+               }
+               
                public void onSuccess(FetchResult result, ClientGetState state) 
{
                        parent.currentState = SingleFileFetcher.this;
                        try {
@@ -390,6 +400,12 @@
                        // Force fatal as the fetcher is presumed to have made 
a reasonable effort.
                        SingleFileFetcher.this.onFailure(e, true);
                }
+
+               public void onBlockSetFinished(ClientGetState state) {
+                       if(wasFetchingFinalData) {
+                               rcb.onBlockSetFinished(SingleFileFetcher.this);
+                       }
+               }

        }

@@ -422,6 +438,10 @@
                        // Pass it on; fetcher is assumed to have retried as 
appropriate already, so this is fatal.
                        SingleFileFetcher.this.onFailure(e, true);
                }
+
+               public void onBlockSetFinished(ClientGetState state) {
+                       // Ignore as we are fetching metadata here
+               }

        }


Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcher.java        
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcher.java        
2006-01-27 23:42:36 UTC (rev 7960)
@@ -217,24 +217,6 @@
                return parent;
        }

-       public void onProgress() {
-               int totalBlocks = splitfileDataBlocks.length;
-               int fetchedBlocks = 0;
-               int failedBlocks = 0;
-               int fatallyFailedBlocks = 0;
-               int runningBlocks = 0;
-               for(int i=0;i<segments.length;i++) {
-                       SplitFileFetcherSegment segment = segments[i];
-                       Logger.minor(this, "Segment: "+segment+": 
fetched="+segment.fetchedBlocks()+", failedBlocks: "+segment.failedBlocks()+
-                                       ", fatally: 
"+segment.fatallyFailedBlocks()+", running: "+segment.runningBlocks());
-                       fetchedBlocks += segment.fetchedBlocks();
-                       failedBlocks += segment.failedBlocks();
-                       fatallyFailedBlocks += segment.fatallyFailedBlocks();
-                       runningBlocks += segment.runningBlocks();
-               }
-               fetchContext.eventProducer.produceEvent(new 
SplitfileProgressEvent(totalBlocks, fetchedBlocks, failedBlocks, 
fatallyFailedBlocks, runningBlocks));
-       }
-
        public void schedule() {
                for(int i=0;i<segments.length;i++) {
                        segments[i].schedule();

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 
2006-01-27 23:42:36 UTC (rev 7960)
@@ -342,4 +342,8 @@
                fail(new FetchException(FetchException.CANCELLED));
        }

+       public void onBlockSetFinished(ClientGetState state) {
+               // Ignore; irrelevant
+       }
+
 }

Modified: trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java 
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java 
2006-01-27 23:42:36 UTC (rev 7960)
@@ -9,18 +9,21 @@
        public final int failedBlocks;
        public final int fatallyFailedBlocks;
        public final int minSuccessfulBlocks;
+       public final boolean finalizedTotal;

        public SplitfileProgressEvent(int totalBlocks, int fetchedBlocks, int 
failedBlocks, 
-                       int fatallyFailedBlocks, int minSuccessfulBlocks) {
+                       int fatallyFailedBlocks, int minSuccessfulBlocks, 
boolean finalizedTotal) {
                this.totalBlocks = totalBlocks;
                this.fetchedBlocks = fetchedBlocks;
                this.failedBlocks = failedBlocks;
                this.fatallyFailedBlocks = fatallyFailedBlocks;
                this.minSuccessfulBlocks = minSuccessfulBlocks;
+               this.finalizedTotal = finalizedTotal;
        }

        public String getDescription() {
-               return "Completed 
"+(100*(fetchedBlocks)/minSuccessfulBlocks)+"% 
"+fetchedBlocks+"/"+totalBlocks+" (failed "+failedBlocks+", fatally 
"+fatallyFailedBlocks+", need "+minSuccessfulBlocks+", total "+totalBlocks+")";
+               return "Completed 
"+(100*(fetchedBlocks)/minSuccessfulBlocks)+"% 
"+fetchedBlocks+"/"+minSuccessfulBlocks+" (failed "+failedBlocks+", fatally 
"+fatallyFailedBlocks+", total "+totalBlocks+")" +
+                       (finalizedTotal ? " (finalized total)" : "");
        }

        public int getCode() {

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-01-27 21:35:46 UTC (rev 
7959)
+++ trunk/freenet/src/freenet/node/Version.java 2006-01-27 23:42:36 UTC (rev 
7960)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 410;
+       private static final int buildNumber = 411;

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 403;

Modified: trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java       
2006-01-27 21:35:46 UTC (rev 7959)
+++ trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java       
2006-01-27 23:42:36 UTC (rev 7960)
@@ -21,6 +21,7 @@
                fs.put("Failed", Integer.toString(event.failedBlocks));
                fs.put("FatallyFailed", 
Integer.toString(event.fatallyFailedBlocks));
                fs.put("Succeeded",Integer.toString(event.fetchedBlocks));
+               fs.put("FinalizedTotal", 
Boolean.toString(event.finalizedTotal));
                fs.put("Identifier", ident);
                return fs;
        }


Reply via email to