Search in sources :

Example 1 with ValueOut

use of net.openhft.chronicle.wire.ValueOut in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueStore method writeMarshallable.

// *************************************************************************
// Marshalling
// *************************************************************************
@Override
public void writeMarshallable(@NotNull WireOut wire) {
    if (lastAcknowledgedIndexReplicated == null)
        lastAcknowledgedIndexReplicated = wire.newLongReference();
    ValueOut wireOut = wire.write(MetaDataField.wireType).object(wireType).writeAlignTo(16, 0).write(MetaDataField.writePosition);
    intForBinding(wireOut, writePosition).write(MetaDataField.roll).typedMarshallable(this.roll).write(MetaDataField.indexing).typedMarshallable(this.indexing).write(MetaDataField.lastAcknowledgedIndexReplicated).int64forBinding(-1L, lastAcknowledgedIndexReplicated);
    wire.write(MetaDataField.recovery).typedMarshallable(recovery);
    wire.write(MetaDataField.deltaCheckpointInterval).int32(this.deltaCheckpointInterval);
    wire.write(MetaDataField.lastIndexReplicated).int64forBinding(-1L, lastIndexReplicated);
    wire.write(MetaDataField.sourceId).int32(sourceId);
    wire.padToCacheAlign();
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut)

Example 2 with ValueOut

use of net.openhft.chronicle.wire.ValueOut in project Chronicle-Queue by OpenHFT.

the class GarbageFreeMethodPublisher method onEightyByteMessage.

@Override
public void onEightyByteMessage(final EightyByteMessage message) {
    final ExcerptAppender appender = outputSupplier.get();
    // DebugTimestamps.operationStart(DebugTimestamps.Operation.GET_WRITING_DOCUMENT);
    @NotNull DocumentContext context = appender.writingDocument();
    // DebugTimestamps.operationEnd(DebugTimestamps.Operation.GET_WRITING_DOCUMENT);
    try {
        Wire wire = context.wire();
        // DebugTimestamps.operationStart(DebugTimestamps.Operation.WRITE_EVENT);
        try {
            wire.write(MethodReader.HISTORY).marshallable(MessageHistory.get());
            final ValueOut valueOut = wire.writeEventName("onEightyByteMessage");
            valueOut.object(EightyByteMessage.class, message);
            wire.padToCacheAlign();
        } finally {
        // DebugTimestamps.operationEnd(DebugTimestamps.Operation.WRITE_EVENT);
        }
    } finally {
        // DebugTimestamps.operationStart(DebugTimestamps.Operation.CLOSE_CONTEXT);
        try {
            context.close();
        } finally {
        // DebugTimestamps.operationEnd(DebugTimestamps.Operation.CLOSE_CONTEXT);
        }
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Wire(net.openhft.chronicle.wire.Wire) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ValueOut

use of net.openhft.chronicle.wire.ValueOut in project Chronicle-Queue by OpenHFT.

the class IncompleteMessageTest method incompleteMessageShouldBeSkipped.

@Test
public void incompleteMessageShouldBeSkipped() throws Exception {
    expectException("Couldn't acquire write lock after ");
    expectException("Forced unlock for the lock ");
    ignoreException("Unable to release the lock");
    try (SingleChronicleQueue queue = createQueue()) {
        try (ExcerptAppender appender = queue.acquireAppender()) {
            appender.writeDocument("hello", ValueOut::text);
            // open a document context, but do not close
            final DocumentContext documentContext = appender.writingDocument();
            documentContext.wire().bytes().write("incomplete longer write".getBytes(StandardCharsets.UTF_8));
        }
    }
    try (SingleChronicleQueue queue = createQueue()) {
        try (ExcerptAppender appender = queue.acquireAppender()) {
            appender.writeDocument("world", ValueOut::text);
        }
        try (ExcerptTailer tailer = queue.createTailer()) {
            tailer.toStart();
            assertEquals("hello", tailer.readText());
            assertEquals("world", tailer.readText());
            assertFalse(tailer.readingDocument().isPresent());
        }
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Example 4 with ValueOut

use of net.openhft.chronicle.wire.ValueOut in project Chronicle-Queue by OpenHFT.

the class QueueInspectorTest method shouldIndicateNoProcessIdWhenDocumentIsComplete.

@Test
public void shouldIndicateNoProcessIdWhenDocumentIsComplete() throws IOException {
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).testBlockSize().build()) {
        final QueueInspector inspector = new QueueInspector(queue);
        final ExcerptAppender appender = queue.acquireAppender();
        appender.writeDocument(37L, ValueOut::int64);
        try (final DocumentContext ctx = appender.writingDocument()) {
            ctx.wire().write("foo").int32(17L);
        }
        final int writingThreadId = inspector.getWritingThreadId();
        assertThat(writingThreadId, is(not(OS.getProcessId())));
        assertThat(QueueInspector.isValidThreadId(writingThreadId), is(false));
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Example 5 with ValueOut

use of net.openhft.chronicle.wire.ValueOut in project Chronicle-Queue by OpenHFT.

the class QueueInspectorTest method shouldDetermineWritingProcessIdWhenDocumentIsNotComplete.

@Test
public void shouldDetermineWritingProcessIdWhenDocumentIsNotComplete() throws IOException {
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).testBlockSize().build()) {
        final QueueInspector inspector = new QueueInspector(queue);
        final ExcerptAppender appender = queue.acquireAppender();
        appender.writeDocument(37L, ValueOut::int64);
        try (final DocumentContext ctx = appender.writingDocument()) {
            ctx.wire().write("foo").int32(17L);
            final int writingThreadId = inspector.getWritingThreadId();
            assertThat(writingThreadId, is(Affinity.getThreadId()));
            assertThat(QueueInspector.isValidThreadId(writingThreadId), is(true));
        }
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Aggregations

ValueOut (net.openhft.chronicle.wire.ValueOut)7 DocumentContext (net.openhft.chronicle.wire.DocumentContext)6 Test (org.junit.Test)5 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)3 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)1 Wire (net.openhft.chronicle.wire.Wire)1 NotNull (org.jetbrains.annotations.NotNull)1