Author: toad
Date: 2008-04-16 18:29:03 +0000 (Wed, 16 Apr 2008)
New Revision: 19375

Modified:
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
Try 5 times to load the plugin.

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2008-04-16 
18:18:34 UTC (rev 19374)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2008-04-16 
18:29:03 UTC (rev 19375)
@@ -502,7 +502,10 @@
                if (logMINOR) {
                        Logger.minor(this, "plugin file " + 
pluginFile.getAbsolutePath() + " exists: " + pluginFile.exists());
                }
+               int RETRIES = 5;
+               for(int i=0;i<RETRIES;i++) {
                if (!pluginFile.exists() || pluginFile.length() == 0) {
+                       try {
                        File tempPluginFile = null;
                        OutputStream pluginOutputStream = null;
                        URLConnection urlConnection = null;
@@ -520,7 +523,9 @@
                                while ((read = pluginInputStream.read(buffer)) 
!= -1) {
                                        pluginOutputStream.write(buffer, 0, 
read);
                                }
-                               pluginOutputStream.close();               
+                               pluginOutputStream.close();
+                               if(tempPluginFile.length() == 0)
+                                       throw new 
PluginNotFoundException("downloaded zero length file");
                                if(!FileUtil.renameTo(tempPluginFile, 
pluginFile)) {
                                        Logger.error(this, "could not rename 
temp file to plugin file");
                                        throw new 
PluginNotFoundException("could not rename temp file to plugin file");
@@ -535,7 +540,14 @@
                                Closer.close(pluginOutputStream);
                                Closer.close(pluginInputStream);
                        }
+                       } catch (PluginNotFoundException e) {
+                               if(i < RETRIES-1) {
+                                       Logger.normal(this, "Failed to load 
plugin: "+e, e);
+                                       continue;
+                               } else throw e;
+                       }
                }
+               }

                /* now get the manifest file. */
                JarFile pluginJarFile = null;


Reply via email to