private boolean readNextAddress() { final boolean blockFound = readBlockIntoBuffer(nextLogStorageReadAddress); if (blockFound) { readNextEvent(); } return blockFound; }
private boolean readNextAddress() { final boolean blockFound = readBlockIntoBuffer(nextLogStorageReadAddress); if (blockFound) { readNextEvent(); } return blockFound; }
@Override public LoggedEvent next() { switch (state) { case EVENT_AVAILABLE: // wrap event for returning wrapReturnedEvent(nextEvent.getFragmentOffset()); // find next event in log readNextEvent(); return returnedEvent; case WRAP_NOT_CALLED: throw new IllegalStateException("Iterator not initialized"); default: throw new NoSuchElementException( "Api protocol violation: No next log entry available; You need to probe with hasNext() first."); } }
@Override public LoggedEvent next() { switch (state) { case EVENT_AVAILABLE: // wrap event for returning wrapReturnedEvent(nextEvent.getFragmentOffset()); // find next event in log readNextEvent(); return returnedEvent; case WRAP_NOT_CALLED: throw new IllegalStateException("Iterator not initialized"); default: throw new NoSuchElementException( "Api protocol violation: No next log entry available; You need to probe with hasNext() first."); } }
@Override public boolean seek(final long position) { if (state == IteratorState.WRAP_NOT_CALLED) { throw new IllegalStateException("Iterator not initialized"); } // invalidate events first as the buffer content may change invalidateBufferAndOffsets(); final long blockAddress = lookUpBlockAddressForPosition(position); if (blockAddress < 0) { // no block found => empty log state = IteratorState.EMPTY_LOG_STREAM; return false; } else { readBlockIntoBuffer(blockAddress); readNextEvent(); return searchPositionInBuffer(position); } }
@Override public boolean seek(final long position) { if (state == IteratorState.WRAP_NOT_CALLED) { throw new IllegalStateException("Iterator not initialized"); } // invalidate events first as the buffer content may change invalidateBufferAndOffsets(); final long blockAddress = lookUpBlockAddressForPosition(position); if (blockAddress < 0) { // no block found => empty log state = IteratorState.EMPTY_LOG_STREAM; return false; } else { readBlockIntoBuffer(blockAddress); readNextEvent(); return searchPositionInBuffer(position); } }
private boolean searchPositionInBuffer(final long position) { while (isNextUncommittedEventAvailable() && nextEvent.getPosition() < position) { readNextEvent(); } if (nextEvent.getPosition() < position) { // not in buffered block, read next block and continue the search return readNextAddress() && searchPositionInBuffer(position); } return nextEvent.getPosition() == position; }
private boolean searchPositionInBuffer(final long position) { while (isNextUncommittedEventAvailable() && nextEvent.getPosition() < position) { readNextEvent(); } if (nextEvent.getPosition() < position) { // not in buffered block, read next block and continue the search return readNextAddress() && searchPositionInBuffer(position); } return nextEvent.getPosition() == position; }