Search in sources :

Example 1 with ErrorConsumer

use of org.agrona.concurrent.errors.ErrorConsumer 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)

Example 2 with ErrorConsumer

use of org.agrona.concurrent.errors.ErrorConsumer in project aeron by real-logic.

the class ClusterMarkFile method saveErrorLog.

public static int saveErrorLog(final PrintStream out, final AtomicBuffer errorBuffer) {
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
    final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) -> out.format("***%n%d observations from %s to %s for:%n %s%n", count, dateFormat.format(new Date(firstTimestamp)), dateFormat.format(new Date(lastTimestamp)), ex);
    final int distinctErrorCount = ErrorLogReader.read(errorBuffer, errorConsumer);
    out.format("%n%d distinct errors observed.%n", distinctErrorCount);
    return distinctErrorCount;
}
Also used : MarkFileHeaderDecoder(io.aeron.cluster.codecs.mark.MarkFileHeaderDecoder) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) ClusterComponentType(io.aeron.cluster.codecs.mark.ClusterComponentType) VarAsciiEncodingEncoder(io.aeron.cluster.codecs.mark.VarAsciiEncodingEncoder) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) FileOutputStream(java.io.FileOutputStream) SimpleDateFormat(java.text.SimpleDateFormat) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) File(java.io.File) org.agrona(org.agrona) Objects(java.util.Objects) Consumer(java.util.function.Consumer) EpochClock(org.agrona.concurrent.EpochClock) MarkFileHeaderEncoder(io.aeron.cluster.codecs.mark.MarkFileHeaderEncoder) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with ErrorConsumer

use of org.agrona.concurrent.errors.ErrorConsumer in project aeron by real-logic.

the class CommonContext method printErrorLog.

/**
 * Print the contents of an error log to a {@link PrintStream} in human-readable format.
 *
 * @param errorBuffer to read errors from.
 * @param out         print the errors to.
 * @return number of distinct errors observed.
 */
public static int printErrorLog(final AtomicBuffer errorBuffer, final PrintStream out) {
    int distinctErrorCount = 0;
    if (errorBuffer.capacity() > 0 && ErrorLogReader.hasErrors(errorBuffer)) {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
        final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) -> out.format("***%n%d observations from %s to %s for:%n %s%n", count, dateFormat.format(new Date(firstTimestamp)), dateFormat.format(new Date(lastTimestamp)), ex);
        distinctErrorCount = ErrorLogReader.read(errorBuffer, errorConsumer);
        out.format("%n%d distinct errors observed.%n", distinctErrorCount);
    }
    return distinctErrorCount;
}
Also used : AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) LoggingErrorHandler(org.agrona.concurrent.errors.LoggingErrorHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) DriverTimeoutException(io.aeron.exceptions.DriverTimeoutException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) SimpleDateFormat(java.text.SimpleDateFormat) ByteBuffer(java.nio.ByteBuffer) DistinctErrorLog(org.agrona.concurrent.errors.DistinctErrorLog) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) org.agrona(org.agrona) ConcurrentConcludeException(io.aeron.exceptions.ConcurrentConcludeException) Map(java.util.Map) System.getProperty(java.lang.System.getProperty) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) AtomicIntegerFieldUpdater.newUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater) CncFileDescriptor.cncVersionOffset(io.aeron.CncFileDescriptor.cncVersionOffset) PrintStream(java.io.PrintStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FileOutputStream(java.io.FileOutputStream) UUID(java.util.UUID) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Long.getLong(java.lang.Long.getLong) Aeron.sleep(io.aeron.Aeron.sleep) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with ErrorConsumer

use of org.agrona.concurrent.errors.ErrorConsumer in project Aeron by real-logic.

the class CommonContext method printErrorLog.

/**
 * Print the contents of an error log to a {@link PrintStream} in human-readable format.
 *
 * @param errorBuffer to read errors from.
 * @param out         print the errors to.
 * @return number of distinct errors observed.
 */
public static int printErrorLog(final AtomicBuffer errorBuffer, final PrintStream out) {
    int distinctErrorCount = 0;
    if (errorBuffer.capacity() > 0 && ErrorLogReader.hasErrors(errorBuffer)) {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
        final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) -> out.format("***%n%d observations from %s to %s for:%n %s%n", count, dateFormat.format(new Date(firstTimestamp)), dateFormat.format(new Date(lastTimestamp)), ex);
        distinctErrorCount = ErrorLogReader.read(errorBuffer, errorConsumer);
        out.format("%n%d distinct errors observed.%n", distinctErrorCount);
    }
    return distinctErrorCount;
}
Also used : AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) LoggingErrorHandler(org.agrona.concurrent.errors.LoggingErrorHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) DriverTimeoutException(io.aeron.exceptions.DriverTimeoutException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) SimpleDateFormat(java.text.SimpleDateFormat) ByteBuffer(java.nio.ByteBuffer) DistinctErrorLog(org.agrona.concurrent.errors.DistinctErrorLog) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) org.agrona(org.agrona) ConcurrentConcludeException(io.aeron.exceptions.ConcurrentConcludeException) Map(java.util.Map) System.getProperty(java.lang.System.getProperty) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) AtomicIntegerFieldUpdater.newUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater) CncFileDescriptor.cncVersionOffset(io.aeron.CncFileDescriptor.cncVersionOffset) PrintStream(java.io.PrintStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FileOutputStream(java.io.FileOutputStream) UUID(java.util.UUID) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Long.getLong(java.lang.Long.getLong) Aeron.sleep(io.aeron.Aeron.sleep) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

File (java.io.File)4 PrintStream (java.io.PrintStream)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4 Consumer (java.util.function.Consumer)4 AtomicBuffer (org.agrona.concurrent.AtomicBuffer)4 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)4 ErrorConsumer (org.agrona.concurrent.errors.ErrorConsumer)4 ErrorLogReader (org.agrona.concurrent.errors.ErrorLogReader)4 Aeron.sleep (io.aeron.Aeron.sleep)3 DriverTimeoutException (io.aeron.exceptions.DriverTimeoutException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 Long.getLong (java.lang.Long.getLong)3 System.getProperty (java.lang.System.getProperty)3 MappedByteBuffer (java.nio.MappedByteBuffer)3 UUID (java.util.UUID)3 org.agrona (org.agrona)3 ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)3 CncFileDescriptor.cncVersionOffset (io.aeron.CncFileDescriptor.cncVersionOffset)2