}
}
- @Override
- 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.
- if (entry.index() > nextIndex) {
- throw new IndexOutOfBoundsException("Entry index is not sequential");
- }
-
- // If the entry's index is less than the next index, truncate the segment.
- if (entry.index() < nextIndex) {
- truncate(entry.index() - 1);
- }
- append(entry.entry());
- }
-
@Override
@SuppressWarnings("unchecked")
<T extends E> Indexed<T> append(T 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.
*
*/
<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.
*
}
}
- @Override
- 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.
- if (entry.index() > nextIndex) {
- throw new IndexOutOfBoundsException("Entry index is not sequential");
- }
-
- // If the entry's index is less than the next index, truncate the segment.
- if (entry.index() < nextIndex) {
- truncate(entry.index() - 1);
- }
- append(entry.entry());
- }
-
@Override
@SuppressWarnings("unchecked")
<T extends E> Indexed<T> append(T entry) {
}
}
- moveToNextSegment();
- return currentWriter.append(entry);
- }
-
- @Override
- public void append(Indexed<E> entry) {
- try {
- currentWriter.append(entry);
- return;
- } catch (BufferOverflowException e) {
- if (currentSegment.index() == currentWriter.getNextIndex()) {
- throw e;
- }
- }
-
- moveToNextSegment();
- currentWriter.append(entry);
- }
-
- private void moveToNextSegment() {
currentWriter.flush();
currentSegment.releaseWriter();
currentSegment = journal.getNextSegment();
currentWriter = currentSegment.acquireWriter();
+ return currentWriter.append(entry);
}
@Override
assertEquals(1, indexed.index());
assertEquals(2, writer.getNextIndex());
- writer.append(new Indexed<>(2, ENTRY, 0));
+ writer.append(ENTRY);
reader.reset(2);
indexed = reader.next();
assertEquals(2, indexed.index());
// Truncate the journal and write a different entry.
writer.truncate(1);
assertEquals(2, writer.getNextIndex());
- writer.append(new Indexed<>(2, ENTRY, 0));
+ writer.append(ENTRY);
reader.reset(2);
indexed = reader.next();
assertEquals(2, indexed.index());