Search in sources :

Example 91 with DirectBuffer

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);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) File(java.io.File)

Example 92 with DirectBuffer

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));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) Publication(io.aeron.Publication) ClusteredService(io.aeron.cluster.service.ClusteredService) Image(io.aeron.Image) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 93 with DirectBuffer

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);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) File(java.io.File) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 94 with DirectBuffer

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));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) MessageHeaderDecoder(uk.co.real_logic.sbe.ir.generated.MessageHeaderDecoder) MsgDecoder(composite.elements.MsgDecoder) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 95 with DirectBuffer

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));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

DirectBuffer (org.agrona.DirectBuffer)116 Header (io.aeron.logbuffer.Header)21 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)21 MutableDirectBuffer (org.agrona.MutableDirectBuffer)20 File (java.io.File)19 MediaDriver (io.aeron.driver.MediaDriver)18 CountersReader (org.agrona.concurrent.status.CountersReader)15 ThreadingMode (io.aeron.driver.ThreadingMode)12 FragmentHandler (io.aeron.logbuffer.FragmentHandler)12 MappedByteBuffer (java.nio.MappedByteBuffer)12 ClusteredService (io.aeron.cluster.service.ClusteredService)10 InterruptAfter (io.aeron.test.InterruptAfter)10 Test (org.junit.jupiter.api.Test)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 Publication (io.aeron.Publication)9 ClientSession (io.aeron.cluster.service.ClientSession)9 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)8 Assertions (org.junit.jupiter.api.Assertions)8 Mockito.mock (org.mockito.Mockito.mock)8