Search in sources :

Example 1 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.

the class DriverTool method main.

public static void main(final String[] args) throws Exception {
    boolean printPidOnly = false;
    if (0 != args.length) {
        checkForHelp(args);
        if (args[0].equals("pid")) {
            printPidOnly = true;
        }
    }
    final File cncFile = CommonContext.newDefaultCncFile();
    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);
    }
    final ManyToOneRingBuffer toDriver = new ManyToOneRingBuffer(createToDriverBuffer(cncByteBuffer, cncMetaData));
    if (printPidOnly) {
        System.out.println(pid(cncMetaData));
    } else {
        System.out.println("Command `n Control file %s" + cncFile);
        System.out.format("Version: %d, PID: %d%n", cncVersion, pid(cncMetaData));
        printDateActivityAndStartTimestamps(startTimestamp(cncMetaData), toDriver.consumerHeartbeatTime());
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) File(java.io.File)

Example 2 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.

the class IpcPublicationTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() {
    final RingBuffer fromClientCommands = new ManyToOneRingBuffer(new UnsafeBuffer(ByteBuffer.allocateDirect(Configuration.CONDUCTOR_BUFFER_LENGTH)));
    final RawLogFactory mockRawLogFactory = mock(RawLogFactory.class);
    final UnsafeBuffer counterBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_LENGTH));
    final CountersManager countersManager = new CountersManager(new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_LENGTH * 2)), counterBuffer, StandardCharsets.US_ASCII);
    when(mockRawLogFactory.newIpcPublication(anyInt(), anyInt(), anyLong(), anyInt())).thenReturn(LogBufferHelper.newTestLogBuffers(TERM_BUFFER_LENGTH));
    final MediaDriver.Context ctx = new MediaDriver.Context().tempBuffer(new UnsafeBuffer(new byte[METADATA_LENGTH])).ipcTermBufferLength(TERM_BUFFER_LENGTH).toDriverCommands(fromClientCommands).rawLogBuffersFactory(mockRawLogFactory).clientProxy(mock(ClientProxy.class)).driverCommandQueue(mock(ManyToOneConcurrentArrayQueue.class)).epochClock(new SystemEpochClock()).cachedEpochClock(new CachedEpochClock()).cachedNanoClock(new CachedNanoClock()).countersManager(countersManager).systemCounters(mock(SystemCounters.class)).nanoClock(nanoClock);
    ctx.countersValuesBuffer(counterBuffer);
    driverProxy = new DriverProxy(fromClientCommands, CLIENT_ID);
    driverConductor = new DriverConductor(ctx);
    driverProxy.addPublication(CommonContext.IPC_CHANNEL, STREAM_ID);
    driverConductor.doWork();
    ipcPublication = driverConductor.getSharedIpcPublication(STREAM_ID);
    publisherLimit = new UnsafeBufferPosition(counterBuffer, ipcPublication.publisherLimitId());
}
Also used : CommonContext(io.aeron.CommonContext) RawLogFactory(io.aeron.driver.buffer.RawLogFactory) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) RingBuffer(org.agrona.concurrent.ringbuffer.RingBuffer) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) DriverProxy(io.aeron.DriverProxy) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) CountersManager(org.agrona.concurrent.status.CountersManager) Before(org.junit.Before)

Example 3 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.

the class DriverEventLogger method logPublicationRemoval.

/**
 * Log the removal of a publication.
 *
 * @param channel   for the channel.
 * @param sessionId for the publication.
 * @param streamId  within the channel.
 */
public void logPublicationRemoval(final String channel, final int sessionId, final int streamId) {
    final int length = SIZE_OF_INT * 3 + channel.length();
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(toEventCodeId(REMOVE_PUBLICATION_CLEANUP), encodedLength);
    if (index > 0) {
        try {
            final UnsafeBuffer buffer = (UnsafeBuffer) ringBuffer.buffer();
            encodePublicationRemoval(buffer, index, captureLength, length, channel, sessionId, streamId);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 4 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.

the class DriverEventLogger method logFrameOut.

/**
 * Log a frame being sent out from the driver to the media.
 *
 * @param buffer     containing the frame.
 * @param dstAddress for the frame.
 */
public void logFrameOut(final ByteBuffer buffer, final InetSocketAddress dstAddress) {
    final int length = buffer.remaining() + socketAddressLength(dstAddress);
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(toEventCodeId(FRAME_OUT), encodedLength);
    if (index > 0) {
        try {
            encode((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, buffer, buffer.position(), dstAddress);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 5 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.

the class DriverEventLogger method logSubscriptionRemoval.

/**
 * Log the removal of a subscription.
 *
 * @param channel        for the channel.
 * @param streamId       within the channel.
 * @param subscriptionId for the subscription.
 */
public void logSubscriptionRemoval(final String channel, final int streamId, final long subscriptionId) {
    final int length = SIZE_OF_INT * 2 + SIZE_OF_LONG + channel.length();
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(toEventCodeId(REMOVE_SUBSCRIPTION_CLEANUP), encodedLength);
    if (index > 0) {
        try {
            final UnsafeBuffer buffer = (UnsafeBuffer) ringBuffer.buffer();
            encodeSubscriptionRemoval(buffer, index, captureLength, length, channel, streamId, subscriptionId);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Aggregations

ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)28 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)7 File (java.io.File)4 MappedByteBuffer (java.nio.MappedByteBuffer)4 DriverProxy (io.aeron.DriverProxy)3 DriverTimeoutException (io.aeron.exceptions.DriverTimeoutException)2 DirectBuffer (org.agrona.DirectBuffer)2 RingBuffer (org.agrona.concurrent.ringbuffer.RingBuffer)2 CountersManager (org.agrona.concurrent.status.CountersManager)2 UnsafeBufferPosition (org.agrona.concurrent.status.UnsafeBufferPosition)2 CommonContext (io.aeron.CommonContext)1 RawLogFactory (io.aeron.driver.buffer.RawLogFactory)1 TestLogFactory (io.aeron.driver.buffer.TestLogFactory)1 SystemCounters (io.aeron.driver.status.SystemCounters)1 AeronException (io.aeron.exceptions.AeronException)1 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1