import java.util.zip.CRC32;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.zip.CRC32;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final @NonNull JournalSegment segment;
private final @NonNull JournalIndex index;
final int maxSegmentSize;
final @NonNull JournalSegment segment;
private final @NonNull JournalIndex index;
final int maxSegmentSize;
- JournalSegmentWriter(final FileChannel channel, final JournalSegment segment, final int maxEntrySize,
+ JournalSegmentWriter(final FileWriter fileWriter, final JournalSegment segment, final int maxEntrySize,
this.segment = requireNonNull(segment);
this.index = requireNonNull(index);
maxSegmentSize = segment.descriptor().maxSegmentSize();
this.maxEntrySize = maxEntrySize;
this.segment = requireNonNull(segment);
this.index = requireNonNull(index);
maxSegmentSize = segment.descriptor().maxSegmentSize();
this.maxEntrySize = maxEntrySize;
lastWritten = previous.lastWritten;
lastIndex = previous.lastIndex;
currentPosition = previous.currentPosition;
lastWritten = previous.lastWritten;
lastIndex = previous.lastIndex;
currentPosition = previous.currentPosition;
// Create a single byte[] in memory for the entire entry and write it as a batch to the underlying buffer.
writeBuffer.putInt(0, length).putInt(Integer.BYTES, (int) crc32.getValue());
// Create a single byte[] in memory for the entire entry and write it as a batch to the underlying buffer.
writeBuffer.putInt(0, length).putInt(Integer.BYTES, (int) crc32.getValue());
*/
final void reset(final long index) {
// acquire ownership of cache and make sure reader does not see anything we've done once we're done
*/
final void reset(final long index) {
// acquire ownership of cache and make sure reader does not see anything we've done once we're done
- abstract JournalSegmentReader reader();
-
- private void resetWithBuffer(final JournalSegmentReader reader, final long index) {
+ private void resetWithBuffer(final FileReader fileReader, final long index) {
long nextIndex = segment.firstIndex();
// Clear the buffer indexes and acquire ownership of the buffer
currentPosition = JournalSegmentDescriptor.BYTES;
long nextIndex = segment.firstIndex();
// Clear the buffer indexes and acquire ownership of the buffer
currentPosition = JournalSegmentDescriptor.BYTES;
- abstract @NonNull MappedJournalSegmentWriter toMapped();
+ @NonNull JournalSegmentWriter toMapped() {
+ final var newWriter = fileWriter.toMapped();
+ return newWriter == null ? this : new JournalSegmentWriter(this, newWriter);
+ }
- abstract @NonNull DiskJournalSegmentWriter toFileChannel();
+ @NonNull JournalSegmentWriter toFileChannel() {
+ final var newWriter = fileWriter.toDisk();
+ return newWriter == null ? this : new JournalSegmentWriter(this, newWriter);
+ }