writes.offer(writeRecord);
}
void perform(RandomAccessFile file, boolean checksum, boolean physicalSync, ReplicationTarget replicationTarget) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(size);
Checksum adler32 = new Adler32();
WriteCommand control = writes.peek();
// Write an empty batch control record.
buffer.putInt(control.location.getPointer());
buffer.putInt(BATCH_CONTROL_RECORD_SIZE);
buffer.put(Location.BATCH_CONTROL_RECORD_TYPE);
buffer.putInt(0);
buffer.putLong(0);
Iterator<WriteCommand> commands = writes.iterator();
// Skip the control write:
commands.next();
// Process others:
while (commands.hasNext()) {
WriteCommand current = commands.next();
buffer.putInt(current.location.getPointer());
buffer.putInt(current.location.getSize());
buffer.put(current.location.getType());
buffer.put(current.getData());
if (checksum) {
adler32.update(current.getData(), 0, current.getData().length);
}
}
// Now we can fill in the batch control record properly.
buffer.position(Journal.HEADER_SIZE);
buffer.putInt(size - Journal.BATCH_CONTROL_RECORD_SIZE);
if (checksum) {
buffer.putLong(adler32.getValue());
}
// Now do the 1 big write.
file.seek(offset);
file.write(buffer.array(), 0, size);