*/
package io.atomix.storage.journal;
+import static io.atomix.storage.journal.SegmentEntry.HEADER_BYTES;
+
import com.esotericsoftware.kryo.KryoException;
import io.atomix.storage.journal.index.JournalIndex;
-
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
}
@Override
- FileChannelJournalSegmentWriter<E> toFileChannel() {
+ DiskJournalSegmentWriter<E> toFileChannel() {
final int position = buffer.position();
close();
- return new FileChannelJournalSegmentWriter<>(this, position);
+ return new DiskJournalSegmentWriter<>(this, position);
}
@Override
// Serialize the entry.
int position = buffer.position();
- if (position + ENTRY_HEADER_BYTES > buffer.limit()) {
+ if (position + HEADER_BYTES > buffer.limit()) {
throw new BufferOverflowException();
}
- buffer.position(position + ENTRY_HEADER_BYTES);
+ buffer.position(position + HEADER_BYTES);
try {
namespace.serialize(entry, buffer);
throw new BufferOverflowException();
}
- final int length = buffer.position() - (position + ENTRY_HEADER_BYTES);
+ final int length = buffer.position() - (position + HEADER_BYTES);
// If the entry length exceeds the maximum entry size then throw an exception.
if (length > maxEntrySize) {
// Compute the checksum for the entry.
final CRC32 crc32 = new CRC32();
- buffer.position(position + ENTRY_HEADER_BYTES);
+ buffer.position(position + HEADER_BYTES);
ByteBuffer slice = buffer.slice();
slice.limit(length);
crc32.update(slice);
final long checksum = crc32.getValue();
// Create a single byte[] in memory for the entire entry and write it as a batch to the underlying buffer.
- buffer.position(position).putInt(length).putInt((int) checksum).position(position + ENTRY_HEADER_BYTES + length);
+ buffer.position(position).putInt(length).putInt((int) checksum).position(position + HEADER_BYTES + length);
// Update the last entry with the correct index/term/length.
Indexed<E> indexedEntry = new Indexed<>(index, entry, length);