Author: xor
Date: 2008-11-01 14:16:34 +0000 (Sat, 01 Nov 2008)
New Revision: 23281
Modified:
trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java
Log:
Use db4o instead of Hashtable of all messages.
Modified: trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java
===================================================================
--- trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java 2008-11-01
14:16:17 UTC (rev 23280)
+++ trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java 2008-11-01
14:16:34 UTC (rev 23281)
@@ -9,6 +9,10 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import com.db4o.query.Query;
+
import freenet.keys.FreenetURI;
import freenet.support.UpdatableSortedLinkedList;
import freenet.support.UpdatableSortedLinkedListKilledException;
@@ -19,9 +23,14 @@
import plugins.FMSPlugin.FMSMessage;
import plugins.FMSPlugin.FMSMessageManager;
import plugins.FMSPlugin.FMSOwnIdentity;
+import plugins.WoT.Identity;
+import plugins.WoT.exceptions.DuplicateIdentityException;
+import plugins.WoT.exceptions.UnknownIdentityException;
public class FMSMessageManagerWoT implements FMSMessageManager {
+ private ObjectContainer db;
+
/**
* Contains all boards which where found in a message. References to
all messages of a board are stored in
* the board. Adding a newly downloaded message therefore is done by
searching its board and calling
@@ -29,16 +38,15 @@
*/
private UpdatableSortedLinkedListWithForeignIndex mBoards = new
UpdatableSortedLinkedListWithForeignIndex();
- /**
- * Contains all messages, even though they are also stored in their
FMSBoard. Used for checking whether
- * a message was already downloaded or not.
- */
- private Hashtable<FreenetURI, FMSMessageWoT> mMessages = new
Hashtable<FreenetURI, FMSMessageWoT>();
-
private ArrayList<FMSOwnIdentityWoT> mOwnIdentites = new
ArrayList<FMSOwnIdentityWoT>();
- public FMSMessage get(FreenetURI uri) {
- return mMessages.get(uri);
+ public synchronized FMSMessage get(FreenetURI uri) {
+ Query query = db.query();
+ query.constrain(FMSMessage.class);
+ query.descend("mURI").constrain(uri);
+ ObjectSet<FMSMessage> result = query.execute();
+
+ return (result.size() == 0) ? null : result.next();
}
public synchronized FMSBoard getBoardByName(String name) {
@@ -50,7 +58,14 @@
}
private synchronized boolean shouldDownloadMessage(FreenetURI uri) {
- return (mMessages.containsKey(uri));
+ Query query = db.query();
+ query.constrain(FMSMessage.class);
+ query.descend("mURI").constrain(uri);
+ ObjectSet<FMSMessage> result = query.execute();
+
+ assert (result.size() <= 1); /* Duplicate messages */
+
+ return (result.size() == 0);
}
private synchronized void onMessageReceived(String newMessageData)
throws UpdatableSortedLinkedListKilledException {
@@ -63,7 +78,11 @@
mBoards.add(board);
}
- mMessages.put(newMessage.getURI(), newMessage);
+ db.store(newMessage);
+ db.commit();
board.addMessage(newMessage);
+
+ db.store(board);
+ db.commit();
}
}