Class AsyncLogger<T>

  • Type Parameters:
    T - The type of the Record instances managed by the Logger.
    All Implemented Interfaces:
    org.refcodes.component.Destroyable, org.refcodes.logger.Logger<T>, org.refcodes.logger.LoggerAccessor.LoggerMutator<org.refcodes.logger.Logger<T>>

    public class AsyncLogger<T>
    extends java.lang.Object
    implements org.refcodes.logger.Logger<T>, org.refcodes.component.Destroyable, org.refcodes.logger.LoggerAccessor.LoggerMutator<org.refcodes.logger.Logger<T>>
    The AsyncLogger uses the asynchronous patter to forward Logger functionality to an encapsulated Logger instance.

    Internally a log line queue (holding Record instances to be logged) as well a daemon thread (taking elements from the log line queue) are used to decouple the encapsulated Logger instance from the asynchronous AsyncLogger.

    A given number of retries are approached in case there is an overflow of the log line queue; this happens when the queue is full the encapsulated Logger instance cannot take the next Record in time.

    To avoid a building up of the log line queue, eventually causing an out of memory, log lines not being taken into the log line queue within the given number of retries, them log lines are dismissed. In such a case a warning with a LogPriority.WARN is printed out.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable

        org.refcodes.component.Destroyable.DestroyAutomaton
    • Constructor Summary

      Constructors 
      Constructor Description
      AsyncLogger()
      Instantiates a new async logger.
      AsyncLogger​(java.util.concurrent.ExecutorService aExecutorService, org.refcodes.logger.Logger<T> aLogger)
      Constructs an AsyncLogger from the provided Logger instance.
      AsyncLogger​(org.refcodes.logger.Logger<T> aLogger)
      Constructs an asynchronous Logger (AsyncLogger) from the provided Logger instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      void log​(org.refcodes.tabular.Record<? extends T> aRecord)
      void printSeparator()
      void setLogger​(org.refcodes.logger.Logger<T> aLogger)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AsyncLogger

        public AsyncLogger()
        Instantiates a new async logger.
      • AsyncLogger

        public AsyncLogger​(org.refcodes.logger.Logger<T> aLogger)
        Constructs an asynchronous Logger (AsyncLogger) from the provided Logger instance.
        Parameters:
        aLogger - The a logger which is to be enriched with asynchronous functionality.
      • AsyncLogger

        public AsyncLogger​(java.util.concurrent.ExecutorService aExecutorService,
                           org.refcodes.logger.Logger<T> aLogger)
        Constructs an AsyncLogger from the provided Logger instance.
        Parameters:
        aExecutorService - The ExecutorService to use when creating threads.
        aLogger - The Logger instances to be used for the AsyncLogger.
    • Method Detail

      • log

        public void log​(org.refcodes.tabular.Record<? extends T> aRecord)
                 throws org.refcodes.logger.IllegalRecordRuntimeException,
                        org.refcodes.logger.UnexpectedLogRuntimeException
        Specified by:
        log in interface org.refcodes.logger.Logger<T>
        Throws:
        org.refcodes.logger.IllegalRecordRuntimeException
        org.refcodes.logger.UnexpectedLogRuntimeException
      • printSeparator

        public void printSeparator()
        Specified by:
        printSeparator in interface org.refcodes.logger.Logger<T>
      • destroy

        public void destroy()
        Specified by:
        destroy in interface org.refcodes.component.Destroyable
      • setLogger

        public void setLogger​(org.refcodes.logger.Logger<T> aLogger)
        Specified by:
        setLogger in interface org.refcodes.logger.LoggerAccessor.LoggerMutator<T>