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
.
The behavior of the appender when the RingBuffer is full and the event cannot be published
is controlled by the appendTimeout
configuration parameter.
By default the appender drops the event immediately, and emits a warning message every
droppedWarnFrequency
consecutive dropped events.
It can also be configured to wait until some space is available, with or without timeout.
A single handler thread will be used to handle the actual handling of the event.
Subclasses must implement createEventHandler()
to provide a EventHandler
to
define the logic that executes in the handler thread.
For example, DelegatingAsyncDisruptorAppender
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.LogEventFactory<Event>
Factory for creating the initial
AsyncDisruptorAppender.LogEvent s to populate
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 abstract com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> |
createEventHandler()
Create the
EventHandler to process events as they become available from the RingBuffer. |
protected void |
fireAppenderStarted() |
protected void |
fireAppenderStopped() |
protected void |
fireEventAppended(Event event,
long durationInNanos) |
protected void |
fireEventAppendFailed(Event event,
Throwable reason) |
Duration |
getAppendRetryFrequency() |
Duration |
getAppendTimeout() |
protected com.lmax.disruptor.dsl.Disruptor<AsyncDisruptorAppender.LogEvent<Event>> |
getDisruptor() |
int |
getDroppedWarnFrequency() |
protected com.lmax.disruptor.EventTranslatorOneArg<AsyncDisruptorAppender.LogEvent<Event>,Event> |
getEventTranslator() |
com.lmax.disruptor.dsl.ProducerType |
getProducerType()
Get the
ProducerType configured for the Disruptor. |
int |
getRingBufferSize()
Returns the maximum number of events allowed in the queue.
|
Duration |
getShutdownGracePeriod() |
ThreadFactory |
getThreadFactory() |
String |
getThreadNameFormat() |
protected List<Object> |
getThreadNameFormatParams() |
com.lmax.disruptor.WaitStrategy |
getWaitStrategy() |
boolean |
isAddDefaultStatusListener() |
boolean |
isDaemon() |
protected boolean |
isRingBufferEmpty()
Test whether the ring buffer is empty or not
|
protected void |
prepareForDeferredProcessing(Event event) |
void |
removeListener(Listener listener) |
protected void |
safelyFireEvent(Consumer<Listener> callback) |
void |
setAddDefaultStatusListener(boolean addDefaultStatusListener) |
void |
setAppendRetryFrequency(Duration appendRetryFrequency) |
void |
setAppendTimeout(Duration appendTimeout) |
void |
setDaemon(boolean useDaemonThread) |
void |
setDroppedWarnFrequency(int droppedWarnFrequency) |
protected void |
setEventFactory(AsyncDisruptorAppender.LogEventFactory<Event> eventFactory) |
protected void |
setEventTranslator(com.lmax.disruptor.EventTranslatorOneArg<AsyncDisruptorAppender.LogEvent<Event>,Event> eventTranslator) |
void |
setProducerType(com.lmax.disruptor.dsl.ProducerType producerType)
Deprecated.
ProducerType will be fixed to MULTI in future release and this method removed without any replacement.
|
void |
setRingBufferSize(int ringBufferSize)
Sets the size of the
RingBuffer . |
void |
setShutdownGracePeriod(Duration shutdownGracePeriod) |
void |
setThreadFactory(ThreadFactory threadFactory) |
void |
setThreadNameFormat(String threadNameFormat)
Pattern used by the to set the handler thread names.
|
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 abstract com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> createEventHandler()
EventHandler
to process events as they become available from the RingBuffer.
This method is invoked when the appender is started by start()
and a new Disruptor
is initialized.EventHandler
instance.protected boolean isRingBufferEmpty()
true
if the ring buffer is empty, false
otherwiseprotected 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(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 com.lmax.disruptor.dsl.Disruptor<AsyncDisruptorAppender.LogEvent<Event>> getDisruptor()
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.
threadNameFormat
- the thread name format patternpublic int getRingBufferSize()
public void setRingBufferSize(int ringBufferSize)
RingBuffer
.
Must be a positive power of 2.
Defaults to 8192.
If the handler thread is not as fast as the producing threads, then the RingBuffer
will eventually fill up, at which point events will be dropped or producing threads blocked
depending on appendTimeout
.
ringBufferSize
- the maximum number of entries in the queue.public com.lmax.disruptor.dsl.ProducerType getProducerType()
ProducerType
configured for the Disruptor.ProducerType
.@Deprecated public void setProducerType(com.lmax.disruptor.dsl.ProducerType producerType)
ProducerType
to use to configure the Disruptor.
By default this is ProducerType.MULTI
.
Can be set to ProducerType.SINGLE
for increase performance if (and only if) only
one thread will ever be appending to this appender.
WARNING: unexpected behavior may occur if this parameter is set to ProducerType.SINGLE
and multiple threads are appending to this appender.
producerType
- the type of producerpublic com.lmax.disruptor.WaitStrategy getWaitStrategy()
public void setWaitStrategy(com.lmax.disruptor.WaitStrategy waitStrategy)
public void setWaitStrategyType(String waitStrategyType)
public Duration getAppendRetryFrequency()
public void setAppendRetryFrequency(Duration appendRetryFrequency)
public Duration getAppendTimeout()
public void setAppendTimeout(Duration appendTimeout)
public void setShutdownGracePeriod(Duration shutdownGracePeriod)
public Duration getShutdownGracePeriod()
public ThreadFactory getThreadFactory()
public void setThreadFactory(ThreadFactory threadFactory)
public int getDroppedWarnFrequency()
public void setDroppedWarnFrequency(int droppedWarnFrequency)
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 © 2013–2022. All rights reserved.