2 * Copyright 2017-2022 Open Networking Foundation 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 org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
24 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
27 public interface JournalReader<E> extends AutoCloseable {
29 * Raft log reader mode.
33 * Reads all entries from the log.
37 * Reads committed entries from the log.
43 * A journal entry processor. Responsible for transforming entries into their internal representation.
45 * @param <E> Entry type
46 * @param <T> Internal representation type
49 interface EntryMapper<E, T> {
53 * @param index entry index
54 * @param entry entry itself
55 * @param size entry size
56 * @return resulting internal representation
58 T mapEntry(long index, E entry, int size);
62 * Returns the first index in the journal.
64 * @return the first index in the journal
69 * Returns the next reader index.
71 * @return The next reader index.
76 * Try to move to the next entry.
78 * @param entryMapper callback to be invoked for the entry
79 * @return processed entry, or {@code null}
81 <T> @Nullable T tryNext(EntryMapper<E, T> entryMapper);
84 * Resets the reader to the start.
89 * Resets the reader to the given index.
91 * @param index The index to which to reset the reader.
93 void reset(long index);