class QueueDrainingEventProcessor implements EventProcessor {

    @Override
    public void submit(Object event) {
        events.add(event);
        if (eventCount.getAndIncrement() == 0) {
            do {
                Object e = events.poll();
                try {
                    eventProcessor.submit(e);
                } catch (RuntimeException cause) {
                    if (logErrors) {
                        LOGGER.warn("Event {} threw an exception {}.", event, cause);
                    }
                }
            } while (eventCount.decrementAndGet() > 0);
        }
    }

    public  QueueDrainingEventProcessor(EventProcessor eventProcessor);
    public  QueueDrainingEventProcessor(EventProcessor eventProcessor, boolean logErrors);

}