Builders for batches and bundles.

This commit is contained in:
akwizgran
2011-07-11 12:25:04 +01:00
parent 51e371f7ca
commit 4f5eb21180
13 changed files with 162 additions and 119 deletions

View File

@@ -7,6 +7,7 @@ import net.sf.briar.api.ContactId;
import net.sf.briar.api.Rating;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.Bundle;
import net.sf.briar.api.protocol.BundleBuilder;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Message;
@@ -48,7 +49,7 @@ public interface DatabaseComponent {
* Generates a bundle of acknowledgements, subscriptions, and batches of
* messages for the given contact.
*/
void generateBundle(ContactId c, Bundle b) throws DbException;
Bundle generateBundle(ContactId c, BundleBuilder bundleBuilder) throws DbException;
/** Returns the IDs of all contacts. */
Set<ContactId> getContacts() throws DbException;

View File

@@ -5,12 +5,7 @@ public interface Batch {
public static final long CAPACITY = 1024L * 1024L;
/** Prepares the batch for transmission and generates its identifier. */
public void seal();
/**
* Returns the batch's unique identifier. Cannot be called before seal().
*/
/** Returns the batch's unique identifier. */
BatchId getId();
/** Returns the size of the batch in bytes. */
@@ -18,7 +13,4 @@ public interface Batch {
/** Returns the messages contained in the batch. */
Iterable<Message> getMessages();
/** Adds a message to the batch. Cannot be called after seal(). */
void addMessage(Message m);
}

View File

@@ -0,0 +1,10 @@
package net.sf.briar.api.protocol;
public interface BatchBuilder {
/** Adds a message to the batch. */
void addMessage(Message m);
/** Builds and returns the batch. */
Batch build();
}

View File

@@ -5,12 +5,7 @@ import java.util.Map;
/** A bundle of acknowledgements, subscriptions, and batches of messages. */
public interface Bundle {
/** Prepares the bundle for transmission and generates its identifier. */
public void seal();
/**
* Returns the bundle's unique identifier. Cannot be called before seal().
*/
/** Returns the bundle's unique identifier. */
BundleId getId();
/** Returns the bundle's capacity in bytes. */
@@ -22,26 +17,12 @@ public interface Bundle {
/** Returns the acknowledgements contained in the bundle. */
Iterable<BatchId> getAcks();
/** Adds an acknowledgement to the bundle. Cannot be called after seal(). */
void addAck(BatchId b);
/** Returns the subscriptions contained in the bundle. */
Iterable<GroupId> getSubscriptions();
/** Adds a subscription to the bundle. Cannot be called after seal(). */
void addSubscription(GroupId g);
/** Returns the transport details contained in the bundle. */
Map<String, String> getTransports();
/** Adds a transport detail to the bundle. Cannot be called after seal(). */
void addTransport(String key, String value);
/** Returns the batches of messages contained in the bundle. */
Iterable<Batch> getBatches();
/**
* Adds a batch of messages to the bundle. Cannot be called after seal().
*/
void addBatch(Batch b);
}

View File

@@ -0,0 +1,22 @@
package net.sf.briar.api.protocol;
public interface BundleBuilder {
/** Returns the bundle's capacity in bytes. */
long getCapacity();
/** Adds an acknowledgement to the bundle. */
void addAck(BatchId b);
/** Adds a subscription to the bundle. */
void addSubscription(GroupId g);
/** Adds a transport detail to the bundle. */
void addTransport(String key, String value);
/** Adds a batch of messages to the bundle. */
void addBatch(Batch b);
/** Builds and returns the bundle. */
Bundle build();
}