More refactoring to connect ConnectionRecogniser to ConnectionReader.

Added TestDatabaseModule so tests can specify their own DB
configuration. The modules are currently too tightly coupled - see
whether any dependencies can be removed.
This commit is contained in:
akwizgran
2011-09-28 14:21:38 +01:00
parent 4aff0c4f88
commit a1b664b639
30 changed files with 260 additions and 191 deletions

View File

@@ -33,13 +33,13 @@ class OutgoingBatchConnection {
void write() throws DbException, IOException {
OutputStream out = conn.getOutputStream();
// There should be enough space for a packet
long capacity = conn.getCapacity();
long capacity = conn.getRemainingCapacity();
if(capacity < MAX_PACKET_LENGTH) throw new IOException();
// Write a transport update
TransportWriter t = protoFactory.createTransportWriter(out);
db.generateTransportUpdate(contactId, t);
// If there's space, write a subscription update
capacity = conn.getCapacity();
capacity = conn.getRemainingCapacity();
if(capacity >= MAX_PACKET_LENGTH) {
SubscriptionWriter s = protoFactory.createSubscriptionWriter(out);
db.generateSubscriptionUpdate(contactId, s);
@@ -47,14 +47,14 @@ class OutgoingBatchConnection {
// Write acks until you can't write acks no more
AckWriter a = protoFactory.createAckWriter(out);
do {
capacity = conn.getCapacity();
capacity = conn.getRemainingCapacity();
int max = (int) Math.min(MAX_PACKET_LENGTH, capacity);
a.setMaxPacketLength(max);
} while(db.generateAck(contactId, a));
// Write batches until you can't write batches no more
BatchWriter b = protoFactory.createBatchWriter(out);
do {
capacity = conn.getCapacity();
capacity = conn.getRemainingCapacity();
int max = (int) Math.min(MAX_PACKET_LENGTH, capacity);
b.setMaxPacketLength(max);
} while(db.generateBatch(contactId, b));