/** The configuration. */
private Configuration configuration;
+ /** Whether we’re currently saving the configuration. */
+ private boolean storingConfiguration = false;
+
/** The identity manager. */
private final IdentityManager identityManager;
*/
public void lockSone(Sone sone) {
synchronized (lockedSones) {
- lockedSones.add(sone);
+ if (lockedSones.add(sone)) {
+ coreListenerManager.fireSoneLocked(sone);
+ }
}
}
*/
public void unlockSone(Sone sone) {
synchronized (lockedSones) {
- lockedSones.remove(sone);
+ if (lockedSones.remove(sone)) {
+ coreListenerManager.fireSoneUnlocked(sone);
+ }
}
}
if (!soneRescueMode) {
for (Post post : storedSone.getPosts()) {
posts.remove(post.getId());
+ if (!sone.getPosts().contains(post)) {
+ coreListenerManager.firePostRemoved(post);
+ }
}
}
synchronized (newPosts) {
if (!soneRescueMode) {
for (Reply reply : storedSone.getReplies()) {
replies.remove(reply.getId());
+ if (!sone.getReplies().contains(reply)) {
+ coreListenerManager.fireReplyRemoved(reply);
+ }
}
}
synchronized (newReplies) {
* @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;
for (Post post : sone.getPosts()) {
String postPrefix = sonePrefix + "/Posts/" + postCounter++;
configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
- if (post.getRecipient() != null) {
- configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipient().getId());
- }
+ configuration.getStringValue(postPrefix + "/Recipient").setValue((post.getRecipient() != null) ? post.getRecipient().getId() : null);
configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
}
}
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);
if (newPosts.remove(post.getId())) {
knownPosts.add(post.getId());
coreListenerManager.fireMarkPostKnown(post);
+ saveConfiguration();
}
}
}
if (newReplies.remove(reply.getId())) {
knownReplies.add(reply.getId());
coreListenerManager.fireMarkReplyKnown(reply);
+ saveConfiguration();
}
}
}
soneInserter.stop();
}
}
+ soneDownloader.stop();
saveConfiguration();
stopped = true;
}
* 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());
} catch (ConfigurationException ce1) {
logger.log(Level.SEVERE, "Could not store configuration!", ce1);
+ } finally {
+ synchronized (configuration) {
+ storingConfiguration = false;
+ }
}
}