Separate out RaftEntryMeta
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / JournalWriter.java
index efb566efa9d5de8dc06183e28b319b914327649d..649e43e4efda36051f50d28a6cbe44076978219e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017-present Open Networking Foundation
+ * Copyright 2017-2022 Open Networking Foundation and others.  All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 package io.atomix.storage.journal;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Log writer.
  *
  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
  */
-public interface JournalWriter<E> extends AutoCloseable {
-
-  /**
-   * Returns the last written index.
-   *
-   * @return The last written index.
-   */
-  long getLastIndex();
-
-  /**
-   * Returns the last entry written.
-   *
-   * @return The last entry written.
-   */
-  Indexed<E> getLastEntry();
-
-  /**
-   * Returns the next index to be written.
-   *
-   * @return The next index to be written.
-   */
-  long getNextIndex();
-
-  /**
-   * Appends an entry to the journal.
-   *
-   * @param entry The entry to append.
-   * @return The appended indexed entry.
-   */
-  <T extends E> Indexed<T> append(T entry);
-
-  /**
-   * Appends an indexed entry to the log.
-   *
-   * @param entry The indexed entry to append.
-   */
-  void append(Indexed<E> entry);
-
-  /**
-   * Commits entries up to the given index.
-   *
-   * @param index The index up to which to commit entries.
-   */
-  void commit(long index);
-
-  /**
-   * Resets the head of the journal to the given index.
-   *
-   * @param index the index to which to reset the head of the journal
-   */
-  void reset(long index);
-
-  /**
-   * Truncates the log to the given index.
-   *
-   * @param index The index to which to truncate the log.
-   */
-  void truncate(long index);
-
-  /**
-   * Flushes written entries to disk.
-   */
-  void flush();
-
-  @Override
-  void close();
+public interface JournalWriter<E> {
+    /**
+     * Returns the next index to be written.
+     *
+     * @return The next index to be written.
+     */
+    long getNextIndex();
+
+    /**
+     * Appends an entry to the journal.
+     *
+     * @param entry The entry to append.
+     * @return The appended indexed entry.
+     */
+    <T extends E> @NonNull Indexed<T> append(T entry);
+
+    /**
+     * Commits entries up to the given index.
+     *
+     * @param index The index up to which to commit entries.
+     */
+    void commit(long index);
+
+    /**
+     * Resets the head of the journal to the given index.
+     *
+     * @param index the next index to write
+     * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index
+     */
+    void reset(long index);
+
+    /**
+     * Flushes written entries to disk.
+     */
+    void flush();
 }