}
@Override
- public void reset(long index) {
+ void reset(long index) {
long nextIndex = firstIndex;
// Clear the buffer indexes.
}
@Override
- public long getLastIndex() {
+ long getLastIndex() {
return lastEntry != null ? lastEntry.index() : firstIndex - 1;
}
@Override
- public Indexed<E> getLastEntry() {
+ Indexed<E> getLastEntry() {
return lastEntry;
}
@Override
- public long getNextIndex() {
+ long getNextIndex() {
if (lastEntry != null) {
return lastEntry.index() + 1;
} else {
}
@Override
- public void append(Indexed<E> entry) {
+ void append(Indexed<E> entry) {
final long nextIndex = getNextIndex();
// If the entry's index is greater than the next index in the segment, skip some entries.
@Override
@SuppressWarnings("unchecked")
- public <T extends E> Indexed<T> append(T entry) {
+ <T extends E> Indexed<T> append(T entry) {
// Store the entry index.
final long index = getNextIndex();
}
@Override
- public void truncate(long index) {
+ void truncate(long index) {
// If the index is greater than or equal to the last index, skip the truncate.
if (index >= getLastIndex()) {
return;
}
@Override
- public void flush() {
+ void flush() {
try {
if (channel.isOpen()) {
channel.force(true);
}
@Override
- public void close() {
+ void close() {
flush();
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-abstract sealed class JournalSegmentWriter<E> implements JournalWriter<E>
- permits FileChannelJournalSegmentWriter, MappedJournalSegmentWriter {
+abstract sealed class JournalSegmentWriter<E> permits FileChannelJournalSegmentWriter, MappedJournalSegmentWriter {
final @NonNull FileChannel channel;
final @NonNull JournalIndex index;
final @NonNull JournalSerdes namespace;
this.firstIndex = previous.firstIndex;
}
- @Override
- public final void commit(final long index) {
- // FIXME: CONTROLLER-2098: eliminate the need for this method
- }
+ /**
+ * Returns the last written index.
+ *
+ * @return The last written index.
+ */
+ abstract long getLastIndex();
+
+ /**
+ * Returns the last entry written.
+ *
+ * @return The last entry written.
+ */
+ abstract Indexed<E> getLastEntry();
+
+ /**
+ * Returns the next index to be written.
+ *
+ * @return The next index to be written.
+ */
+ abstract long getNextIndex();
+
+ /**
+ * Appends an entry to the journal.
+ *
+ * @param entry The entry to append.
+ * @return The appended indexed entry.
+ */
+ abstract <T extends E> Indexed<T> append(T entry);
+
+ /**
+ * Appends an indexed entry to the log.
+ *
+ * @param entry The indexed entry to append.
+ */
+ abstract void append(Indexed<E> entry);
+
+ /**
+ * Resets the head of the segment to the given index.
+ *
+ * @param index the index to which to reset the head of the segment
+ */
+ abstract void reset(long index);
+
+ /**
+ * Truncates the log to the given index.
+ *
+ * @param index The index to which to truncate the log.
+ */
+ abstract void truncate(long index);
+
+ /**
+ * Flushes written entries to disk.
+ */
+ abstract void flush();
+
+ /**
+ * Closes this writer.
+ */
+ abstract void close();
/**
* Returns the mapped buffer underlying the segment writer, or {@code null} if the writer does not have such a
*
* @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/
-public interface JournalWriter<E> extends AutoCloseable {
-
+public interface JournalWriter<E> {
/**
* Returns the last written index.
*
* Flushes written entries to disk.
*/
void flush();
-
- @Override
- void close();
}
}
@Override
- public void reset(long index) {
+ void reset(long index) {
long nextIndex = firstIndex;
// Clear the buffer indexes.
}
@Override
- public long getLastIndex() {
+ long getLastIndex() {
return lastEntry != null ? lastEntry.index() : firstIndex - 1;
}
@Override
- public Indexed<E> getLastEntry() {
+ Indexed<E> getLastEntry() {
return lastEntry;
}
@Override
- public long getNextIndex() {
+ long getNextIndex() {
if (lastEntry != null) {
return lastEntry.index() + 1;
} else {
}
@Override
- public void append(Indexed<E> entry) {
+ void append(Indexed<E> entry) {
final long nextIndex = getNextIndex();
// If the entry's index is greater than the next index in the segment, skip some entries.
@Override
@SuppressWarnings("unchecked")
- public <T extends E> Indexed<T> append(T entry) {
+ <T extends E> Indexed<T> append(T entry) {
// Store the entry index.
final long index = getNextIndex();
return (Indexed<T>) indexedEntry;
}
-
@Override
- public void truncate(long index) {
+ void truncate(long index) {
// If the index is greater than or equal to the last index, skip the truncate.
if (index >= getLastIndex()) {
return;
}
@Override
- public void flush() {
+ void flush() {
mappedBuffer.force();
}
@Override
- public void close() {
+ void close() {
flush();
try {
BufferCleaner.freeBuffer(mappedBuffer);
public void flush() {
currentWriter.flush();
}
-
- @Override
- public void close() {
- currentWriter.close();
- }
}