Search in sources :

Example 1 with CNC_VERSION

use of io.aeron.CncFileDescriptor.CNC_VERSION in project aeron by real-logic.

the class CommonContext method saveErrorLog.

/**
 * Read the error log to a given {@link PrintStream}
 *
 * @param out           to write the error log contents to.
 * @param cncByteBuffer containing the error log.
 * @return the number of observations from the error log.
 */
public int saveErrorLog(final PrintStream out, final MappedByteBuffer cncByteBuffer) {
    if (null == cncByteBuffer) {
        return 0;
    }
    final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
    if (CNC_VERSION != cncVersion) {
        throw new IllegalStateException("Aeron CnC version does not match: required=" + CNC_VERSION + " version=" + cncVersion);
    }
    final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
    final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) -> formatError(out, dateFormat, count, firstTimestamp, lastTimestamp, ex);
    final int distinctErrorCount = ErrorLogReader.read(buffer, errorConsumer);
    out.format("%n%d distinct errors observed.%n", distinctErrorCount);
    return distinctErrorCount;
}
Also used : PrintStream(java.io.PrintStream) CNC_VERSION(io.aeron.CncFileDescriptor.CNC_VERSION) Date(java.util.Date) DriverTimeoutException(io.aeron.exceptions.DriverTimeoutException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) SimpleDateFormat(java.text.SimpleDateFormat) UUID(java.util.UUID) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) IoUtil(org.agrona.IoUtil) File(java.io.File) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) Consumer(java.util.function.Consumer) SystemUtil(org.agrona.SystemUtil) Long.getLong(java.lang.Long.getLong) Aeron.sleep(io.aeron.Aeron.sleep) System.getProperty(java.lang.System.getProperty) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Aeron.sleep (io.aeron.Aeron.sleep)1 CNC_VERSION (io.aeron.CncFileDescriptor.CNC_VERSION)1 DriverTimeoutException (io.aeron.exceptions.DriverTimeoutException)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 Long.getLong (java.lang.Long.getLong)1 System.getProperty (java.lang.System.getProperty)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 UUID (java.util.UUID)1 Consumer (java.util.function.Consumer)1 IoUtil (org.agrona.IoUtil)1 SystemUtil (org.agrona.SystemUtil)1 AtomicBuffer (org.agrona.concurrent.AtomicBuffer)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 ErrorConsumer (org.agrona.concurrent.errors.ErrorConsumer)1 ErrorLogReader (org.agrona.concurrent.errors.ErrorLogReader)1 ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)1