import net.pterodactylus.sone.freenet.wot.IdentityListener;
import net.pterodactylus.sone.freenet.wot.IdentityManager;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
-import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.util.config.Configuration;
import net.pterodactylus.util.config.ConfigurationException;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.service.AbstractService;
+import net.pterodactylus.util.thread.NamedThreadFactory;
import net.pterodactylus.util.thread.Ticker;
import net.pterodactylus.util.validation.EqualityValidator;
import net.pterodactylus.util.validation.IntegerRangeValidator;
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
+ /** The start time. */
+ private final long startupTime = System.currentTimeMillis();
+
/** The options. */
private final Options options = new Options();
private final ImageInserter imageInserter;
/** Sone downloader thread-pool. */
- private final ExecutorService soneDownloaders = Executors.newFixedThreadPool(10);
+ private final ExecutorService soneDownloaders = Executors.newFixedThreadPool(10, new NamedThreadFactory("Sone Downloader %2$d"));
/** The update checker. */
private final UpdateChecker updateChecker;
//
/**
+ * Returns the time Sone was started.
+ *
+ * @return The startup time (in milliseconds since Jan 1, 1970 UTC)
+ */
+ public long getStartupTime() {
+ return startupTime;
+ }
+
+ /**
* Sets the configuration to use. This will automatically save the current
* configuration to the given configuration.
*
}
/**
- * Retrieves the trust relationship from the origin to the target. If the
- * trust relationship can not be retrieved, {@code null} is returned.
- *
- * @see Identity#getTrust(OwnIdentity)
- * @param origin
- * The origin of the trust tree
- * @param target
- * The target of the trust
- * @return The trust relationship
- */
- public Trust getTrust(Sone origin, Sone target) {
- if (!isLocalSone(origin)) {
- logger.log(Level.WARNING, String.format("Tried to get trust from remote Sone: %s", origin));
- return null;
- }
- webOfTrustUpdater.getTrust((OwnIdentity) origin.getIdentity(), target.getIdentity());
- return target.getIdentity().getTrust((OwnIdentity) origin.getIdentity());
- }
-
- /**
* Sets the trust value of the given origin Sone for the target Sone.
*
* @param origin
if (!storedPosts.contains(post)) {
if (post.getTime() < getSoneFollowingTime(sone)) {
knownPosts.add(post.getId());
+ post.setKnown(true);
} else if (!knownPosts.contains(post.getId())) {
- sone.setKnown(false);
coreListenerManager.fireNewPostFound(post);
}
}
if (!storedReplies.contains(reply)) {
if (reply.getTime() < getSoneFollowingTime(sone)) {
knownReplies.add(reply.getId());
+ reply.setKnown(true);
} else if (!knownReplies.contains(reply.getId())) {
- reply.setKnown(false);
coreListenerManager.fireNewReplyFound(reply);
}
}
@Override
public void serviceStop() {
synchronized (localSones) {
- for (SoneInserter soneInserter : soneInserters.values()) {
- soneInserter.removeSoneInsertListener(this);
- soneInserter.stop();
+ for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
+ soneInserter.getValue().removeSoneInsertListener(this);
+ soneInserter.getValue().stop();
+ saveSone(soneInserter.getKey());
}
}
+ saveConfiguration();
webOfTrustUpdater.stop();
updateChecker.stop();
updateChecker.removeUpdateListener(this);
* The URI to derive the Sone URI from
* @return The derived URI
*/
- private FreenetURI getSoneUri(String uriString) {
+ private static FreenetURI getSoneUri(String uriString) {
try {
FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]);
return uri;
} catch (MalformedURLException mue1) {
- logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uriString, mue1));
+ logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uriString), mue1);
return null;
}
}
*/
@Override
public void identityUpdated(OwnIdentity ownIdentity, final Identity identity) {
- new Thread(new Runnable() {
+ soneDownloaders.execute(new Runnable() {
@Override
@SuppressWarnings("synthetic-access")
soneDownloader.addSone(sone);
soneDownloader.fetchSone(sone);
}
- }).start();
+ });
}
/**