Retrieve messages from the database in raw form to avoid creating unnecessary short-lived objects. Added timestamps to headers.

This commit is contained in:
akwizgran
2011-07-14 12:01:35 +01:00
parent d4382fd232
commit 836d30f6df
32 changed files with 202 additions and 197 deletions

View File

@@ -25,6 +25,8 @@ import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Header;
import net.sf.briar.api.protocol.Message;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.serial.Raw;
import net.sf.briar.api.serial.RawByteArray;
import com.google.inject.Inject;
@@ -212,8 +214,8 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
synchronized(messageStatusLock) {
Txn txn = db.startTransaction();
try {
long capacity = Math.min(b.getRemainingCapacity(),
Batch.MAX_SIZE);
long capacity =
Math.min(b.getRemainingCapacity(), Batch.MAX_SIZE);
Iterator<MessageId> it =
db.getSendableMessages(txn, c, capacity).iterator();
if(!it.hasNext()) {
@@ -221,13 +223,13 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
return false; // No more messages to send
}
Set<MessageId> sent = new HashSet<MessageId>();
List<Message> messages = new ArrayList<Message>();
List<Raw> messages = new ArrayList<Raw>();
int bytesSent = 0;
while(it.hasNext()) {
MessageId m = it.next();
Message message = db.getMessage(txn, m);
bytesSent += message.getSize();
messages.add(message);
byte[] message = db.getMessage(txn, m);
bytesSent += message.length;
messages.add(new RawByteArray(message));
sent.add(m);
}
BatchId batchId = b.addBatch(messages);