use of org.agrona.DirectBuffer in project aeron by real-logic.
the class ClusterTool method printErrors.
private static void printErrors(final ClusterMarkFile markFile) {
System.out.println("Cluster component error log:");
ClusterMarkFile.saveErrorLog(System.out, markFile.errorBuffer());
final String aeronDirectory = markFile.decoder().aeronDirectory();
System.out.println("Aeron driver error log (directory: " + aeronDirectory + "):");
final File cncFile = new File(aeronDirectory, CncFileDescriptor.CNC_FILE);
final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
if (CncFileDescriptor.CNC_VERSION != cncVersion) {
throw new IllegalStateException("Aeron CnC version does not match: version=" + cncVersion + " required=" + CncFileDescriptor.CNC_VERSION);
}
final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
ClusterMarkFile.saveErrorLog(System.out, buffer);
}
use of org.agrona.DirectBuffer in project aeron by real-logic.
the class ClusterNodeRestartTest method launchService.
private void launchService(final boolean initialLaunch, final AtomicLong msgCounter) {
final ClusteredService service = new StubClusteredService() {
private int counterValue = 0;
public void onSessionMessage(final long clusterSessionId, final long correlationId, final long timestampMs, final DirectBuffer buffer, final int offset, final int length, final Header header) {
final int sentValue = buffer.getInt(offset);
assertThat(sentValue, is(counterValue));
counterValue++;
serviceState.set(Integer.toString(counterValue));
msgCounter.getAndIncrement();
}
public void onTakeSnapshot(final Publication snapshotPublication) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
int length = 0;
buffer.putInt(length, counterValue);
length += SIZE_OF_INT;
length += buffer.putIntAscii(length, counterValue);
snapshotPublication.offer(buffer, 0, length);
}
public void onLoadSnapshot(final Image snapshotImage) {
while (true) {
final int fragments = snapshotImage.poll((buffer, offset, length, header) -> {
counterValue = buffer.getInt(offset);
final String s = buffer.getStringWithoutLengthAscii(offset + SIZE_OF_INT, length - SIZE_OF_INT);
serviceState.set(s);
}, 1);
if (fragments == 1) {
break;
}
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
};
container = null;
container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).terminationHook(() -> {
}).errorHandler(Throwable::printStackTrace).deleteDirOnStart(initialLaunch));
}
use of org.agrona.DirectBuffer in project aeron by real-logic.
the class AeronStat method mapCounters.
public static CountersReader mapCounters() {
final File cncFile = CommonContext.newDefaultCncFile();
System.out.println("Command `n Control file " + cncFile);
final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
if (CncFileDescriptor.CNC_VERSION != cncVersion) {
throw new IllegalStateException("Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION);
}
return new CountersReader(createCountersMetaDataBuffer(cncByteBuffer, cncMetaData), createCountersValuesBuffer(cncByteBuffer, cncMetaData), StandardCharsets.US_ASCII);
}
use of org.agrona.DirectBuffer in project simple-binary-encoding by real-logic.
the class CompositeElementsGenerationTest method shouldDecodeCorrectly.
@Test
public void shouldDecodeCorrectly() {
final ByteBuffer encodedMsgBuffer = ByteBuffer.allocate(MSG_BUFFER_CAPACITY);
encodeTestMessage(encodedMsgBuffer);
final DirectBuffer decodeBuffer = new UnsafeBuffer(encodedMsgBuffer);
final MessageHeaderDecoder hdrDecoder = new MessageHeaderDecoder();
final MsgDecoder msgDecoder = new MsgDecoder();
hdrDecoder.wrap(decodeBuffer, 0);
msgDecoder.wrap(decodeBuffer, hdrDecoder.encodedLength(), MSG_ENCODER.sbeBlockLength(), MSG_ENCODER.sbeSchemaVersion());
assertThat(hdrDecoder.blockLength(), is(22));
assertThat(hdrDecoder.templateId(), is(1));
assertThat(hdrDecoder.schemaId(), is(3));
assertThat(hdrDecoder.version(), is(0));
assertThat(msgDecoder.structure().enumOne(), is(EnumOne.Value10));
assertThat(msgDecoder.structure().zeroth(), is((short) 42));
assertThat(msgDecoder.structure().setOne().bit0(), is(false));
assertThat(msgDecoder.structure().setOne().bit16(), is(true));
assertThat(msgDecoder.structure().setOne().bit26(), is(false));
assertThat(msgDecoder.structure().inner().first(), is(101L));
assertThat(msgDecoder.structure().inner().second(), is(202L));
assertThat(msgDecoder.encodedLength(), is(22));
}
use of org.agrona.DirectBuffer in project simple-binary-encoding by real-logic.
the class CompositeElementsGenerationTest method shouldEncodeCorrectly.
@Test
public void shouldEncodeCorrectly() {
final ByteBuffer encodedMsgBuffer = ByteBuffer.allocate(MSG_BUFFER_CAPACITY);
encodeTestMessage(encodedMsgBuffer);
final DirectBuffer decodeBuffer = new UnsafeBuffer(encodedMsgBuffer);
int offset = 0;
assertThat(decodeBuffer.getShort(offset), is((short) 22));
offset += BitUtil.SIZE_OF_SHORT;
assertThat(decodeBuffer.getShort(offset), is((short) 1));
offset += BitUtil.SIZE_OF_SHORT;
assertThat(decodeBuffer.getShort(offset), is((short) 3));
offset += BitUtil.SIZE_OF_SHORT;
assertThat(decodeBuffer.getShort(offset), is((short) 0));
offset += BitUtil.SIZE_OF_SHORT;
assertThat(decodeBuffer.getByte(offset), is((byte) 10));
offset += BitUtil.SIZE_OF_BYTE;
assertThat(decodeBuffer.getByte(offset), is((byte) 42));
offset += BitUtil.SIZE_OF_BYTE;
assertThat(decodeBuffer.getInt(offset), is(0x00_01_00_00));
offset += BitUtil.SIZE_OF_INT;
assertThat(decodeBuffer.getLong(offset), is(101L));
offset += BitUtil.SIZE_OF_LONG;
assertThat(decodeBuffer.getLong(offset), is(202L));
}
Aggregations