public class AsyncLoggerConfigDisruptor extends AbstractLifeCycle implements AsyncLoggerConfigDelegate
AsyncLoggerConfig
class from the LMAX Disruptor library.
AsyncLoggerConfig
is a plugin, and will be loaded even if users do not configure any <asyncLogger>
or
<asyncRoot>
elements in the configuration. If AsyncLoggerConfig
has inner classes that extend or
implement classes from the Disruptor library, a NoClassDefFoundError
is thrown if the Disruptor jar is not in
the classpath when the PluginManager loads the AsyncLoggerConfig
plugin from the pre-defined plugins
definition file.
This class serves to make the dependency on the Disruptor optional, so that these classes are only loaded when the
AsyncLoggerConfig
is actually used.
Modifier and Type | Class and Description |
---|---|
static class |
AsyncLoggerConfigDisruptor.Log4jEventWrapper
RingBuffer events contain all information necessary to perform the work in a separate thread.
|
private static class |
AsyncLoggerConfigDisruptor.Log4jEventWrapperHandler
EventHandler performs the work in a separate thread.
|
LifeCycle.State
Modifier and Type | Field and Description |
---|---|
private boolean |
alreadyLoggedWarning |
private AsyncQueueFullPolicy |
asyncQueueFullPolicy |
private long |
backgroundThreadId |
private com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> |
disruptor |
private com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> |
factory |
private static com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> |
FACTORY
Factory used to populate the RingBuffer with events.
|
private static int |
MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN |
private java.lang.Boolean |
mutable |
private static com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> |
MUTABLE_FACTORY
Factory used to populate the RingBuffer with events.
|
private static com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> |
MUTABLE_TRANSLATOR
Object responsible for passing on data to a RingBuffer event with a MutableLogEvent.
|
private java.lang.Object |
queueFullEnqueueLock |
private int |
ringBufferSize |
private static int |
SLEEP_MILLIS_BETWEEN_DRAIN_ATTEMPTS |
private com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> |
translator |
private static com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> |
TRANSLATOR
Object responsible for passing on data to a specific RingBuffer event.
|
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
Constructor and Description |
---|
AsyncLoggerConfigDisruptor() |
Modifier and Type | Method and Description |
---|---|
RingBufferAdmin |
createRingBufferAdmin(java.lang.String contextName,
java.lang.String loggerConfigName)
Creates and returns a new
RingBufferAdmin that instruments the ringbuffer of this
AsyncLoggerConfig . |
private void |
enqueue(LogEvent logEvent,
AsyncLoggerConfig asyncLoggerConfig) |
void |
enqueueEvent(LogEvent event,
AsyncLoggerConfig asyncLoggerConfig)
Enqueues the
LogEvent on the mixed configuration ringbuffer. |
private LogEvent |
ensureImmutable(LogEvent event) |
EventRoute |
getEventRoute(Level logLevel)
Returns the
EventRoute for the event with the specified level. |
private static boolean |
hasBacklog(com.lmax.disruptor.dsl.Disruptor<?> theDisruptor)
Returns
true if the specified disruptor still has unprocessed events. |
private boolean |
hasLog4jBeenShutDown(com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> aDisruptor)
Returns
true if the specified disruptor is null. |
private LogEvent |
prepareEvent(LogEvent event) |
private int |
remainingDisruptorCapacity() |
void |
setLogEventFactory(LogEventFactory logEventFactory)
Notifies the delegate what LogEventFactory an AsyncLoggerConfig is using, so the delegate can determine
whether to populate the ring buffer with mutable log events or not.
|
private void |
showWarningAboutCustomLogEventWithReusableMessage(LogEvent logEvent) |
void |
start()
Increases the reference count and creates and starts a new Disruptor and associated thread if none currently
exists.
|
boolean |
stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Decreases the reference count.
|
private boolean |
synchronizeEnqueueWhenQueueFull() |
boolean |
tryEnqueue(LogEvent event,
AsyncLoggerConfig asyncLoggerConfig) |
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
private static final int MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN
private static final int SLEEP_MILLIS_BETWEEN_DRAIN_ATTEMPTS
private static final com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> FACTORY
private static final com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> MUTABLE_FACTORY
private static final com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> TRANSLATOR
private static final com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> MUTABLE_TRANSLATOR
private int ringBufferSize
private AsyncQueueFullPolicy asyncQueueFullPolicy
private java.lang.Boolean mutable
private volatile com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> disruptor
private long backgroundThreadId
private com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> factory
private com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> translator
private volatile boolean alreadyLoggedWarning
private final java.lang.Object queueFullEnqueueLock
public void setLogEventFactory(LogEventFactory logEventFactory)
AsyncLoggerConfigDelegate
setLogEventFactory
in interface AsyncLoggerConfigDelegate
logEventFactory
- the factory usedpublic void start()
start
in interface LifeCycle
start
in class AbstractLifeCycle
AbstractLifeCycle.stop()
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)
null
.stop
in interface LifeCycle2
stop
in class AbstractLifeCycle
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argumentprivate static boolean hasBacklog(com.lmax.disruptor.dsl.Disruptor<?> theDisruptor)
true
if the specified disruptor still has unprocessed events.public EventRoute getEventRoute(Level logLevel)
AsyncLoggerConfigDelegate
EventRoute
for the event with the specified level.getEventRoute
in interface AsyncLoggerConfigDelegate
logLevel
- the level of the event to logEventRoute
private int remainingDisruptorCapacity()
private boolean hasLog4jBeenShutDown(com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> aDisruptor)
true
if the specified disruptor is null.public void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig)
AsyncLoggerConfigDelegate
LogEvent
on the mixed configuration ringbuffer.
This method must only be used after AsyncLoggerConfigDelegate.tryEnqueue(LogEvent, AsyncLoggerConfig)
returns false
indicating that the ringbuffer is full, otherwise it may incur unnecessary synchronization.enqueueEvent
in interface AsyncLoggerConfigDelegate
private void showWarningAboutCustomLogEventWithReusableMessage(LogEvent logEvent)
private void enqueue(LogEvent logEvent, AsyncLoggerConfig asyncLoggerConfig)
private boolean synchronizeEnqueueWhenQueueFull()
public boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig)
tryEnqueue
in interface AsyncLoggerConfigDelegate
public RingBufferAdmin createRingBufferAdmin(java.lang.String contextName, java.lang.String loggerConfigName)
AsyncLoggerConfigDelegate
RingBufferAdmin
that instruments the ringbuffer of this
AsyncLoggerConfig
.createRingBufferAdmin
in interface AsyncLoggerConfigDelegate
contextName
- name of the LoggerContext
loggerConfigName
- name of the logger config