From cae31cf3d6924dfbd3fe73a6f0f954b01d96bea2 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 10 Feb 2013 09:43:52 +0200 Subject: [PATCH] retry loading of metadata --- .../meviz/htmlindexer/WebIndexer.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java index f659a35..199f789 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java @@ -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 -- 2.20.1