Author: saces
Date: 2008-08-03 12:43:09 +0000 (Sun, 03 Aug 2008)
New Revision: 21594

Modified:
   trunk/plugins/KeyExplorer/KeyExplorer.java
   trunk/plugins/KeyExplorer/VerySimpleGet.java
   trunk/plugins/KeyExplorer/VerySimpleGetter.java
Log:
add retry

Modified: trunk/plugins/KeyExplorer/KeyExplorer.java
===================================================================
--- trunk/plugins/KeyExplorer/KeyExplorer.java  2008-08-03 12:08:52 UTC (rev 
21593)
+++ trunk/plugins/KeyExplorer/KeyExplorer.java  2008-08-03 12:43:09 UTC (rev 
21594)
@@ -32,6 +32,10 @@
 import freenet.support.api.HTTPRequest;
 import freenet.support.io.BucketTools;

+/**
+ * @author saces
+ *
+ */
 public class KeyExplorer implements FredPlugin, FredPluginHTTP, FredPluginFCP, 
FredPluginThreadless, FredPluginVersioned {

        private PluginRespirator m_pr;
@@ -130,10 +134,7 @@
                        throw new MalformedURLException("Not a supported 
freenet uri: "+uri);
                }
                VerySimpleGetter vsg = new VerySimpleGetter((short) 1, 
m_pr.getNode().clientCore.requestStarters.chkFetchScheduler, m_pr
-                               
.getNode().clientCore.requestStarters.sskFetchScheduler, uri, new Object() {
-                                       public boolean persistent() {
-                                               return false;
-                                       }});
+                               
.getNode().clientCore.requestStarters.sskFetchScheduler, uri, new Object());
                VerySimpleGet vs = new VerySimpleGet(ck, 3, 
m_pr.getHLSimpleClient().getFetchContext(), vsg);
                vs.schedule();
                return new GetResult(vs.waitForCompletion(), vs.isMetadata());

Modified: trunk/plugins/KeyExplorer/VerySimpleGet.java
===================================================================
--- trunk/plugins/KeyExplorer/VerySimpleGet.java        2008-08-03 12:08:52 UTC 
(rev 21593)
+++ trunk/plugins/KeyExplorer/VerySimpleGet.java        2008-08-03 12:43:09 UTC 
(rev 21594)
@@ -1,6 +1,6 @@
-/**
- * 
- */
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
 package plugins.KeyExplorer;

 import java.io.IOException;
