retry loading of metadata
authorSvjatoslav Agejenko <n0@n0-Aspire-8920.(none)>
Sun, 10 Feb 2013 07:43:52 +0000 (09:43 +0200)
committerSvjatoslav Agejenko <n0@n0-Aspire-8920.(none)>
Sun, 10 Feb 2013 07:43:52 +0000 (09:43 +0200)
src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java

index f659a35..199f789 100644 (file)
@@ -16,6 +16,7 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 
 public class WebIndexer extends AbstractIndexer {
 
+       private static final int METADATA_LOAD_TRY_COUNT = 10;
        private final String globalPrefix;
        private final String jspPath;
 
@@ -50,7 +51,7 @@ public class WebIndexer extends AbstractIndexer {
        }
 
        public DirectoryMetadata getMetadataForPath(final String requestPath)
-                       throws IOException, MalformedURLException, ClassNotFoundException {
+                       throws ClassNotFoundException, IOException {
 
                final StringBuffer urlStringBuffer = new StringBuffer();
 
@@ -60,15 +61,25 @@ public class WebIndexer extends AbstractIndexer {
 
                final String urlString = urlStringBuffer.toString();
 
-               final BufferedInputStream in = new BufferedInputStream(new URL(
-                               urlString).openStream());
+               IOException exception = null;
 
-               final ObjectInputStream oin = new ObjectInputStream(in);
-               final DirectoryMetadata directory = (DirectoryMetadata) oin
-                               .readObject();
-               in.close();
+               for (int i = 0; i < METADATA_LOAD_TRY_COUNT; i++)
+                       try {
 
-               return directory;
+                               final BufferedInputStream in = new BufferedInputStream(new URL(
+                                               urlString).openStream());
+
+                               final ObjectInputStream oin = new ObjectInputStream(in);
+                               final DirectoryMetadata directory = (DirectoryMetadata) oin
+                                               .readObject();
+                               in.close();
+
+                               return directory;
+                       } catch (final IOException e) {
+                               exception = e;
+                       }
+
+               throw exception;
        }
 
        @Override