*/
package io.atomix.storage.journal;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
*
* @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/
+@NonNullByDefault
public interface JournalReader<E> extends AutoCloseable {
/**
* Raft log reader mode.
COMMITS,
}
+ /**
+ * A journal entry processor. Responsible for transforming entries into their internal representation.
+ *
+ * @param <E> Entry type
+ * @param <T> Internal representation type
+ */
+ @FunctionalInterface
+ interface EntryMapper<E, T> {
+ /**
+ * Process an entry.
+ *
+ * @param index entry index
+ * @param entry entry itself
+ * @param size entry size
+ * @return resulting internal representation
+ */
+ T mapEntry(long index, E entry, int size);
+ }
+
/**
* Returns the first index in the journal.
*
/**
* Try to move to the next entry.
*
- * @return The next entry in the reader, or {@code null} if there is no next entry.
+ * @param entryMapper callback to be invoked for the entry
+ * @return processed entry, or {@code null}
*/
- @Nullable Indexed<E> tryNext();
+ <T> @Nullable T tryNext(EntryMapper<E, T> entryMapper);
/**
* Resets the reader to the start.
/**
* Resets the reader to the given index.
*
- * @param index The index to which to reset the reader.
+ * @param index the next index to read
*/
void reset(long index);