Author: toad
Date: 2006-07-26 16:31:52 +0000 (Wed, 26 Jul 2006)
New Revision: 9774

Modified:
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/ClientPutter.java
   trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
   trunk/freenet/src/freenet/node/Version.java
Log:
905: Cancellation of requests during STARTING phase should now work. (at least 
for inserts)

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-07-26 
16:04:05 UTC (rev 9773)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-07-26 
16:31:52 UTC (rev 9774)
@@ -63,8 +63,10 @@
                                                uri, ctx, actx, 
ctx.maxNonSplitfileRetries, 0, false, null, true,
                                                returnBucket);
                        }
+                       if(cancelled) cancel();
                        if(currentState != null)
                                currentState.schedule();
+                       if(cancelled) cancel();
                } catch (MalformedURLException e) {
                        throw new FetchException(FetchException.INVALID_URI, e);
                }

Modified: trunk/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientPutter.java    2006-07-26 
16:04:05 UTC (rev 9773)
+++ trunk/freenet/src/freenet/client/async/ClientPutter.java    2006-07-26 
16:31:52 UTC (rev 9774)
@@ -23,6 +23,7 @@
        private boolean finished;
        private final boolean getCHKOnly;
        private final boolean isMetadata;
+       private boolean startedStarting;
        private FreenetURI uri;
        /** SimpleFieldSet containing progress information from last startup.
         * Will be progressively cleared during startup. */
@@ -61,12 +62,36 @@
        public void start() throws InserterException {
                Logger.minor(this, "Starting "+this);
                try {
+                       boolean cancel = false;
                        synchronized(this) {
+                               if(startedStarting) return;
+                               startedStarting = true;
                                if(currentState != null) return;
-                               currentState =
-                                       new SingleFileInserter(this, this, new 
InsertBlock(data, cm, targetURI), isMetadata, ctx, false, getCHKOnly, false, 
null, false);
+                               cancel = this.cancelled;
+                               if(!cancel) {
+                                       currentState =
+                                               new SingleFileInserter(this, 
this, new InsertBlock(data, cm, targetURI), isMetadata, ctx, false, getCHKOnly, 
false, null, false);
+                               }
                        }
+                       if(cancel) {
+                               onFailure(new 
InserterException(InserterException.CANCELLED), null);
+                               return;
+                       }
+                       synchronized(this) {
+                               cancel = cancelled;
+                       }
+                       if(cancel) {
+                               onFailure(new 
InserterException(InserterException.CANCELLED), null);
+                               return;
+                       }
                        ((SingleFileInserter)currentState).start(oldProgress);
+                       synchronized(this) {
+                               cancel = cancelled;
+                       }
+                       if(cancel) {
+                               onFailure(new 
InserterException(InserterException.CANCELLED), null);
+                               return;
+                       }
                } catch (InserterException e) {
                        Logger.error(this, "Failed to start insert: "+e, e);
                        synchronized(this) {
@@ -106,10 +131,16 @@
                client.onGeneratedURI(uri, this);
        }

-       public synchronized void cancel() {
-               super.cancel();
-               if(currentState != null)
-                       currentState.cancel();
+       public void cancel() {
+               synchronized(this) {
+                       if(cancelled) return;
+                       super.cancel();
+                       if(currentState != null)
+                               currentState.cancel();
+                       if(startedStarting) return;
+                       startedStarting = true;
+               }
+               onFailure(new InserterException(InserterException.CANCELLED), 
null);
        }

        public synchronized boolean isFinished() {

Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-07-26 16:04:05 UTC (rev 9773)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-07-26 16:31:52 UTC (rev 9774)
@@ -219,11 +219,13 @@
                PutHandler[] running;
                running = (PutHandler[]) runningPutHandlers.toArray(new 
PutHandler[runningPutHandlers.size()]);

+               if(cancelled) cancel();
                try {
                        for(int i=0;i<running.length;i++) {
                                running[i].start();
                        }
                        Logger.minor(this, "Started "+running.length+" 
PutHandler's for "+this);
+                       if(cancelled) cancel();
                        if(running.length == 0) {
                                insertedAllFiles = true;
                                gotAllMetadata();
@@ -508,6 +510,10 @@
                }
        }

+       public void cancel() {
+               fail(new InserterException(InserterException.CANCELLED));
+       }
+       
        public void onSuccess(ClientPutState state) {
                synchronized(this) {
                        metadataPuttersByMetadata.remove(state.getToken());

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-07-26 16:04:05 UTC (rev 
9773)
+++ trunk/freenet/src/freenet/node/Version.java 2006-07-26 16:31:52 UTC (rev 
9774)
@@ -18,7 +18,7 @@
        public static final String protocolVersion = "1.0";

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

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


Reply via email to