Class AsyncLoggerDisruptor
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.async.AsyncLoggerDisruptor
- All Implemented Interfaces:
LifeCycle
,LifeCycle2
Helper class for async loggers: AsyncLoggerDisruptor handles the mechanics of working with the LMAX Disruptor, and
works with its associated AsyncLoggerContext to synchronize the life cycle of the Disruptor and its thread with the
life cycle of the context. The AsyncLoggerDisruptor of the context is shared by all AsyncLogger objects created by
that AsyncLoggerContext.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AsyncQueueFullPolicy
private long
private String
private com.lmax.disruptor.dsl.Disruptor<RingBufferLogEvent>
private static final int
private final Object
private int
private static final int
private boolean
private com.lmax.disruptor.WaitStrategy
private final Supplier<AsyncWaitStrategyFactory>
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncLoggerDisruptor
(String contextName, Supplier<AsyncWaitStrategyFactory> waitStrategyFactorySupplier) -
Method Summary
Modifier and TypeMethodDescriptioncreateRingBufferAdmin
(String jmxContextName) Creates and returns a newRingBufferAdmin
that instruments the ringbuffer of theAsyncLogger
.(package private) void
enqueueLogMessageWhenQueueFull
(com.lmax.disruptor.EventTranslatorVararg<RingBufferLogEvent> translator, AsyncLogger asyncLogger, StackTraceElement location, String fqcn, Level level, Marker marker, Message msg, Throwable thrown) (package private) void
(package private) com.lmax.disruptor.dsl.Disruptor<RingBufferLogEvent>
(package private) EventRoute
getEventRoute
(Level logLevel) (package private) com.lmax.disruptor.WaitStrategy
private static boolean
hasBacklog
(com.lmax.disruptor.dsl.Disruptor<?> theDisruptor) Returnstrue
if the specified disruptor still has unprocessed events.private boolean
hasLog4jBeenShutDown
(com.lmax.disruptor.dsl.Disruptor<RingBufferLogEvent> aDisruptor) Returnstrue
if the specified disruptor is null.boolean
Returns whether it is allowed to store non-JDK classes in ThreadLocal objects for efficiency.private void
private void
logWarningOnNpeFromDisruptorPublish
(Level level, String fqcn, Message msg, Throwable thrown) private int
void
setContextName
(String name) void
setUseThreadLocals
(boolean allow) Signals this AsyncLoggerDisruptor whether it is allowed to store non-JDK classes in ThreadLocal objects for efficiency.void
start()
Creates and starts a new Disruptor and associated thread if none currently exists.boolean
Decreases the reference count.private boolean
(package private) boolean
tryPublish
(RingBufferLogEventTranslator translator) Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
Field Details
-
SLEEP_MILLIS_BETWEEN_DRAIN_ATTEMPTS
private static final int SLEEP_MILLIS_BETWEEN_DRAIN_ATTEMPTS- See Also:
-
MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN
private static final int MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN- See Also:
-
queueFullEnqueueLock
-
disruptor
-
contextName
-
waitStrategyFactorySupplier
-
useThreadLocalTranslator
private boolean useThreadLocalTranslator -
backgroundThreadId
private long backgroundThreadId -
asyncQueueFullPolicy
-
ringBufferSize
private int ringBufferSize -
waitStrategy
private com.lmax.disruptor.WaitStrategy waitStrategy
-
-
Constructor Details
-
AsyncLoggerDisruptor
AsyncLoggerDisruptor(String contextName, Supplier<AsyncWaitStrategyFactory> waitStrategyFactorySupplier)
-
-
Method Details
-
getWaitStrategy
com.lmax.disruptor.WaitStrategy getWaitStrategy() -
getContextName
-
setContextName
-
getDisruptor
com.lmax.disruptor.dsl.Disruptor<RingBufferLogEvent> getDisruptor() -
start
public void start()Creates and starts a new Disruptor and associated thread if none currently exists.- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractLifeCycle
- See Also:
-
stop
Decreases the reference count. If the reference count reached zero, the Disruptor and its associated thread are shut down and their references set tonull
.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractLifeCycle
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
hasBacklog
private static boolean hasBacklog(com.lmax.disruptor.dsl.Disruptor<?> theDisruptor) Returnstrue
if the specified disruptor still has unprocessed events. -
createRingBufferAdmin
Creates and returns a newRingBufferAdmin
that instruments the ringbuffer of theAsyncLogger
.- Parameters:
jmxContextName
- name of theAsyncLoggerContext
- Returns:
- a new
RingBufferAdmin
that instruments the ringbuffer
-
getEventRoute
-
remainingDisruptorCapacity
private int remainingDisruptorCapacity() -
hasLog4jBeenShutDown
private boolean hasLog4jBeenShutDown(com.lmax.disruptor.dsl.Disruptor<RingBufferLogEvent> aDisruptor) Returnstrue
if the specified disruptor is null. -
tryPublish
-
enqueueLogMessageWhenQueueFull
-
enqueueLogMessageWhenQueueFull
void enqueueLogMessageWhenQueueFull(com.lmax.disruptor.EventTranslatorVararg<RingBufferLogEvent> translator, AsyncLogger asyncLogger, StackTraceElement location, String fqcn, Level level, Marker marker, Message msg, Throwable thrown) -
synchronizeEnqueueWhenQueueFull
private boolean synchronizeEnqueueWhenQueueFull() -
logWarningOnNpeFromDisruptorPublish
-
logWarningOnNpeFromDisruptorPublish
-
isUseThreadLocals
public boolean isUseThreadLocals()Returns whether it is allowed to store non-JDK classes in ThreadLocal objects for efficiency.- Returns:
- whether AsyncLoggers are allowed to use ThreadLocal objects
- Since:
- 2.5
- See Also:
-
setUseThreadLocals
public void setUseThreadLocals(boolean allow) Signals this AsyncLoggerDisruptor whether it is allowed to store non-JDK classes in ThreadLocal objects for efficiency.This property may be modified after the
start()
method has been called.- Parameters:
allow
- whether AsyncLoggers are allowed to use ThreadLocal objects- Since:
- 2.5
- See Also:
-