Search in sources :

Example 46 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 47 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 48 with ManyToOneRingBuffer

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

the class ArchiveEventLogger method logSessionStateChange.

/**
 * Log a state change event for an archive control session
 *
 * @param eventCode        for the type of state change.
 * @param oldState         before the change.
 * @param newState         after the change.
 * @param controlSessionId identity for the control session on the Archive.
 * @param <E>              type representing the state change.
 */
public <E extends Enum<E>> void logSessionStateChange(final ArchiveEventCode eventCode, final E oldState, final E newState, final long controlSessionId) {
    final int length = sessionStateChangeLength(oldState, newState);
    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 {
            encodeSessionStateChange((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldState, newState, controlSessionId);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 49 with ManyToOneRingBuffer

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

the class ArchiveEventLogger method logCatalogResize.

/**
 * Log a Catalog resize event.
 *
 * @param oldCatalogLength before the resize.
 * @param newCatalogLength after the resize.
 */
public void logCatalogResize(final long oldCatalogLength, final long newCatalogLength) {
    final int length = SIZE_OF_LONG * 2;
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(CATALOG_RESIZE.toEventCodeId(), encodedLength);
    if (index > 0) {
        try {
            encodeCatalogResize((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldCatalogLength, newCatalogLength);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 50 with ManyToOneRingBuffer

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

the class CommonContext method isDriverActive.

/**
 * Is a media driver active in the current mapped CnC buffer? If the driver is starting then it will wait for
 * up to the driverTimeoutMs by checking for the cncVersion being set.
 *
 * @param driverTimeoutMs for the driver liveness check.
 * @param logger          for feedback as liveness checked.
 * @param cncByteBuffer   for the existing CnC file.
 * @return true if a driver is active or false if not.
 */
public static boolean isDriverActive(final long driverTimeoutMs, final Consumer<String> logger, final ByteBuffer cncByteBuffer) {
    if (null == cncByteBuffer) {
        return false;
    }
    final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
    final long startTimeMs = System.currentTimeMillis();
    int cncVersion;
    while (0 == (cncVersion = cncMetaDataBuffer.getIntVolatile(CncFileDescriptor.cncVersionOffset(0)))) {
        if (System.currentTimeMillis() > (startTimeMs + driverTimeoutMs)) {
            throw new DriverTimeoutException("CnC file is created but not initialised.");
        }
        sleep(1);
    }
    CncFileDescriptor.checkVersion(cncVersion);
    final ManyToOneRingBuffer toDriverBuffer = new ManyToOneRingBuffer(CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer));
    final long timestampMs = toDriverBuffer.consumerHeartbeatTime();
    final long nowMs = System.currentTimeMillis();
    final long timestampAgeMs = nowMs - timestampMs;
    logger.accept("INFO: Aeron toDriver consumer heartbeat is (ms): " + timestampAgeMs);
    return timestampAgeMs <= driverTimeoutMs;
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) DriverTimeoutException(io.aeron.exceptions.DriverTimeoutException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

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