Separate byte-level atomic-storage access
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / ByteBufMapper.java
similarity index 59%
rename from atomix-storage/src/main/java/io/atomix/storage/journal/CommitsSegmentJournalReader.java
rename to atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufMapper.java
index 767e67fa4630864fb60fc4fa9d5ae4ce221b5064..cabd48d8bd7d8d428f91ad8d388ca869dd837d2f 100644 (file)
  */
 package io.atomix.storage.journal;
 
+import io.netty.buffer.ByteBuf;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * A {@link JournalReader} traversing only committed entries.
+ * Support for serialization of {@link ByteBufJournal} entries.
  */
 @NonNullByDefault
-final class CommitsSegmentJournalReader<E> extends SegmentedJournalReader<E> {
-    CommitsSegmentJournalReader(final SegmentedJournal<E> journal, final JournalSegment segment) {
-        super(journal, segment);
-    }
+public interface ByteBufMapper<T> {
+    /**
+     * Converts an object into a series of bytes in a {@link ByteBuf}.
+     *
+     * @param obj the object
+     * @return resulting buffer
+     */
+    ByteBuf objectToBytes(T obj) ;
 
-    @Override
-    public <T> T tryNext(final EntryMapper<E, T> mapper) {
-        return getNextIndex() <= journal.getCommitIndex() ? super.tryNext(mapper) : null;
-    }
+    /**
+     * Converts the contents of a {@link ByteBuf} to an object.
+     *
+     * @param buf buffer to convert
+     * @return resulting object
+     */
+    T bytesToObject(ByteBuf buf);
 }