Class AsyncLoggerConfigDisruptor

java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.async.AsyncLoggerConfigDisruptor
All Implemented Interfaces:
AsyncLoggerConfigDelegate, LifeCycle, LifeCycle2

public class AsyncLoggerConfigDisruptor extends AbstractLifeCycle implements AsyncLoggerConfigDelegate
Helper class decoupling the 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.

  • Field Details

  • Constructor Details

  • Method Details

    • getWaitStrategy

      com.lmax.disruptor.WaitStrategy getWaitStrategy()
    • setLogEventFactory

      public void setLogEventFactory(LogEventFactory logEventFactory)
      Description copied from interface: AsyncLoggerConfigDelegate
      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. This method may be invoked multiple times for all AsyncLoggerConfigs that use this delegate.
      Specified by:
      setLogEventFactory in interface AsyncLoggerConfigDelegate
      Parameters:
      logEventFactory - the factory used
    • start

      public void start()
      Increases the reference count and creates and starts a new Disruptor and associated thread if none currently exists.
      Specified by:
      start in interface LifeCycle
      Overrides:
      start in class AbstractLifeCycle
      See Also:
    • stop

      public boolean stop(long timeout, TimeUnit timeUnit)
      Decreases the reference count. If the reference count reached zero, the Disruptor and its associated thread are shut down and their references set to null.
      Specified by:
      stop in interface LifeCycle2
      Overrides:
      stop in class AbstractLifeCycle
      Parameters:
      timeout - the maximum time to wait
      timeUnit - 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)
      Returns true if the specified disruptor still has unprocessed events.
    • getEventRoute

      public EventRoute getEventRoute(Level logLevel)
      Description copied from interface: AsyncLoggerConfigDelegate
      Returns the EventRoute for the event with the specified level.
      Specified by:
      getEventRoute in interface AsyncLoggerConfigDelegate
      Parameters:
      logLevel - the level of the event to log
      Returns:
      the EventRoute
    • remainingDisruptorCapacity

      private int remainingDisruptorCapacity()
    • hasLog4jBeenShutDown

      private boolean hasLog4jBeenShutDown(com.lmax.disruptor.dsl.Disruptor<AsyncLoggerConfigDisruptor.Log4jEventWrapper> aDisruptor)
      Returns true if the specified disruptor is null.
    • enqueueEvent

      public void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig)
      Description copied from interface: AsyncLoggerConfigDelegate
      Enqueues the 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.
      Specified by:
      enqueueEvent in interface AsyncLoggerConfigDelegate
    • prepareEvent

      private LogEvent prepareEvent(LogEvent event)
    • showWarningAboutCustomLogEventWithReusableMessage

      private void showWarningAboutCustomLogEventWithReusableMessage(LogEvent logEvent)
    • enqueue

      private void enqueue(LogEvent logEvent, AsyncLoggerConfig asyncLoggerConfig)
    • synchronizeEnqueueWhenQueueFull

      private boolean synchronizeEnqueueWhenQueueFull()
    • tryEnqueue

      public boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig)
      Specified by:
      tryEnqueue in interface AsyncLoggerConfigDelegate
    • ensureImmutable

      private LogEvent ensureImmutable(LogEvent event)
    • createRingBufferAdmin

      public RingBufferAdmin createRingBufferAdmin(String contextName, String loggerConfigName)
      Description copied from interface: AsyncLoggerConfigDelegate
      Creates and returns a new RingBufferAdmin that instruments the ringbuffer of this AsyncLoggerConfig.
      Specified by:
      createRingBufferAdmin in interface AsyncLoggerConfigDelegate
      Parameters:
      contextName - name of the LoggerContext
      loggerConfigName - name of the logger config
      Returns:
      the RingBufferAdmin that instruments the ringbuffer