Search in sources :

Example 31 with ManyToOneRingBuffer

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

the class ArchiveEventLogger method log.

/**
 * Log an Archive control event.
 *
 * @param eventCode for the type of control event.
 * @param buffer    containing the encoded event.
 * @param offset    in the buffer at which the event begins.
 * @param length    of the encoded event.
 */
private void log(final ArchiveEventCode eventCode, final DirectBuffer buffer, final int offset, final int length) {
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(eventCode.toEventCodeId(), encodedLength);
    if (index > 0) {
        try {
            encode((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, buffer, offset);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 32 with ManyToOneRingBuffer

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

the class ArchiveEventLogger method logReplaySessionError.

/**
 * Log a control response error.
 *
 * @param sessionId    associated with the response.
 * @param recordingId  to which the error applies.
 * @param errorMessage which resulted.
 */
public void logReplaySessionError(final long sessionId, final long recordingId, final String errorMessage) {
    final int length = SIZE_OF_LONG * 2 + SIZE_OF_INT + errorMessage.length();
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(REPLAY_SESSION_ERROR.toEventCodeId(), encodedLength);
    if (index > 0) {
        try {
            encodeReplaySessionError((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, sessionId, recordingId, errorMessage);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 33 with ManyToOneRingBuffer

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

the class IpcPublicationTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {
    final RingBuffer toDriverCommands = new ManyToOneRingBuffer(new UnsafeBuffer(ByteBuffer.allocate(Configuration.CONDUCTOR_BUFFER_LENGTH_DEFAULT)));
    final UnsafeBuffer counterBuffer = new UnsafeBuffer(ByteBuffer.allocate(BUFFER_LENGTH));
    final UnsafeBuffer metaDataBuffer = new UnsafeBuffer(ByteBuffer.allocate(Configuration.countersMetadataBufferLength(BUFFER_LENGTH)));
    final CountersManager countersManager = new CountersManager(metaDataBuffer, counterBuffer, StandardCharsets.US_ASCII);
    final SystemCounters systemCounters = new SystemCounters(countersManager);
    final MediaDriver.Context ctx = new MediaDriver.Context().tempBuffer(new UnsafeBuffer(new byte[METADATA_LENGTH])).ipcTermBufferLength(TERM_BUFFER_LENGTH).toDriverCommands(toDriverCommands).logFactory(new TestLogFactory()).clientProxy(mock(ClientProxy.class)).driverCommandQueue(mock(ManyToOneConcurrentArrayQueue.class)).epochClock(SystemEpochClock.INSTANCE).cachedEpochClock(new CachedEpochClock()).cachedNanoClock(new CachedNanoClock()).countersManager(countersManager).systemCounters(systemCounters).nameResolver(DefaultNameResolver.INSTANCE).nanoClock(new CachedNanoClock());
    ctx.countersValuesBuffer(counterBuffer);
    driverProxy = new DriverProxy(toDriverCommands, CLIENT_ID);
    driverConductor = new DriverConductor(ctx);
    driverConductor.onStart();
    driverProxy.addPublication(CommonContext.IPC_CHANNEL, STREAM_ID);
    driverConductor.doWork();
    ipcPublication = driverConductor.getSharedIpcPublication(STREAM_ID);
    publisherLimit = new UnsafeBufferPosition(counterBuffer, ipcPublication.publisherLimitId());
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) TestLogFactory(io.aeron.driver.buffer.TestLogFactory) SystemCounters(io.aeron.driver.status.SystemCounters) 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) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 34 with ManyToOneRingBuffer

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

the class DriverEventLogger method logUntetheredSubscriptionStateChange.

/**
 * Log an untethered subscription state change.
 *
 * @param oldState       before the change.
 * @param newState       after the change.
 * @param subscriptionId to which the change applies.
 * @param streamId       of the image.
 * @param sessionId      of the image.
 * @param <E>            type of the event.
 */
public <E extends Enum<E>> void logUntetheredSubscriptionStateChange(final E oldState, final E newState, final long subscriptionId, final int streamId, final int sessionId) {
    final int length = untetheredSubscriptionStateChangeLength(oldState, newState);
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(toEventCodeId(UNTETHERED_SUBSCRIPTION_STATE_CHANGE), encodedLength);
    if (index > 0) {
        try {
            encodeUntetheredSubscriptionStateChange((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldState, newState, subscriptionId, streamId, sessionId);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 35 with ManyToOneRingBuffer

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

the class DriverEventLogger method logFrameIn.

/**
 * Log a frame coming in from the media.
 *
 * @param buffer      containing the frame.
 * @param offset      in the buffer at which the frame begins.
 * @param frameLength of the frame.
 * @param dstAddress  for the frame.
 */
public void logFrameIn(final DirectBuffer buffer, final int offset, final int frameLength, final InetSocketAddress dstAddress) {
    final int length = frameLength + socketAddressLength(dstAddress);
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(toEventCodeId(FRAME_IN), encodedLength);
    if (index > 0) {
        try {
            encode((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, buffer, offset, dstAddress);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Aggregations

ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)50 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)12 File (java.io.File)5 MappedByteBuffer (java.nio.MappedByteBuffer)5 DriverProxy (io.aeron.DriverProxy)4 DriverTimeoutException (io.aeron.exceptions.DriverTimeoutException)3 TestLogFactory (io.aeron.driver.buffer.TestLogFactory)2 SystemCounters (io.aeron.driver.status.SystemCounters)2 AeronException (io.aeron.exceptions.AeronException)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 BeforeEach (org.junit.jupiter.api.BeforeEach)2