public ByteBuffer[] sliceTerms() { final ByteBuffer[] terms = new ByteBuffer[PARTITION_COUNT]; for (int i = 0; i < PARTITION_COUNT; i++) { terms[i] = termBuffers[i].byteBuffer().duplicate(); } return terms; }
static boolean notHeaderAligned( final FileChannel channel, final UnsafeBuffer buffer, final int segmentOffset, final int termOffset, final int termId, final int streamId) throws IOException { final ByteBuffer byteBuffer = buffer.byteBuffer(); byteBuffer.clear().limit(DataHeaderFlyweight.HEADER_LENGTH); if (DataHeaderFlyweight.HEADER_LENGTH != channel.read(byteBuffer, segmentOffset)) { throw new ArchiveException("failed to read fragment header"); } return isInvalidHeader(buffer, streamId, termId, termOffset); }
private int readRecording(final long availableReplay) throws IOException { if (publication.availableWindow() > 0) { final int limit = Math.min((int)Math.min(availableReplay, MAX_BLOCK_LENGTH), termLength - termOffset); final ByteBuffer byteBuffer = replayBuffer.byteBuffer(); byteBuffer.clear().limit(limit); int position = termBaseSegmentOffset + termOffset; do { position += fileChannel.read(byteBuffer, position); } while (byteBuffer.remaining() > 0); return byteBuffer.limit(); } else if (!publication.isConnected()) { state = State.INACTIVE; } return 0; }
private void fileChunk( final long correlationId, final long chunkOffset, final long chunkLength, final DirectBuffer buffer, final int offset) { final UnsafeBuffer fileBuffer = fileSessionByIdMap.get(correlationId); buffer.getBytes(offset + CHUNK_PAYLOAD_OFFSET, fileBuffer, (int)chunkOffset, (int)chunkLength); if ((chunkOffset + chunkLength) >= fileBuffer.capacity()) { fileSessionByIdMap.remove(correlationId); IoUtil.unmap(fileBuffer.byteBuffer()); } }
dataHeaderBuffer.byteBuffer().put(0, (byte)0).limit(1).position(0); channel.write(dataHeaderBuffer.byteBuffer(), segmentLength - 1);
/** * Map a position over a buffer and this indicator owns the counter for reclamation. * * @param buffer containing the counter. * @param counterId identifier of the counter. * @param countersManager to be used for freeing the counter when this is closed. */ public UnsafeBufferPosition(final UnsafeBuffer buffer, final int counterId, final CountersManager countersManager) { this.counterId = counterId; this.countersManager = countersManager; this.byteArray = buffer.byteArray(); this.byteBuffer = buffer.byteBuffer(); final int counterOffset = CountersManager.counterOffset(counterId); buffer.boundsCheck(counterOffset, SIZE_OF_LONG); this.addressOffset = buffer.addressOffset() + counterOffset; }
@After public void after() { IoUtil.unmap(mockLogBufferMapped.byteBuffer()); CloseHelper.close(mockLogBufferChannel); IoUtil.delete(archiveDir, false); IoUtil.delete(termFile, false); }
static boolean notHeaderAligned( final FileChannel channel, final UnsafeBuffer buffer, final int segmentOffset, final int termOffset, final int termId, final int streamId) throws IOException { final ByteBuffer byteBuffer = buffer.byteBuffer(); byteBuffer.clear().limit(DataHeaderFlyweight.HEADER_LENGTH); if (DataHeaderFlyweight.HEADER_LENGTH != channel.read(byteBuffer, segmentOffset)) { throw new ArchiveException("failed to read fragment header"); } return isInvalidHeader(buffer, streamId, termId, termOffset); }
private int readRecording(final long availableReplay) throws IOException { if (publication.availableWindow() > 0) { final int limit = Math.min((int)Math.min(availableReplay, MAX_BLOCK_LENGTH), termLength - termOffset); final ByteBuffer byteBuffer = replayBuffer.byteBuffer(); byteBuffer.clear().limit(limit); int position = termBaseSegmentOffset + termOffset; do { position += fileChannel.read(byteBuffer, position); } while (byteBuffer.remaining() > 0); return byteBuffer.limit(); } else if (!publication.isConnected()) { state = State.INACTIVE; } return 0; }
/** * Map a position over a buffer and this indicator owns the counter for reclamation. * * @param buffer containing the counter. * @param counterId identifier of the counter. * @param countersManager to be used for freeing the counter when this is closed. */ public UnsafeBufferPosition(final UnsafeBuffer buffer, final int counterId, final CountersManager countersManager) { this.counterId = counterId; this.countersManager = countersManager; this.byteArray = buffer.byteArray(); this.byteBuffer = buffer.byteBuffer(); final int counterOffset = CountersManager.counterOffset(counterId); buffer.boundsCheck(counterOffset, SIZE_OF_LONG); this.addressOffset = buffer.addressOffset() + counterOffset; }
dataHeaderBuffer.byteBuffer().put(0, (byte)0).limit(1).position(0); channel.write(dataHeaderBuffer.byteBuffer(), segmentLength - 1);