import net.pterodactylus.util.config.ConfigurationException;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
+import net.pterodactylus.util.version.Version;
import freenet.keys.FreenetURI;
/**
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class Core implements IdentityListener {
+public class Core implements IdentityListener, UpdateListener {
/**
* Enumeration for the possible states of a {@link Sone}.
/** The configuration. */
private Configuration configuration;
+ /** Whether we’re currently saving the configuration. */
+ private boolean storingConfiguration = false;
+
/** The identity manager. */
private final IdentityManager identityManager;
/** The Sone downloader. */
private final SoneDownloader soneDownloader;
+ /** The update checker. */
+ private final UpdateChecker updateChecker;
+
/** Whether the core has been stopped. */
private volatile boolean stopped;
this.freenetInterface = freenetInterface;
this.identityManager = identityManager;
this.soneDownloader = new SoneDownloader(this, freenetInterface);
+ this.updateChecker = new UpdateChecker(freenetInterface);
}
//
}
/**
+ * Returns the update checker.
+ *
+ * @return The update checker
+ */
+ public UpdateChecker getUpdateChecker() {
+ return updateChecker;
+ }
+
+ /**
* Returns the status of the given Sone.
*
* @param sone
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();
}
}
}
*/
public void start() {
loadConfiguration();
+ updateChecker.addUpdateListener(this);
+ updateChecker.start();
}
/**
soneInserter.stop();
}
}
+ updateChecker.stop();
+ updateChecker.removeUpdateListener(this);
soneDownloader.stop();
saveConfiguration();
stopped = true;
/**
* Saves the current options.
*/
- public synchronized void saveConfiguration() {
+ 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/ConfigurationVersion").setValue(0);
configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal());
configuration.getBooleanValue("Option/SoneRescueMode").setValue(options.getBooleanOption("SoneRescueMode").getReal());
configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal());
} catch (ConfigurationException ce1) {
logger.log(Level.SEVERE, "Could not store configuration!", ce1);
+ } finally {
+ synchronized (configuration) {
+ storingConfiguration = false;
+ }
}
}
/* TODO */
}
+ //
+ // INTERFACE UpdateListener
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void updateFound(Version version, long releaseTime) {
+ }
+
}