Event
- type of event (ILoggingEvent
or IAccessEvent
).public abstract class AsyncDisruptorAppender<Event extends DeferredProcessingAware,Listener extends AppenderListener<Event>> extends UnsynchronizedAppenderBase<Event>
RingBuffer
as the interthread data exchange mechanism (as opposed to a BlockingQueue
used by logback's AsyncAppender
).
See the LMAX Disruptor documentation
for more information about the advantages of using a RingBuffer
over a BlockingQueue
.
This appender will never block the logging thread, since it uses
RingBuffer.tryPublishEvent(EventTranslatorOneArg, Object)
to publish events (rather than RingBuffer.publishEvent(EventTranslatorOneArg, Object)
).
If the RingBuffer is full, and the event cannot be published,
the event will be dropped. A warning message will be logged to
logback's context every droppedWarnFrequency
consecutive dropped events.
A single handler thread will be used to handle the actual handling of the event.
Subclasses are required to set the eventHandler
to define
the logic that executes in the handler thread.
For example, DelegatingAsyncDisruptorAppender
for will delegate
appending of the event to another appender in the handler thread.
By default, child threads created by this appender will be daemon threads,
and therefore allow the JVM to exit gracefully without
needing to explicitly shut down the appender.
Note that in this case, it is possible for appended log events to not
be handled (if the child thread has not had a chance to process them yet).
By setting setDaemon(boolean)
to false, you can change this behavior.
When false, child threads created by this appender will not be daemon threads,
and therefore will prevent the JVM from shutting down
until the appender is explicitly shut down.
Set this to false if you want to ensure that every log event
prior to shutdown is handled.
Modifier and Type | Class and Description |
---|---|
protected static class |
AsyncDisruptorAppender.LogEvent<Event>
Event wrapper object used for each element of the
RingBuffer . |
protected static class |
AsyncDisruptorAppender.LogEventTranslator<Event>
Sets the
AsyncDisruptorAppender.LogEvent.event to the logback Event. |
Modifier and Type | Field and Description |
---|---|
protected static String |
APPENDER_NAME_FORMAT |
static int |
DEFAULT_DROPPED_WARN_FREQUENCY |
static com.lmax.disruptor.dsl.ProducerType |
DEFAULT_PRODUCER_TYPE |
static int |
DEFAULT_RING_BUFFER_SIZE |
static String |
DEFAULT_THREAD_NAME_FORMAT |
static com.lmax.disruptor.WaitStrategy |
DEFAULT_WAIT_STRATEGY |
protected List<Listener> |
listeners
These listeners will be notified when certain events occur on this appender.
|
protected static String |
THREAD_INDEX_FORMAT |
name, started
context
Constructor and Description |
---|
AsyncDisruptorAppender() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Listener listener) |
protected void |
append(Event event) |
protected String |
calculateThreadName() |
protected void |
fireAppenderStarted() |
protected void |
fireAppenderStopped() |
protected void |
fireEventAppended(Event event,
long durationInNanos) |
protected void |
fireEventAppendFailed(Event event,
Throwable reason) |
protected com.lmax.disruptor.dsl.Disruptor<AsyncDisruptorAppender.LogEvent<Event>> |
getDisruptor() |
int |
getDroppedWarnFrequency() |
protected com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> |
getEventHandler() |
protected com.lmax.disruptor.EventTranslatorOneArg<AsyncDisruptorAppender.LogEvent<Event>,Event> |
getEventTranslator() |
protected ScheduledExecutorService |
getExecutorService() |
com.lmax.disruptor.dsl.ProducerType |
getProducerType() |
int |
getRingBufferSize() |
ThreadFactory |
getThreadFactory() |
String |
getThreadNameFormat() |
protected List<Object> |
getThreadNameFormatParams() |
String |
getThreadNamePrefix()
Deprecated.
|
protected int |
getThreadPoolCoreSize() |
com.lmax.disruptor.WaitStrategy |
getWaitStrategy() |
boolean |
isAddDefaultStatusListener() |
boolean |
isDaemon() |
protected void |
prepareForDeferredProcessing(Event event) |
void |
removeListener(Listener listener) |
void |
setAddDefaultStatusListener(boolean addDefaultStatusListener) |
void |
setDaemon(boolean useDaemonThread) |
void |
setDroppedWarnFrequency(int droppedWarnFrequency) |
protected void |
setEventFactory(net.logstash.logback.appender.AsyncDisruptorAppender.LogEventFactory<Event> eventFactory) |
protected void |
setEventHandler(com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> eventHandler) |
protected void |
setEventTranslator(com.lmax.disruptor.EventTranslatorOneArg<AsyncDisruptorAppender.LogEvent<Event>,Event> eventTranslator) |
void |
setProducerType(com.lmax.disruptor.dsl.ProducerType producerType) |
void |
setRingBufferSize(int ringBufferSize) |
void |
setThreadFactory(ThreadFactory threadFactory) |
void |
setThreadNameFormat(String threadNameFormat)
Pattern used by the to set the handler thread names.
|
void |
setThreadNamePrefix(String threadNamePrefix)
Deprecated.
use
setThreadNameFormat(String) instead. |
protected void |
setThreadPoolCoreSize(int threadPoolCoreSize) |
void |
setWaitStrategy(com.lmax.disruptor.WaitStrategy waitStrategy) |
void |
setWaitStrategyType(String waitStrategyType) |
void |
start() |
void |
stop() |
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
protected static final String APPENDER_NAME_FORMAT
protected static final String THREAD_INDEX_FORMAT
public static final String DEFAULT_THREAD_NAME_FORMAT
public static final int DEFAULT_RING_BUFFER_SIZE
public static final com.lmax.disruptor.dsl.ProducerType DEFAULT_PRODUCER_TYPE
public static final com.lmax.disruptor.WaitStrategy DEFAULT_WAIT_STRATEGY
public static final int DEFAULT_DROPPED_WARN_FREQUENCY
protected final List<Listener extends AppenderListener<Event>> listeners
public void start()
start
in interface LifeCycle
start
in class UnsynchronizedAppenderBase<Event extends DeferredProcessingAware>
public void stop()
stop
in interface LifeCycle
stop
in class UnsynchronizedAppenderBase<Event extends DeferredProcessingAware>
protected void append(Event event)
append
in class UnsynchronizedAppenderBase<Event extends DeferredProcessingAware>
protected void prepareForDeferredProcessing(Event event)
protected String calculateThreadName()
protected void fireAppenderStarted()
protected void fireAppenderStopped()
protected void fireEventAppended(Event event, long durationInNanos)
protected void setEventFactory(net.logstash.logback.appender.AsyncDisruptorAppender.LogEventFactory<Event> eventFactory)
protected com.lmax.disruptor.EventTranslatorOneArg<AsyncDisruptorAppender.LogEvent<Event>,Event> getEventTranslator()
protected void setEventTranslator(com.lmax.disruptor.EventTranslatorOneArg<AsyncDisruptorAppender.LogEvent<Event>,Event> eventTranslator)
protected ScheduledExecutorService getExecutorService()
protected com.lmax.disruptor.dsl.Disruptor<AsyncDisruptorAppender.LogEvent<Event>> getDisruptor()
protected int getThreadPoolCoreSize()
protected void setThreadPoolCoreSize(int threadPoolCoreSize)
@Deprecated public String getThreadNamePrefix()
getThreadNameFormat()
@Deprecated public void setThreadNamePrefix(String threadNamePrefix)
setThreadNameFormat(String)
instead.threadNamePrefix
- public String getThreadNameFormat()
public void setThreadNameFormat(String threadNameFormat)
If you change the threadFactory
, then this
value may not be honored.
The string is a format pattern understood by Formatter.format(String, Object...)
.
Formatter.format(String, Object...)
is used to
construct the actual thread name prefix.
The first argument (%1$s) is the string appender name.
The second argument (%2$d) is the numerical thread index.
Other arguments can be made available by subclasses.
public int getRingBufferSize()
public void setRingBufferSize(int ringBufferSize)
public com.lmax.disruptor.dsl.ProducerType getProducerType()
public void setProducerType(com.lmax.disruptor.dsl.ProducerType producerType)
public com.lmax.disruptor.WaitStrategy getWaitStrategy()
public void setWaitStrategy(com.lmax.disruptor.WaitStrategy waitStrategy)
public void setWaitStrategyType(String waitStrategyType)
public ThreadFactory getThreadFactory()
public void setThreadFactory(ThreadFactory threadFactory)
public int getDroppedWarnFrequency()
public void setDroppedWarnFrequency(int droppedWarnFrequency)
protected com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> getEventHandler()
protected void setEventHandler(com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> eventHandler)
public boolean isDaemon()
public void setDaemon(boolean useDaemonThread)
public void addListener(Listener listener)
public void removeListener(Listener listener)
public boolean isAddDefaultStatusListener()
public void setAddDefaultStatusListener(boolean addDefaultStatusListener)
Copyright © 2020. All rights reserved.