Factor MessageTracker out of BdfIncomingMessageHook.

This commit is contained in:
akwizgran
2016-11-11 16:55:06 +00:00
parent ab16ee7465
commit aa210fc555
46 changed files with 628 additions and 379 deletions

View File

@@ -1,14 +1,15 @@
package org.briarproject.api.clients;
import org.briarproject.api.FormatException;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Metadata;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.InvalidMessageException;
import org.briarproject.api.sync.MessageContext;
@NotNullByDefault
public interface MessageQueueManager {
/**
@@ -52,17 +53,17 @@ public interface MessageQueueManager {
*
* @throws DbException Should only be used for real database errors.
* If this is thrown, delivery will be attempted again at next startup,
* whereas if an FormatException is thrown,
* whereas if an InvalidMessageException is thrown,
* the message will be permanently invalidated.
* @throws FormatException for any non-database error
* @throws InvalidMessageException for any non-database error
* that occurs while handling remotely created data.
* This includes errors that occur while handling locally created data
* in a context controlled by remotely created data
* (for example, parsing the metadata of a dependency
* of an incoming message).
* Never rethrow DbException as FormatException!
* Never rethrow DbException as InvalidMessageException!
*/
void incomingMessage(Transaction txn, QueueMessage q, Metadata meta)
throws DbException, FormatException;
throws DbException, InvalidMessageException;
}
}

View File

@@ -1,9 +1,13 @@
package org.briarproject.api.clients;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
@NotNullByDefault
public interface MessageTracker {
/**
@@ -13,11 +17,34 @@ public interface MessageTracker {
GroupCount getGroupCount(GroupId g) throws DbException;
/**
* Marks a message as read or unread and updates the group counts in g.
* Gets the number of visible and unread messages in the group
* as well as the timestamp of the latest message
**/
GroupCount getGroupCount(Transaction txn, GroupId g) throws DbException;
/**
* Updates the group count for the given incoming message.
*/
void trackIncomingMessage(Transaction txn, Message m) throws DbException;
/**
* Updates the group count for the given outgoing message.
*/
void trackOutgoingMessage(Transaction txn, Message m) throws DbException;
/**
* Updates the group count for the given message.
*/
void trackMessage(Transaction txn, GroupId g, long timestamp, boolean read)
throws DbException;
/**
* Marks a message as read or unread and updates the group count.
*/
void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException;
class GroupCount {
private final int msgCount, unreadCount;
private final long latestMsgTime;