X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=f7b56a1022a952130bb51b4de661a5185f0efc9a;hb=4a2fdf3b0b3dfcfc761c83797018237ec4c82a4b;hp=d688f71fc4f17e1b85fa3a871ecf5e245e6c6022;hpb=7b4bfb180ff840c52a624b39038a837fa7ce564c;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index d688f71..f7b56a1 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -88,6 +88,9 @@ public class Core implements IdentityListener { /** The configuration. */ private Configuration configuration; + /** Whether we’re currently saving the configuration. */ + private boolean storingConfiguration = false; + /** The identity manager. */ private final IdentityManager identityManager; @@ -728,7 +731,9 @@ public class Core implements IdentityListener { */ public void lockSone(Sone sone) { synchronized (lockedSones) { - lockedSones.add(sone); + if (lockedSones.add(sone)) { + coreListenerManager.fireSoneLocked(sone); + } } } @@ -741,7 +746,9 @@ public class Core implements IdentityListener { */ public void unlockSone(Sone sone) { synchronized (lockedSones) { - lockedSones.remove(sone); + if (lockedSones.remove(sone)) { + coreListenerManager.fireSoneUnlocked(sone); + } } } @@ -1166,7 +1173,7 @@ public class Core implements IdentityListener { * @param sone * The Sone to save */ - public void saveSone(Sone sone) { + public synchronized void saveSone(Sone sone) { if (!isLocalSone(sone)) { logger.log(Level.FINE, "Tried to save non-local Sone: %s", sone); return; @@ -1237,6 +1244,7 @@ public class Core implements IdentityListener { } configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null); + configuration.save(); logger.log(Level.INFO, "Sone %s saved.", sone); } catch (ConfigurationException ce1) { logger.log(Level.WARNING, "Could not save Sone: " + sone, ce1); @@ -1353,6 +1361,7 @@ public class Core implements IdentityListener { if (newPosts.remove(post.getId())) { knownPosts.add(post.getId()); coreListenerManager.fireMarkPostKnown(post); + saveConfiguration(); } } } @@ -1433,6 +1442,7 @@ public class Core implements IdentityListener { if (newReplies.remove(reply.getId())) { knownReplies.add(reply.getId()); coreListenerManager.fireMarkReplyKnown(reply); + saveConfiguration(); } } } @@ -1453,6 +1463,7 @@ public class Core implements IdentityListener { soneInserter.stop(); } } + soneDownloader.stop(); saveConfiguration(); stopped = true; } @@ -1461,6 +1472,14 @@ public class Core implements IdentityListener { * Saves the current options. */ public void saveConfiguration() { + synchronized (configuration) { + if (storingConfiguration) { + logger.log(Level.FINE, "Already storing configuration…"); + return; + } + storingConfiguration = true; + } + /* store the options first. */ try { configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal()); @@ -1500,6 +1519,10 @@ public class Core implements IdentityListener { } catch (ConfigurationException ce1) { logger.log(Level.SEVERE, "Could not store configuration!", ce1); + } finally { + synchronized (configuration) { + storingConfiguration = false; + } } }