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; }
private boolean readBlockIntoBuffer(final long blockAddress) { if (byteBuffer.remaining() < LogEntryDescriptor.HEADER_BLOCK_LENGTH) { compactBuffer(); } final long result = logStorage.read(byteBuffer, blockAddress, completeEventsInBlockProcessor); if (result == LogStorage.OP_RESULT_INSUFFICIENT_BUFFER_CAPACITY) { // it was not possible to read the block in the existing buffer => expand buffer long nextCapacity = 2L * (long) byteBuffer.capacity(); nextCapacity = Math.min(nextCapacity, MAX_BUFFER_CAPACITY); allocateBuffer((int) nextCapacity); // retry to read the next block return readBlockIntoBuffer(blockAddress); } else if (result == LogStorage.OP_RESULT_INVALID_ADDR) { throw new IllegalStateException("Invalid address to read from " + blockAddress); } else if (result == LogStorage.OP_RESULT_NO_DATA) { state = IteratorState.NOT_ENOUGH_DATA; return false; } else { this.nextLogStorageReadAddress = result; return true; } }
private boolean readBlockIntoBuffer(final long blockAddress) { if (byteBuffer.remaining() < LogEntryDescriptor.HEADER_BLOCK_LENGTH) { compactBuffer(); } final long result = logStorage.read(byteBuffer, blockAddress, completeEventsInBlockProcessor); if (result == LogStorage.OP_RESULT_INSUFFICIENT_BUFFER_CAPACITY) { // it was not possible to read the block in the existing buffer => expand buffer long nextCapacity = 2L * (long) byteBuffer.capacity(); nextCapacity = Math.min(nextCapacity, MAX_BUFFER_CAPACITY); allocateBuffer((int) nextCapacity); // retry to read the next block return readBlockIntoBuffer(blockAddress); } else if (result == LogStorage.OP_RESULT_INVALID_ADDR) { throw new IllegalStateException("Invalid address to read from " + blockAddress); } else if (result == LogStorage.OP_RESULT_NO_DATA) { state = IteratorState.NOT_ENOUGH_DATA; return false; } else { this.nextLogStorageReadAddress = result; return true; } }
@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); } }