Author: toad
Date: 2006-01-26 22:56:36 +0000 (Thu, 26 Jan 2006)
New Revision: 7942

Added:
   trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java
Modified:
   trunk/freenet/src/freenet/client/InserterContext.java
   trunk/freenet/src/freenet/client/async/ClientRequest.java
   trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
   trunk/freenet/src/freenet/client/async/SendableGet.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/SplitFileInserterSegment.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/ClientPut.java
   trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
Log:
394:
Progress reporting on FCP (SimpleProgress message's if verbosity & 1 == 1).
Debug progress reporting (including making it work properly on putdir).


Modified: trunk/freenet/src/freenet/client/InserterContext.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterContext.java       2006-01-26 
22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/InserterContext.java       2006-01-26 
22:56:36 UTC (rev 7942)
@@ -1,6 +1,7 @@
 package freenet.client;

 import freenet.client.events.ClientEventProducer;
+import freenet.client.events.SimpleEventProducer;
 import freenet.crypt.RandomSource;
 import freenet.support.BucketFactory;

@@ -52,6 +53,20 @@
                this.cacheLocalRequests = ctx.cacheLocalRequests;
        }

+       public InserterContext(InserterContext ctx, SimpleEventProducer 
producer) {
+               this.bf = ctx.bf;
+               this.random = ctx.random;
+               this.dontCompress = ctx.dontCompress;
+               this.splitfileAlgorithm = ctx.splitfileAlgorithm;
+               this.consecutiveRNFsCountAsSuccess = 
ctx.consecutiveRNFsCountAsSuccess;
+               this.maxInsertRetries = ctx.maxInsertRetries;
+               this.maxSplitInsertThreads = ctx.maxSplitInsertThreads;
+               this.eventProducer = producer;
+               this.splitfileSegmentDataBlocks = 
ctx.splitfileSegmentDataBlocks;
+               this.splitfileSegmentCheckBlocks = 
ctx.splitfileSegmentCheckBlocks;
+               this.cacheLocalRequests = ctx.cacheLocalRequests;
+       }
+
        public void cancel() {
                cancelled = true;
        }

Modified: trunk/freenet/src/freenet/client/async/ClientRequest.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequest.java   2006-01-26 
22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/ClientRequest.java   2006-01-26 
22:56:36 UTC (rev 7942)
@@ -1,6 +1,7 @@
 package freenet.client.async;

 import freenet.keys.FreenetURI;
+import freenet.support.Logger;

 /** A high level client request. A request (either fetch or put) started
  * by a Client. Has a suitable context and a URI; is fulfilled only when
@@ -54,9 +55,11 @@
                totalBlocks+=num;
        }

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

        public synchronized void failedBlock() {

Modified: trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2006-01-26 22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2006-01-26 22:56:36 UTC (rev 7942)
@@ -56,7 +56,8 @@
                                return;
                        }
                        if(block != null) {
-                               getter.onSuccess(block);
+                               Logger.minor(this, "Can fulfill immediately 
from store");
+                               getter.onSuccess(block, true);
                                return;
                        }
                }

Modified: trunk/freenet/src/freenet/client/async/SendableGet.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SendableGet.java     2006-01-26 
22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/SendableGet.java     2006-01-26 
22:56:36 UTC (rev 7942)
@@ -12,7 +12,7 @@
        public ClientKey getKey();

        /** Called when/if the low-level request succeeds. */
-       public void onSuccess(ClientKeyBlock block);
+       public void onSuccess(ClientKeyBlock block, boolean fromStore);

        /** Called when/if the low-level request fails. */
        public void onFailure(LowLevelGetException e);

Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-01-26 22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-01-26 22:56:36 UTC (rev 7942)
@@ -103,6 +103,30 @@
                        }
                }

+               public void addBlock() {
+                       SimpleManifestPutter.this.addBlock();
+               }
+               
+               public void addBlocks(int num) {
+                       SimpleManifestPutter.this.addBlocks(num);
+               }
+               
+               public void completedBlock(boolean dontNotify) {
+                       SimpleManifestPutter.this.completedBlock(dontNotify);
+               }
+               
+               public void failedBlock() {
+                       SimpleManifestPutter.this.failedBlock();
+               }
+               
+               public void fatallyFailedBlock() {
+                       SimpleManifestPutter.this.fatallyFailedBlock();
+               }
+               
+               public void addMustSucceedBlocks(int blocks) {
+                       SimpleManifestPutter.this.addMustSucceedBlocks(blocks);
+               }
+               
                public void notifyClients() {
                        // FIXME generate per-filename events???
                }

Modified: trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleBlockInserter.java     
2006-01-26 22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/SingleBlockInserter.java     
2006-01-26 22:56:36 UTC (rev 7942)
@@ -207,7 +207,7 @@
                synchronized(this) {
                        finished = true;
                }
