use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method removeEOF.
private void removeEOF(Path path) throws IOException {
long blockSize = 64 << 10;
long chunkSize = OS.pageAlign(blockSize);
long overlapSize = OS.pageAlign(blockSize / 4);
final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
mappedBytes.reserve();
try {
final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
final Bytes<?> bytes = wire.bytes();
bytes.readLimit(bytes.capacity());
bytes.readSkip(4);
// move past header
try (final SingleChronicleQueueStore qs = loadStore(wire)) {
assertNotNull(qs);
long l = qs.writePosition();
long len = Wires.lengthOf(bytes.readVolatileInt(l));
long eofOffset = l + len + 4L;
bytes.writePosition(eofOffset);
bytes.writeInt(0);
}
} finally {
mappedBytes.release();
}
}
use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueue method newIndex.
/**
* Creates a new Excerpt containing and index which will be 1L << 17L bytes long, This method is used for creating
* both the primary and secondary indexes. Chronicle Queue uses a root primary index ( each entry in the primary
* index points to a unique a secondary index. The secondary index only records the addressForRead of every 64th except,
* the except are linearly scanned from there on.
*
* @return the addressForRead of the Excerpt containing the usable index, just after the header
*/
long newIndex() {
final ByteableLongArrayValues array = longArray.get();
final long size = array.sizeInBytes(NUMBER_OF_ENTRIES_IN_EACH_INDEX);
final Bytes buffer = NativeBytes.nativeBytes(size);
buffer.zeroOut(0, size);
final Wire wire = WireUtil.createWire(this.builder.wireType(), buffer);
wire.write(() -> "index").int64array(NUMBER_OF_ENTRIES_IN_EACH_INDEX);
buffer.flip();
return appendMetaDataReturnAddress(buffer);
}
Aggregations