@@ -19,72 +19,89 @@

 /**
  * @author saces
- *
+ * 
  */
 public class VerySimpleGet extends BaseSingleFileFetcher {
-       
+
        private boolean finished = false;
        private LowLevelGetException error;
        private Bucket data;
        private final Object waiter = new Object();
        private boolean ismetadata;

-       public VerySimpleGet(ClientKey key2, int maxRetries2, FetchContext 
ctx2, ClientRequester parent2) {
+       public VerySimpleGet(ClientKey key2, int maxRetries2, FetchContext ctx2,
+                       ClientRequester parent2) {
                super(key2, maxRetries2, ctx2, parent2);
        }

-       public void onFailure(LowLevelGetException e, Object token, 
RequestScheduler sheduler) {
+       public void onFailure(LowLevelGetException e, Object token,
+                       RequestScheduler sched) {
+               boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+               if (logMINOR)
+                       Logger.minor(this, "onFailure( " + e + " , ...)", e);
+
+               if (!(isFatalError(e.code))) {
+                       if (retry(sched)) {
+                               if (logMINOR)
+                                       Logger.minor(this, "Retrying");
+                               return;
+                       }
+               }
                error = e;
                finished = true;
-               synchronized(waiter)
-               {
+               synchronized (waiter) {
                        waiter.notifyAll();
                }
        }

-       public void onSuccess(ClientKeyBlock block, boolean fromStore, Object 
token, RequestScheduler sheduler) {
+       public void onSuccess(ClientKeyBlock block, boolean fromStore,
+                       Object token, RequestScheduler scheduler) {
                data = extract(block);
                ismetadata = block.isMetadata();
-               if(data == null) return; // failed
+               if (data == null)
+                       return; // failed
                finished = true;
-               synchronized(waiter)
-               {
+               synchronized (waiter) {
                        waiter.notifyAll();
                }
        }
-       
+
        public Bucket waitForCompletion() throws LowLevelGetException {
-               while(!finished) {
+               while (!finished) {
                        try {
-                               synchronized(waiter)
-                               {
+                               synchronized (waiter) {
                                        waiter.wait();
                                }
                        } catch (InterruptedException e) {
                                // Ignore
                        }
                }
-               if(error != null) throw error;
+               if (error != null)
+                       throw error;
                return data;
        }
-       
+
        private Bucket extract(ClientKeyBlock block) {
                Bucket tempdata;
                try {
                        // FIXME What is the maximim size of an decompressed 
32K chunk?
-                       tempdata = block.decode(getContext().bucketFactory, 
1024*1024, false);
+                       tempdata = block.decode(getContext().bucketFactory, 
1024 * 1024,
+                                       false);
                } catch (KeyDecodeException e1) {
-                       if(Logger.shouldLog(Logger.MINOR, this))
-                               Logger.minor(this, "Decode failure: "+e1, e1);
-                       onFailure(new 
LowLevelGetException(LowLevelGetException.DECODE_FAILED), null, null);
+                       if (Logger.shouldLog(Logger.MINOR, this))
+                               Logger.minor(this, "Decode failure: " + e1, e1);
+                       onFailure(new LowLevelGetException(
+                                       LowLevelGetException.DECODE_FAILED), 
null, null);
                        return null;
                } catch (TooBigException e) {
-                       Logger.error(this, "Should never happens: "+e, e);
-                       onFailure(new 
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR), null, null);
+                       Logger.error(this, "Should never happens: " + e, e);
+                       onFailure(new LowLevelGetException(
+                                       LowLevelGetException.INTERNAL_ERROR), 
null, null);
                        return null;
                } catch (IOException e) {
-                       Logger.error(this, "Could not capture data - disk 
full?: "+e, e);
-                       onFailure(new 
LowLevelGetException(LowLevelGetException.DECODE_FAILED), null, null);
+                       Logger.error(this, "Could not capture data - disk 
full?: " + e, e);
+                       onFailure(new LowLevelGetException(
+                                       LowLevelGetException.DECODE_FAILED), 
null, null);
                        return null;
                }
                return tempdata;
@@ -93,4 +110,28 @@
        public boolean isMetadata() {
                return ismetadata;
        }
+
+       public static boolean isFatalError(int mode) {
+               switch (mode) {
+               // Low level errors, can be retried
+               case LowLevelGetException.DATA_NOT_FOUND:
+               case LowLevelGetException.ROUTE_NOT_FOUND:
+               case LowLevelGetException.REJECTED_OVERLOAD:
+               case LowLevelGetException.TRANSFER_FAILED:
+               case LowLevelGetException.RECENTLY_FAILED: // wait a bit, but 
fine
+                       return false;
+               case LowLevelGetException.INTERNAL_ERROR:
+                       // Maybe fatal
+                       return false;
+
+                       // Wierd ones
+               case LowLevelGetException.CANCELLED:
+                       return true;
+
+               default:
+                       Logger.error(VerySimpleGet.class,
+                                       "Do not know if error code ("+mode+") 
is fatal: " + LowLevelGetException.getMessage(mode));
+                       return false; // assume it isn't
+               }
+       }
 }

Modified: trunk/plugins/KeyExplorer/VerySimpleGetter.java
===================================================================
--- trunk/plugins/KeyExplorer/VerySimpleGetter.java     2008-08-03 12:08:52 UTC 
(rev 21593)
+++ trunk/plugins/KeyExplorer/VerySimpleGetter.java     2008-08-03 12:43:09 UTC 
(rev 21594)
@@ -1,6 +1,6 @@
-/**
- * 
- */
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
 package plugins.KeyExplorer;

 import freenet.client.async.ClientGetState;


Reply via email to