Position is a simple record
[controller.git] / third-party / atomix / storage / src / main / java / io / atomix / storage / journal / JournalReader.java
1 /*
2  * Copyright 2017-present Open Networking Foundation
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package io.atomix.storage.journal;
17
18 import java.util.Iterator;
19
20 /**
21  * Log reader.
22  *
23  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
24  */
25 public interface JournalReader<E> extends Iterator<Indexed<E>>, AutoCloseable {
26
27   /**
28    * Raft log reader mode.
29    */
30   enum Mode {
31
32     /**
33      * Reads all entries from the log.
34      */
35     ALL,
36
37     /**
38      * Reads committed entries from the log.
39      */
40     COMMITS,
41   }
42
43   /**
44    * Returns the first index in the journal.
45    *
46    * @return the first index in the journal
47    */
48   long getFirstIndex();
49
50   /**
51    * Returns the current reader index.
52    *
53    * @return The current reader index.
54    */
55   long getCurrentIndex();
56
57   /**
58    * Returns the last read entry.
59    *
60    * @return The last read entry.
61    */
62   Indexed<E> getCurrentEntry();
63
64   /**
65    * Returns the next reader index.
66    *
67    * @return The next reader index.
68    */
69   long getNextIndex();
70
71   /**
72    * Returns whether the reader has a next entry to read.
73    *
74    * @return Whether the reader has a next entry to read.
75    */
76   @Override
77   boolean hasNext();
78
79   /**
80    * Returns the next entry in the reader.
81    *
82    * @return The next entry in the reader.
83    */
84   @Override
85   Indexed<E> next();
86
87   /**
88    * Resets the reader to the start.
89    */
90   void reset();
91
92   /**
93    * Resets the reader to the given index.
94    *
95    * @param index The index to which to reset the reader.
96    */
97   void reset(long index);
98
99   @Override
100   void close();
101 }