/* synchronize access on this on itself. */
private Map<String, Sone> remoteSones = new HashMap<String, Sone>();
+ /** All new Sones. */
+ private Set<Sone> newSones = new HashSet<Sone>();
+
/** All posts. */
private Map<String, Post> posts = new HashMap<String, Post>();
}
/**
+ * Returns whether the Sone with the given ID is a remote Sone.
+ *
+ * @param id
+ * The ID of the Sone to check
+ * @return {@code true} if the Sone with the given ID is a remote Sone,
+ * {@code false} otherwise
+ */
+ public boolean isRemoteSone(String id) {
+ synchronized (remoteSones) {
+ return remoteSones.containsKey(id);
+ }
+ }
+
+ /**
+ * Returns whether the given Sone is a new Sone. After this check, the Sone
+ * is marked as known, i.e. a second call with the same parameters will
+ * always yield {@code false}.
+ *
+ * @param sone
+ * The sone to check for
+ * @return {@code true} if the given Sone is new, false otherwise
+ */
+ public boolean isNewSone(Sone sone) {
+ synchronized (newSones) {
+ return newSones.remove(sone);
+ }
+ }
+
+ /**
* Returns the post with the given ID.
*
* @param postId
soneInserter.start();
setSoneStatus(sone, SoneStatus.idle);
loadSone(sone);
+ new Thread(new Runnable() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ soneDownloader.fetchSone(sone);
+ }
+
+ }, "Sone Downloader").start();
return sone;
}
}
return null;
}
synchronized (remoteSones) {
+ boolean newSone = !isRemoteSone(identity.getId());
final Sone sone = getRemoteSone(identity.getId()).setIdentity(identity);
- sone.setRequestUri(getSoneUri(identity.getRequestUri(), identity.getProperty("Sone.LatestEdition")));
+ sone.setRequestUri(getSoneUri(identity.getRequestUri()));
+ sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
+ if (newSone) {
+ synchronized (newSones) {
+ newSones.add(sone);
+ }
+ }
remoteSones.put(identity.getId(), sone);
soneDownloader.addSone(sone);
+ setSoneStatus(sone, SoneStatus.unknown);
new Thread(new Runnable() {
@Override
}
}, "Sone Downloader").start();
- setSoneStatus(sone, SoneStatus.idle);
return sone;
}
}
storedSone.setLikePostIds(sone.getLikedPostIds());
storedSone.setLikeReplyIds(sone.getLikedReplyIds());
storedSone.setLatestEdition(sone.getRequestUri().getEdition());
+ storedSone.setModificationCounter(0);
}
- saveSone(storedSone);
}
}
String sonePrefix = "Sone/" + sone.getId();
Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
if (soneTime == null) {
- logger.log(Level.INFO, "Could not load Sone because there is no Sone has been saved.");
+ logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
return;
}
long soneModificationCounter = configuration.getLongValue(sonePrefix + "/ModificationCounter").getValue((long) 0);
*
* @param uriString
* The URI to derive the Sone URI from
- * @param latestEditionString
- * The latest edition as a {@link String}, or {@code null}
* @return The derived URI
*/
- private FreenetURI getSoneUri(String uriString, String latestEditionString) {
+ private FreenetURI getSoneUri(String uriString) {
try {
- FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]).setSuggestedEdition(Numbers.safeParseLong(latestEditionString, (long) 0));
+ FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]);
return uri;
} catch (MalformedURLException mue1) {
logger.log(Level.WARNING, "Could not create Sone URI from URI: " + uriString, mue1);
*/
@Override
public void ownIdentityRemoved(OwnIdentity ownIdentity) {
- /* TODO */
+ logger.log(Level.FINEST, "Removing OwnIdentity: " + ownIdentity);
}
/**
* {@inheritDoc}
*/
@Override
- public void identityUpdated(Identity identity) {
- /* TODO */
+ public void identityUpdated(final Identity identity) {
+ new Thread(new Runnable() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ Sone sone = getRemoteSone(identity.getId());
+ soneDownloader.fetchSone(sone);
+ }
+ }).start();
}
/**