Search in sources :

Example 11 with Wire

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();
    }
}
Also used : SingleChronicleQueueStore(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueStore) Wire(net.openhft.chronicle.wire.Wire) MappedBytes(net.openhft.chronicle.bytes.MappedBytes)

Example 12 with Wire

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);
}
Also used : ByteableLongArrayValues(net.openhft.chronicle.wire.ByteableLongArrayValues) Wire(net.openhft.chronicle.wire.Wire)

Aggregations

Wire (net.openhft.chronicle.wire.Wire)12 DocumentContext (net.openhft.chronicle.wire.DocumentContext)8 Test (org.junit.Test)6 File (java.io.File)5 NotNull (org.jetbrains.annotations.NotNull)5 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)4 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)4 IOException (java.io.IOException)3 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)3 Ignore (org.junit.Ignore)3 LocalDateTime (java.time.LocalDateTime)2 MappedFile (net.openhft.chronicle.bytes.MappedFile)2 BinaryWire (net.openhft.chronicle.wire.BinaryWire)2 Assert (org.junit.Assert)2 FileNotFoundException (java.io.FileNotFoundException)1 StreamCorruptedException (java.io.StreamCorruptedException)1 ByteBuffer (java.nio.ByteBuffer)1 ParseException (java.text.ParseException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1