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();
}
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);
}
}
}
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());
}
}
}
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));
}
}
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));
}
}
}
Aggregations