public void wrap( final LogStorage logStorage, final LogBlockIndex logBlockIndex, final long position) { this.logStorage = logStorage; this.logBlockIndex = logBlockIndex; if (isClosed()) { allocateBuffer(DEFAULT_INITIAL_BUFFER_CAPACITY); } seek(position); }
public void wrap( final LogStorage logStorage, final LogBlockIndex logBlockIndex, final long position) { this.logStorage = logStorage; this.logBlockIndex = logBlockIndex; if (isClosed()) { allocateBuffer(DEFAULT_INITIAL_BUFFER_CAPACITY); } seek(position); }
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; } }