Search in sources :

Example 6 with LongValue

use of net.openhft.chronicle.core.values.LongValue in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueue method appendDocument.

@Override
public long appendDocument(@NotNull Bytes buffer) {
    long length = checkRemainingForAppend(buffer);
    LongValue writeByte = header.writeByte();
    for (; ; ) {
        long lastByte = writeByte.getVolatileValue();
        if (bytes.compareAndSwapInt(lastByte, 0, NOT_COMPLETE | (int) length)) {
            long lastByte2 = lastByte + 4 + buffer.remaining();
            bytes.write(lastByte + 4, buffer);
            long lastIndex = header.lastIndex().addAtomicValue(1);
            writeByte.setOrderedValue(lastByte2);
            bytes.writeOrderedInt(lastByte, (int) length);
            return lastIndex;
        }
        int length2 = length30(bytes.readVolatileInt());
        bytes.skip(length2);
        try {
            Jvm.checkInterrupted();
        } catch (InterruptedException e) {
            throw new InterruptedRuntimeException(e);
        }
    }
}
Also used : LongValue(net.openhft.chronicle.core.values.LongValue)

Aggregations

LongValue (net.openhft.chronicle.core.values.LongValue)6 Test (org.junit.Test)2 EOFException (java.io.EOFException)1 File (java.io.File)1 StreamCorruptedException (java.io.StreamCorruptedException)1 IORuntimeException (net.openhft.chronicle.core.io.IORuntimeException)1 TwoLongValue (net.openhft.chronicle.core.values.TwoLongValue)1 TableStore (net.openhft.chronicle.queue.impl.TableStore)1 ValueIn (net.openhft.chronicle.wire.ValueIn)1