Added support for registering listeners with the database that are

called when new messages are available, and a new method
hasSendableMessages(ContactId) that listeners can call to see whether
it's worth trying to create a batch.
This commit is contained in:
akwizgran
2011-07-27 20:27:43 +01:00
parent e93fbe0b20
commit adee3e121c
10 changed files with 364 additions and 99 deletions

View File

@@ -48,6 +48,12 @@ public interface DatabaseComponent {
/** Waits for any open transactions to finish and closes the database. */
void close() throws DbException;
/** Adds a listener to be notified when new messages are available. */
void addListener(MessageListener m);
/** Removes a listener. */
void removeListener(MessageListener m);
/**
* Adds a new contact to the database with the given transport details and
* returns an ID for the contact.
@@ -112,6 +118,9 @@ public interface DatabaseComponent {
/** Returns the contacts to which the given group is visible. */
Collection<ContactId> getVisibility(GroupId g) throws DbException;
/** Returns true if any messages are sendable to the given contact. */
boolean hasSendableMessages(ContactId c) throws DbException;
/** Processes an acknowledgement from the given contact. */
void receiveAck(ContactId c, Ack a) throws DbException;

View File

@@ -0,0 +1,10 @@
package net.sf.briar.api.db;
/**
* An interface for receiving notifications when the database may have new
* messages available.
*/
public interface MessageListener {
void messagesAdded();
}