From: David ‘Bombe’ Roden Date: Mon, 10 Sep 2012 11:06:55 +0000 (+0200) Subject: Make it possible for update jobs to return whether they were successful. X-Git-Tag: 0.8.3^2~49 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=cfbde5f4b68cb6e185aa1ea1d0b2dcfc4d224cb2 Make it possible for update jobs to return whether they were successful. --- diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java index cfb9932..0ee5a2c 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java @@ -170,6 +170,9 @@ public class WebOfTrustUpdater extends AbstractService { /** Whether the job has finished. */ private boolean finished; + /** Whether the job was successful. */ + private boolean success; + // // ACTIONS // @@ -187,10 +190,13 @@ public class WebOfTrustUpdater extends AbstractService { * Waits for completion of this job or stopping of the WebOfTrust * updater. * + * @return {@code true} if this job finished successfully, {@code false} + * otherwise + * * @see WebOfTrustUpdater#stop() */ @SuppressWarnings("synthetic-access") - public void waitForCompletion() { + public boolean waitForCompletion() { synchronized (syncObject) { while (!finished && !shouldStop()) { try { @@ -199,6 +205,7 @@ public class WebOfTrustUpdater extends AbstractService { /* we’re looping, ignore. */ } } + return success; } } @@ -208,10 +215,15 @@ public class WebOfTrustUpdater extends AbstractService { /** * Signals that this job has finished. + * + * @param success + * {@code true} if this job finished successfully, + * {@code false} otherwise */ - protected void finish() { + protected void finish(boolean success) { synchronized (syncObject) { finished = true; + this.success = success; syncObject.notifyAll(); } } @@ -329,10 +341,11 @@ public class WebOfTrustUpdater extends AbstractService { } webOfTrustConnector.removeTrust(truster, trustee); } + finish(true); } catch (WebOfTrustException wote1) { logger.log(Level.WARNING, "Could not set Trust value for " + truster + " -> " + trustee + " to " + score + " (" + comment + ")!", wote1); + finish(false); } - finish(); } } @@ -367,10 +380,11 @@ public class WebOfTrustUpdater extends AbstractService { if (trustee instanceof DefaultIdentity) { ((DefaultIdentity) trustee).setTrust(truster, trust); } + finish(true); } catch (PluginException pe1) { logger.log(Level.WARNING, "Could not get Trust value for " + truster + " -> " + trustee + "!", pe1); + finish(false); } - finish(); } }