Introduce JournalSegmentReader
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / JournalSegmentReader.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package io.atomix.storage.journal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import io.atomix.storage.journal.index.JournalIndex;
13
14 abstract sealed class JournalSegmentReader<E> implements JournalReader<E>
15         permits FileChannelJournalSegmentReader, MappedJournalSegmentReader {
16     final int maxEntrySize;
17     final JournalIndex index;
18     final JournalSerdes namespace;
19     final long firstIndex;
20
21     JournalSegmentReader(final JournalSegment<E> segment, final int maxEntrySize, final JournalIndex index,
22             final JournalSerdes namespace) {
23         this.maxEntrySize = maxEntrySize;
24         this.index = requireNonNull(index);
25         this.namespace = requireNonNull(namespace);
26         this.firstIndex = segment.index();
27     }
28
29     @Override
30     public final long getFirstIndex() {
31         return firstIndex;
32     }
33
34     @Override
35     public final void close() {
36         // FIXME: CONTROLLER-2098: remove this method
37     }
38 }