On Tuesday 04 November 2008 08:35, xor at freenetproject.org wrote:
> 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);
This *should* work, but will be slow (even with an index).
It would work better to keep a copy as a String (NOT a byte[]), and query for
that. The copy can be private.
Same applies to shouldDownloadMessage() below.
> + 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);
> }
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20081111/03cb4f6a/attachment.pgp>