- java.lang.Object
-
- org.refcodes.logger.alt.async.AsyncLogger<T>
-
- Type Parameters:
T- The type of theRecordinstances managed by theLogger.
- All Implemented Interfaces:
org.refcodes.component.Destroyable,org.refcodes.logger.LogDecorator,org.refcodes.logger.Logger<T>,org.refcodes.logger.LoggerAccessor.LoggerMutator<org.refcodes.logger.Logger<T>>
public class AsyncLogger<T> extends Object implements org.refcodes.logger.Logger<T>, org.refcodes.component.Destroyable, org.refcodes.logger.LoggerAccessor.LoggerMutator<org.refcodes.logger.Logger<T>>
TheAsyncLoggeruses the asynchronous patter to forwardLoggerfunctionality to an encapsulatedLoggerinstance.Internally a log line queue (holding
Recordinstances to be logged) as well a daemon thread (taking elements from the log line queue) are used to decouple the encapsulatedLoggerinstance from the asynchronousAsyncLogger.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
Loggerinstance cannot take the nextRecordin 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.WARNis printed out.
-
-
Constructor Summary
Constructors Constructor Description AsyncLogger()Instantiates a new async logger.AsyncLogger(ExecutorService aExecutorService, org.refcodes.logger.Logger<T> aLogger)Constructs anAsyncLoggerfrom the providedLoggerinstance.AsyncLogger(org.refcodes.logger.Logger<T> aLogger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()voidlog(org.refcodes.tabular.Record<? extends T> aRecord)voidprintSeparator()voidsetLogger(org.refcodes.logger.Logger<T> aLogger)
-
-
-
Constructor Detail
-
AsyncLogger
public AsyncLogger()
Instantiates a new async logger.
-
AsyncLogger
public AsyncLogger(org.refcodes.logger.Logger<T> aLogger)
- Parameters:
aLogger- The a logger which is to be enriched with asynchronous functionality.
-
AsyncLogger
public AsyncLogger(ExecutorService aExecutorService, org.refcodes.logger.Logger<T> aLogger)
Constructs anAsyncLoggerfrom the providedLoggerinstance.- Parameters:
aExecutorService- TheExecutorServiceto use when creating threads.aLogger- TheLoggerinstances to be used for theAsyncLogger.
-
-
Method Detail
-
log
public void log(org.refcodes.tabular.Record<? extends T> aRecord) throws org.refcodes.logger.IllegalRecordRuntimeException, org.refcodes.logger.UnexpectedLogRuntimeException
- Specified by:
login interfaceorg.refcodes.logger.Logger<T>- Throws:
org.refcodes.logger.IllegalRecordRuntimeExceptionorg.refcodes.logger.UnexpectedLogRuntimeException
-
printSeparator
public void printSeparator()
- Specified by:
printSeparatorin interfaceorg.refcodes.logger.LogDecorator
-
destroy
public void destroy()
- Specified by:
destroyin interfaceorg.refcodes.component.Destroyable
-
-