2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package io.atomix.storage.journal;
10 import static java.util.Objects.requireNonNull;
12 import io.atomix.storage.journal.index.JournalIndex;
13 import java.nio.MappedByteBuffer;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
17 abstract sealed class JournalSegmentWriter<E> implements JournalWriter<E>
18 permits FileChannelJournalSegmentWriter, MappedJournalSegmentWriter {
19 final @NonNull JournalSegment<E> segment;
20 final int maxEntrySize;
21 final @NonNull JournalIndex index;
22 final @NonNull JournalSerdes namespace;
23 final long firstIndex;
25 JournalSegmentWriter(final JournalSegment<E> segment, final int maxEntrySize, final JournalIndex index,
26 final JournalSerdes namespace) {
27 this.segment = requireNonNull(segment);
28 this.maxEntrySize = maxEntrySize;
29 this.index = requireNonNull(index);
30 this.namespace = requireNonNull(namespace);
31 this.firstIndex = segment.index();
35 public final void commit(final long index) {
36 // FIXME: CONTROLLER-2098: eliminate the need for this method
40 * Returns the mapped buffer underlying the segment writer, or {@code null} if the writer does not have such a
43 * @return the mapped buffer underlying the segment writer, or {@code null}.
45 abstract @Nullable MappedByteBuffer buffer();