L - The Logger type to be supported. As the
AsyncLoggerImpl is being extended to support other
Logger types, we have to provide this generic parameter (for
example, sub-classes make use of the #getLoggers() method to
access the encapsulated Logger instances being sub-types of
the Logger interface).T - The type of the Record instances managed by the
Logger.public class AsyncLoggerImpl<T> extends Object implements org.refcodes.logger.Logger<T>, org.refcodes.component.Destroyable, org.refcodes.logger.LoggerAccessor.LoggerMutator<org.refcodes.logger.Logger<T>>
AsyncLoggerImpl 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
AsyncLoggerImpl.
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.
TODO: Provide configuration parameters (additional constructors) for not dismissing any log lines with the risk of a memory overflow.
| Constructor and Description |
|---|
AsyncLoggerImpl() |
AsyncLoggerImpl(ExecutorService aExecutorService,
org.refcodes.logger.Logger<T> aLogger)
Constructs an
AsyncLoggerImpl from the provided Logger
instance. |
AsyncLoggerImpl(org.refcodes.logger.Logger<T> aLogger)
Constructs an
AbstractCompositeLogger from the provided
Logger instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
void |
log(org.refcodes.tabular.Record<? extends T> aRecord) |
void |
setLogger(org.refcodes.logger.Logger<T> aLogger)
Unfortunately required as of the underlying configuration framework (at
the time of this writing) is not capable of constructor injection:
"https://commons.apache.org/proper/commons-configuration/userguide/howto_beans.html"
Constructor args "config-constrarg" seem not to be supported before
version 2.x of the apache commons-configuration artifact; as of the times
of this writing, the 2.x version was in alpha state.
|
public AsyncLoggerImpl()
public AsyncLoggerImpl(org.refcodes.logger.Logger<T> aLogger)
AbstractCompositeLogger from the provided
Logger instance.aLoggers - The Logger instances to be used for the
AbstractCompositeLogger.public AsyncLoggerImpl(ExecutorService aExecutorService, org.refcodes.logger.Logger<T> aLogger)
AsyncLoggerImpl from the provided Logger
instance.aExecutorService - The ExecutorService to use when creating
threads.aLogger - The Logger instances to be used for the
AsyncLoggerImpl.public void log(org.refcodes.tabular.Record<? extends T> aRecord) throws org.refcodes.logger.IllegalRecordRuntimeException, org.refcodes.logger.UnexpectedLogRuntimeException
log in interface org.refcodes.logger.Logger<T>org.refcodes.logger.IllegalRecordRuntimeExceptionorg.refcodes.logger.UnexpectedLogRuntimeExceptionpublic void destroy()
destroy in interface org.refcodes.component.Destroyablepublic void setLogger(org.refcodes.logger.Logger<T> aLogger)
setLogger in interface org.refcodes.logger.LoggerAccessor.LoggerMutator<org.refcodes.logger.Logger<T>>Copyright © 2016. All rights reserved.