-               parent.completedBlock();
+               parent.completedBlock(false);
                cb.onSuccess(this);
        }


Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-01-26 22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-01-26 22:56:36 UTC (rev 7942)
@@ -134,7 +134,8 @@

        // Process the completed data. May result in us going to a
        // splitfile, or another SingleFileFetcher, etc.
-       public void onSuccess(ClientKeyBlock block) {
+       public void onSuccess(ClientKeyBlock block, boolean fromStore) {
+               parent.completedBlock(fromStore);
                // Extract data
                Bucket data;
                try {
@@ -206,7 +207,6 @@
                        }
                        result = new FetchResult(result, data);
                }
-               parent.completedBlock();
                rcb.onSuccess(result, this);
        }

@@ -503,7 +503,7 @@
                        onFailure(new 
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR));
                        return;
                }
-               onSuccess(block);
+               onSuccess(block, false);
        }

 }

Modified: trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java        
2006-01-26 22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java        
2006-01-26 22:56:36 UTC (rev 7942)
@@ -46,7 +46,7 @@
                dataBlockInserters = new SingleBlockInserter[dataBlocks.length];
                checkBlockInserters = new 
SingleBlockInserter[checkBlocks.length];
                parent.parent.addBlocks(dataURIs.length+checkURIs.length);
-               parent.parent.addMustSucceedBlocks(dataURIs.length);
+               
parent.parent.addMustSucceedBlocks(dataURIs.length+checkURIs.length);
                this.segNo = segNo;
        }


Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-01-26 22:07:23 UTC (rev 
7941)
+++ trunk/freenet/src/freenet/node/Version.java 2006-01-26 22:56:36 UTC (rev 
7942)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       public static final int buildNumber = 393;
+       public static final int buildNumber = 394;

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

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java   2006-01-26 22:07:23 UTC 
(rev 7941)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java   2006-01-26 22:56:36 UTC 
(rev 7942)
@@ -8,6 +8,9 @@
 import freenet.client.async.ClientCallback;
 import freenet.client.async.ClientGetter;
 import freenet.client.async.ClientPutter;
+import freenet.client.events.ClientEvent;
+import freenet.client.events.ClientEventListener;
+import freenet.client.events.SplitfileProgressEvent;
 import freenet.keys.FreenetURI;
 import freenet.support.Logger;

@@ -15,7 +18,7 @@
  * A simple client fetch. This can of course fetch arbitrarily large
  * files, including splitfiles, redirects, etc.
  */
