From: David ‘Bombe’ Roden Date: Fri, 31 Aug 2012 08:46:48 +0000 (+0200) Subject: Make sure we have a connection to the node before checking for updates. X-Git-Tag: 0.11^2~12 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6ade8115edbcc68c531e4ea115dd0d0389ac3285;p=jSite.git Make sure we have a connection to the node before checking for updates. --- diff --git a/src/main/java/de/todesbaum/jsite/application/UpdateChecker.java b/src/main/java/de/todesbaum/jsite/application/UpdateChecker.java index bd3b14f..0c78010 100644 --- a/src/main/java/de/todesbaum/jsite/application/UpdateChecker.java +++ b/src/main/java/de/todesbaum/jsite/application/UpdateChecker.java @@ -193,17 +193,31 @@ public class UpdateChecker implements Runnable { */ @Override public void run() { - Connection connection = freenetInterface.getConnection("jSite-" + ++counter + "-UpdateChecker"); - try { - connection.connect(); - } catch (IOException e1) { - e1.printStackTrace(); - } - Client client = new Client(connection); - boolean checkNow = false; int currentEdition = lastUpdateEdition; while (!shouldStop()) { - checkNow = false; + + /* try to connect. */ + Client client; + while (true) { + Connection connection = freenetInterface.getConnection("jSite-" + ++counter + "-UpdateChecker"); + try { + connection.connect(); + logger.log(Level.INFO, "Connected to " + freenetInterface.getNode() + "."); + client = new Client(connection); + break; + } catch (IOException ioe1) { + logger.log(Level.INFO, "Could not connect to " + freenetInterface.getNode() + ".", ioe1); + } + if (!connection.isConnected()) { + try { + Thread.sleep(60 * 1000); + } catch (InterruptedException ie1) { + /* ignore, we’re looping. */ + } + } + } + + boolean checkNow = false; logger.log(Level.FINE, "Trying " + constructUpdateKey(currentEdition)); ClientGet clientGet = new ClientGet("get-update-key"); clientGet.setUri(constructUpdateKey(currentEdition));