Example usage for com.google.common.eventbus EventBusException getCause

List of usage examples for com.google.common.eventbus EventBusException getCause

Introduction

In this page you can find the example usage for com.google.common.eventbus EventBusException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.killbill.bus.DefaultPersistentBus.java

@Override
public int doProcessEvents() {
    final List<BusEventModelDao> events = dao.getReadyEntries();
    if (events.size() == 0) {
        return 0;
    }//w w  w  . j a  va 2  s. c om

    int result = 0;
    final List<BusEventModelDao> historyEvents = new ArrayList<BusEventModelDao>();
    for (final BusEventModelDao cur : events) {
        final BusEvent evt = deserializeEvent(cur.getClassName(), objectMapper, cur.getEventJson());
        result++;

        long errorCount = cur.getErrorCount();
        Throwable lastException = null;

        final Timer.Context dispatchTimerContext = dispatchTimer.time();
        try {
            eventBusDelegate.postWithException(evt);
        } catch (final com.google.common.eventbus.EventBusException e) {

            if (e.getCause() != null && e.getCause() instanceof InvocationTargetException) {
                lastException = e.getCause().getCause();
            } else {
                lastException = e;
            }
            errorCount++;
        } finally {
            dispatchTimerContext.stop();
            if (lastException == null) {
                final BusEventModelDao processedEntry = new BusEventModelDao(cur, Hostname.get(),
                        clock.getUTCNow(), PersistentQueueEntryLifecycleState.PROCESSED);
                historyEvents.add(processedEntry);
            } else if (errorCount <= config.getMaxFailureRetries()) {
                log.info("Bus dispatch error, will attempt a retry ", lastException);
                // STEPH we could batch those as well
                final BusEventModelDao retriedEntry = new BusEventModelDao(cur, Hostname.get(),
                        clock.getUTCNow(), PersistentQueueEntryLifecycleState.AVAILABLE, errorCount);
                dao.updateOnError(retriedEntry);
            } else {
                log.error("Fatal Bus dispatch error, data corruption...", lastException);
                final BusEventModelDao processedEntry = new BusEventModelDao(cur, Hostname.get(),
                        clock.getUTCNow(), PersistentQueueEntryLifecycleState.FAILED);
                historyEvents.add(processedEntry);
            }
        }
    }
    dao.moveEntriesToHistory(historyEvents);

    return result;
}