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

@@ -4,6 +4,8 @@ import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Map;
import net.sf.briar.api.serial.Raw;
/**
* An interface for writing a bundle of acknowledgements, subscriptions,
* transport details and batches.
@@ -18,8 +20,8 @@ public interface BundleWriter {
Map<String, String> transports) throws IOException,
GeneralSecurityException;
/** Adds a batch to the bundle and returns its identifier. */
BatchId addBatch(Iterable<Message> messages) throws IOException,
/** Adds a batch of messages to the bundle and returns its identifier. */
BatchId addBatch(Iterable<Raw> messages) throws IOException,
GeneralSecurityException;
/** Finishes writing the bundle. */

View File

@@ -16,4 +16,7 @@ public interface Header {
/** Returns the transport details contained in the header. */
Map<String, String> getTransports();
/** Returns the header's timestamp. */
long getTimestamp();
}

View File

@@ -1,7 +0,0 @@
package net.sf.briar.api.protocol;
public interface MessageFactory {
Message createMessage(MessageId id, MessageId parent, GroupId group,
AuthorId author, long timestamp, byte[] raw);
}

View File

@@ -0,0 +1,29 @@
package net.sf.briar.api.serial;
import java.util.Arrays;
/** A byte array wrapped in the Raw interface. */
public class RawByteArray implements Raw {
private final byte[] bytes;
public RawByteArray(byte[] bytes) {
this.bytes = bytes;
}
public byte[] getBytes() {
return bytes;
}
@Override
public int hashCode() {
return Arrays.hashCode(bytes);
}
@Override
public boolean equals(Object o) {
if(o instanceof Raw) return Arrays.equals(bytes, ((Raw) o).getBytes());
return false;
}
}