2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.storage.journal;
18 import static java.util.Objects.requireNonNull;
20 import io.netty.util.internal.PlatformDependent;
21 import java.io.UncheckedIOException;
22 import java.nio.MappedByteBuffer;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
26 * {@link FileAccess} for {@link StorageLevel#MAPPED}.
29 final class MappedFileAccess extends FileAccess {
30 private final MappedByteBuffer mappedBuffer;
32 MappedFileAccess(final JournalSegmentFile file, final int maxEntrySize, final MappedByteBuffer mappedBuffer) {
33 super(file, maxEntrySize);
34 this.mappedBuffer = requireNonNull(mappedBuffer);
38 MappedFileReader newFileReader() {
39 return new MappedFileReader(file, mappedBuffer.slice());
43 @SuppressWarnings("checkstyle:avoidHidingCauseException")
44 MappedFileWriter newFileWriter() {
45 return new MappedFileWriter(file, maxEntrySize, mappedBuffer.slice(), () -> {
48 } catch (UncheckedIOException e) {
56 PlatformDependent.freeDirectBuffer(mappedBuffer);