Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.logging;
 
 
public class AsyncAppender extends AppenderBase<ILoggingEventimplements Runnable {
    private static final int BATCH_SIZE = 1000;
    public static Appender<ILoggingEventwrap(Appender<ILoggingEventdelegate) {
        final AsyncAppender appender = new AsyncAppender(delegate);
        appender.start();
        return appender;
    }
    private static final ThreadFactory THREAD_FACTORY =
            new ThreadFactoryBuilder().setNameFormat("async-log-appender-%d")
                                      .setDaemon(true)
                                      .build();
    private final Appender<ILoggingEventdelegate;
    private final BlockingQueue<ILoggingEventqueue;
    private final List<ILoggingEventbatch;
    private final Thread dispatcher;
    private volatile boolean running;
    private AsyncAppender(Appender<ILoggingEventdelegate) {
        this. = delegate;
        this. = Queues.newLinkedBlockingQueue();
        this. = Lists.newArrayListWithCapacity();
        this. = .newThread(this);
        setContext(delegate.getContext());
    }
    @Override
    protected void append(ILoggingEvent eventObject) {
        eventObject.prepareForDeferredProcessing();
        .add(eventObject);
    }
    @Override
    public void start() {
        super.start();
        this. = true;
        .start();
    }
    @Override
    public void stop() {
        this. = false;
        super.stop();
    }
    @Override
    public void run() {
        while () {
            try {
                .add(.take());
                .drainTo( - 1);
                for (ILoggingEvent event : ) {
                    .doAppend(event);
                }
                .clear();
            } catch (InterruptedException ignored) {
                Thread.currentThread().interrupt();
            }
        }
    }
New to GrepCode? Check out our FAQ X