-public class ClientGet extends ClientRequest implements ClientCallback {
+public class ClientGet extends ClientRequest implements ClientCallback, 
ClientEventListener {

        private final FreenetURI uri;
        private final FetcherContext fctx;
@@ -24,7 +27,11 @@
        private final FCPConnectionHandler handler;
        private final ClientGetter getter;
        private final short priorityClass;
+       private boolean finished;

+       // Verbosity bitmasks
+       private int VERBOSITY_SPLITFILE_PROGRESS = 1;
+       
        public ClientGet(FCPConnectionHandler handler, ClientGetMessage 
message) {
                uri = message.uri;
                // FIXME
@@ -33,6 +40,7 @@
                // since the client may override a few context elements.
                this.handler = handler;
                fctx = new FetcherContext(handler.defaultFetchContext, 
FetcherContext.IDENTICAL_MASK);
+               fctx.eventProducer.addEventListener(this);
                // ignoreDS
                fctx.localRequestOnly = message.dsOnly;
                fctx.ignoreStore = message.ignoreDS;
@@ -59,6 +67,7 @@
        }

        public void onSuccess(FetchResult result, ClientGetter state) {
+               finished = true;
                FCPMessage msg = new DataFoundMessage(handler, result, 
identifier);
                handler.outputHandler.queue(msg);
                // Send all the data at once
@@ -68,6 +77,7 @@
        }

        public void onFailure(FetchException e, ClientGetter state) {
+               finished = true;
                Logger.minor(this, "Caught "+e, e);
                FCPMessage msg = new GetFailedMessage(handler, e, identifier);
                handler.outputHandler.queue(msg);
@@ -85,4 +95,14 @@
                // Ignore
        }

+       public void receive(ClientEvent ce) {
+               if(finished) return;
+               if(!(((verbosity & VERBOSITY_SPLITFILE_PROGRESS) == 
VERBOSITY_SPLITFILE_PROGRESS) &&
+                               (ce instanceof SplitfileProgressEvent)))
+                       return;
+               SimpleProgressMessage progress = 
+                       new SimpleProgressMessage(identifier, 
(SplitfileProgressEvent)ce);
+               handler.outputHandler.queue(progress);
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/fcp/ClientPut.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPut.java   2006-01-26 22:07:23 UTC 
(rev 7941)
+++ trunk/freenet/src/freenet/node/fcp/ClientPut.java   2006-01-26 22:56:36 UTC 
(rev 7942)
@@ -10,9 +10,13 @@
 import freenet.client.async.ClientCallback;
 import freenet.client.async.ClientGetter;
 import freenet.client.async.ClientPutter;
+import freenet.client.events.ClientEvent;
+import freenet.client.events.ClientEventListener;
+import freenet.client.events.SimpleEventProducer;
+import freenet.client.events.SplitfileProgressEvent;
 import freenet.keys.FreenetURI;

-public class ClientPut extends ClientRequest implements ClientCallback {
+public class ClientPut extends ClientRequest implements ClientCallback, 
ClientEventListener {

        final FreenetURI uri;
        final ClientPutter inserter;
@@ -22,13 +26,20 @@
        final String identifier;
        final boolean getCHKOnly;
        final short priorityClass;
+       final int verbosity;
+       private boolean finished;

+       // Verbosity bitmasks
+       private int VERBOSITY_SPLITFILE_PROGRESS = 1;
+       
        public ClientPut(FCPConnectionHandler handler, ClientPutMessage 
message) {
+               this.verbosity = message.verbosity;
                this.handler = handler;
                this.identifier = message.identifier;
                this.getCHKOnly = message.getCHKOnly;
                this.priorityClass = 0;
-               ctx = new InserterContext(handler.defaultInsertContext);
+               ctx = new InserterContext(handler.defaultInsertContext, new 
SimpleEventProducer());
+               ctx.eventProducer.addEventListener(this);
                ctx.maxInsertRetries = message.maxRetries;
                // Now go through the fields one at a time
                uri = message.uri;
@@ -47,11 +58,13 @@
        }

        public void onSuccess(BaseClientPutter state) {
+               finished = true;
                FCPMessage msg = new PutSuccessfulMessage(identifier, 
state.getURI());
                handler.outputHandler.queue(msg);
        }

        public void onFailure(InserterException e, BaseClientPutter state) {
+               finished = true;
                FCPMessage msg = new PutFailedMessage(e, identifier);
                handler.outputHandler.queue(msg);
        }
@@ -69,4 +82,14 @@
                // ignore
        }

+       public void receive(ClientEvent ce) {
+               if(finished) return;
+               if(!(((verbosity & VERBOSITY_SPLITFILE_PROGRESS) == 
VERBOSITY_SPLITFILE_PROGRESS) &&
+                               (ce instanceof SplitfileProgressEvent)))
+                       return;
+               SimpleProgressMessage progress = 
+                       new SimpleProgressMessage(identifier, 
(SplitfileProgressEvent)ce);
+               handler.outputHandler.queue(progress);
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java    2006-01-26 
22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java    2006-01-26 
22:56:36 UTC (rev 7942)
@@ -33,6 +33,9 @@

        public ClientPutMessage(SimpleFieldSet fs) throws 
MessageInvalidException {
                try {
+                       String u = fs.get("URI");
+                       if(u == null)
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No URI");
                        uri = new FreenetURI(fs.get("URI"));
                } catch (MalformedURLException e) {
                        throw new 
MessageInvalidException(ProtocolErrorMessage.URI_PARSE_ERROR, e.getMessage());

Added: trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java       
2006-01-26 22:07:23 UTC (rev 7941)
+++ trunk/freenet/src/freenet/node/fcp/SimpleProgressMessage.java       
2006-01-26 22:56:36 UTC (rev 7942)
@@ -0,0 +1,36 @@
+package freenet.node.fcp;
+
+import freenet.client.events.SplitfileProgressEvent;
+import freenet.node.Node;
+import freenet.support.SimpleFieldSet;
+
+public class SimpleProgressMessage extends FCPMessage {
+
+       private final String ident;
+       private final SplitfileProgressEvent event;
+       
+       public SimpleProgressMessage(String identifier, SplitfileProgressEvent 
event) {
+               this.ident = identifier;
+               this.event = event;
+       }
+
+       public SimpleFieldSet getFieldSet() {
+               SimpleFieldSet fs = new SimpleFieldSet();
+               fs.put("Total", Integer.toString(event.totalBlocks));
+               fs.put("Required", Integer.toString(event.minSuccessfulBlocks));
+               fs.put("Failed", Integer.toString(event.failedBlocks));
+               fs.put("FatallyFailed", 
Integer.toString(event.fatallyFailedBlocks));
+               fs.put("Succeeded",Integer.toString(event.fetchedBlocks));
+               fs.put("Identifier", ident);
+               return fs;
+       }
+
+       public String getName() {
+               return "SimpleProgress";
+       }
+
+       public void run(FCPConnectionHandler handler, Node node) throws 
MessageInvalidException {
+               throw new 
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "SimpleProgress 
goes from server to client not the other way around");
+       }
+
+}


Reply via email to