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 AsyncQueueFullPolicy |
asyncQueueFullPolicy |
private long |
backgroundThreadId |
private com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> |
disruptor |
private java.util.concurrent.ExecutorService |
executor |
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 int |
ringBufferSize |
private static int |
SLEEP_MILLIS_BETWEEN_DRAIN_ATTEMPTS |
private static java.util.concurrent.ThreadFactory |
THREAD_FACTORY |
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) |
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.
|
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.
|
boolean |
tryEnqueue(LogEvent event,
AsyncLoggerConfig asyncLoggerConfig) |
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stopprivate 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 static final java.util.concurrent.ThreadFactory THREAD_FACTORY
private int ringBufferSize
private AsyncQueueFullPolicy asyncQueueFullPolicy
private java.lang.Boolean mutable
private volatile com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> disruptor
private java.util.concurrent.ExecutorService executor
private long backgroundThreadId
private com.lmax.disruptor.EventFactory<AsyncLoggerConfigDisruptor.Log4jEventWrapper> factory
private com.lmax.disruptor.EventTranslatorTwoArg<AsyncLoggerConfigDisruptor.Log4jEventWrapper,LogEvent,AsyncLoggerConfig> translator
public void setLogEventFactory(LogEventFactory logEventFactory)
AsyncLoggerConfigDelegatesetLogEventFactory in interface AsyncLoggerConfigDelegatelogEventFactory - the factory usedpublic void start()
start in interface LifeCyclestart in class AbstractLifeCycleAbstractLifeCycle.stop()public boolean stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
null.stop in interface LifeCycle2stop in class AbstractLifeCycletimeout - 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)
AsyncLoggerConfigDelegateEventRoute for the event with the specified level.getEventRoute in interface AsyncLoggerConfigDelegatelogLevel - the level of the event to logEventRouteprivate 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)
enqueueEvent in interface AsyncLoggerConfigDelegateprivate void enqueue(LogEvent logEvent, AsyncLoggerConfig asyncLoggerConfig)
public boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig)
tryEnqueue in interface AsyncLoggerConfigDelegatepublic RingBufferAdmin createRingBufferAdmin(java.lang.String contextName, java.lang.String loggerConfigName)
AsyncLoggerConfigDelegateRingBufferAdmin that instruments the ringbuffer of this
AsyncLoggerConfig.createRingBufferAdmin in interface AsyncLoggerConfigDelegatecontextName - name of the LoggerContextloggerConfigName - name of the logger config