Author: xor
Date: 2008-11-04 08:35:43 +0000 (Tue, 04 Nov 2008)
New Revision: 23304
Modified:
trunk/plugins/FMSPlugin/FMSMessageManager.java
trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java
Log:
Move code upwards in the class hierarchy.
Modified: trunk/plugins/FMSPlugin/FMSMessageManager.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSMessageManager.java 2008-11-04 00:50:58 UTC
(rev 23303)
+++ trunk/plugins/FMSPlugin/FMSMessageManager.java 2008-11-04 08:35:43 UTC
(rev 23304)
@@ -5,22 +5,55 @@
import java.util.Iterator;
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import com.db4o.query.Query;
+
import freenet.keys.FreenetURI;
+import freenet.support.UpdatableSortedLinkedListWithForeignIndex;
/**
* @author xor
*
*/
-public interface FMSMessageManager {
+public abstract class FMSMessageManager {
- public FMSMessage get(FreenetURI uri);
+ protected ObjectContainer db;
- public FMSBoard getBoardByName(String name);
+ /**
+ * 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
+ * <code>addMessage()</code> on that board. Further, the message is
also added to mMessages, see below.
+ */
+ protected UpdatableSortedLinkedListWithForeignIndex mBoards = new
UpdatableSortedLinkedListWithForeignIndex();
+ 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) {
+ return (FMSBoard)mBoards.get(name);
+ }
+
/**
* Get an iterator of boards which the identity could subscribe to.
* @param identity
* @return
*/
- public Iterator<FMSBoard> boardIterator(FMSOwnIdentity identity);
+ public synchronized Iterator<FMSBoard> boardIterator(FMSOwnIdentity
identity) {
+ return (Iterator<FMSBoard>)mBoards.iterator();
+ }
+
+
+ /**
+ * Returns true if the message was not downloaded yet and any of the
FMSOwnIdentity wants the message.
+ * @param uri
+ * @return
+ */
+ protected abstract boolean shouldDownloadMessage(FreenetURI uri);
}
Modified: trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java
===================================================================
--- trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java 2008-11-04
00:50:58 UTC (rev 23303)
+++ trunk/plugins/FMSPlugin/WoT/FMSMessageManagerWoT.java 2008-11-04
08:35:43 UTC (rev 23304)
@@ -28,42 +28,14 @@
import plugins.WoT.exceptions.DuplicateIdentityException;
import plugins.WoT.exceptions.UnknownIdentityException;
-public class FMSMessageManagerWoT implements FMSMessageManager {
+public class FMSMessageManagerWoT extends 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
- * <code>addMessage()</code> on that board. Further, the message is
also added to mMessages, see below.
- */
- private UpdatableSortedLinkedListWithForeignIndex mBoards = new
UpdatableSortedLinkedListWithForeignIndex();
-
- private ArrayList<FMSOwnIdentityWoT> mOwnIdentites = new
ArrayList<FMSOwnIdentityWoT>();
-
- public synchronized FMSMessage get(FreenetURI uri) {
+ protected synchronized boolean shouldDownloadMessage(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) {
- return (FMSBoard)mBoards.get(name);
- }
-
- public synchronized Iterator<FMSBoard> boardIterator(FMSOwnIdentity
identity) {
- return (Iterator<FMSBoard>)mBoards.iterator();
- }
-
- private synchronized boolean shouldDownloadMessage(FreenetURI uri) {
- Query query = db.query();
- query.constrain(FMSMessage.class);
- query.descend("mURI").constrain(uri);
- ObjectSet<FMSMessage> result = query.execute();
-
if(result.size() > 1) { /* Duplicate messages */
assert(false);
/* FIXME: Add logging!*/
@@ -74,7 +46,7 @@
return (result.size() == 0);
}
- private synchronized void deleteMessage(FreenetURI uri) throws
NoSuchElementException {
+ protected synchronized void deleteMessage(FreenetURI uri) throws
NoSuchElementException {
/* FIXME: implement */
}