Search in sources :

Example 26 with ConsumerCallbackResult

use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.

the class GenericDispatcher method doEndStreamSource.

protected boolean doEndStreamSource(DispatcherState curState) {
    boolean success = true;
    boolean debugEnabled = _log.isDebugEnabled();
    if (debugEnabled)
        _log.debug("Entered endSource");
    if (!curState.getStateId().equals(StateId.END_STREAM_SOURCE)) {
        success = false;
        _log.error("END_STREAM_SOURCE state expected but found :" + curState.getStateId());
    } else if (null == curState.getCurrentSource()) {
        success = false;
        _log.error("Missing source information in the current state");
    } else if (curState.getCurrentSource().getId() >= 0) {
        String sourceName = curState.getCurrentSource().getName();
        ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
        try {
            callbackResult = getAsyncCallback().onEndSource(sourceName, curState.getCurrentSourceSchema());
        } catch (RuntimeException e) {
            _log.error("Internal onEndSource error:" + e.getMessage(), e);
        }
        success = ConsumerCallbackResult.isSuccess(callbackResult);
        if (!success) {
            _log.error("Method endSource() failed for the source : " + sourceName);
        } else {
            if (debugEnabled)
                _log.debug("endSource succeeded:" + sourceName);
            curState.resetSourceInfo();
            curState.switchToExpectStreamDataEvents();
        }
    }
    return success;
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Example 27 with ConsumerCallbackResult

use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.

the class GenericDispatcher method processDataEvent.

protected boolean processDataEvent(DispatcherState curState, DbusEvent event) {
    ConsumerCallbackResult callbackResult = getAsyncCallback().onDataEvent(event, curState.getEventDecoder());
    boolean success = ConsumerCallbackResult.isSuccess(callbackResult);
    if (!success) {
        _log.error("Method onDataEvent failed on consumer callback returned an error.");
    } else {
        _log.debug("Event queued: " + event.toString());
    }
    return success;
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Example 28 with ConsumerCallbackResult

use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.

the class GenericDispatcher method doRollback.

protected void doRollback(DispatcherState curState, SCN rollbackScn, boolean checkRetries, boolean regressItr) {
    boolean success = true;
    boolean debugEnabled = _log.isDebugEnabled();
    if (!curState.getStateId().equals(StateId.ROLLBACK)) {
        success = false;
        _log.error("ROLLBACK state is expected by the dispatcher, but the current state is:" + curState.getStateId());
    }
    int retriesLeft = Integer.MAX_VALUE;
    if (checkRetries) {
        retriesLeft = getStatus().getRetriesLeft();
        _log.info("Rolling back the dispatcher to last successful checkpoint. Number of remaining retries for dispatcher to replay events = " + retriesLeft);
        success = success && (retriesLeft > 0);
        if (success) {
            if (0 == getStatus().getRetriesNum())
                getStatus().retryOnError("rollback");
            else
                getStatus().retryOnLastError();
        }
    }
    if (success) {
        Checkpoint lastCp = curState.getLastSuccessfulCheckpoint();
        if ((null != lastCp) || (!regressItr)) {
            ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
            try {
                _log.info("Rolling back to SCN : " + rollbackScn);
                callbackResult = getAsyncCallback().onRollback(rollbackScn);
            } catch (RuntimeException e) {
                _log.error("Internal onRollback error: " + e.getMessage(), e);
            }
            success = ConsumerCallbackResult.isSuccess(callbackResult);
            if (success) {
                if (debugEnabled)
                    _log.debug("Rollback consumer callback succeeded");
            } else {
                _log.error("Rollback consumer callback failed");
            }
        }
        if (regressItr) {
            if (null != curState.getLastSuccessfulIterator()) {
                _log.info("Rolled back to last successful checkpoint position in the buffer: " + curState.getLastSuccessfulIterator());
                _currentWindowSizeInBytes = 0;
                curState.switchToReplayDataEvents();
            } else {
                _log.fatal("Unable to rollback, this usually means that the events belonging to the last checkpoint" + " are no longer to be found in the buffer. Please checkpoint more frequently to avoid this. Restarting the client " + "will fix this problem, last checkpoint found: \n" + lastCp);
                curState.switchToClosed();
            }
        }
    } else {
        DispatcherRetriesExhaustedException exp = new DispatcherRetriesExhaustedException();
        _log.info("Invoke onError callback as dispatcher retries have exhausted");
        getAsyncCallback().onError(exp);
        curState.switchToClosed();
    }
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) DispatcherRetriesExhaustedException(com.linkedin.databus.core.DispatcherRetriesExhaustedException) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) Checkpoint(com.linkedin.databus.core.Checkpoint)

Example 29 with ConsumerCallbackResult

use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.

the class BootstrapProducerCallback method onStartDataEventSequence.

@Override
public ConsumerCallbackResult onStartDataEventSequence(SCN startScn) {
    _srcRm.start();
    _totalNumEvents = 0;
    ConsumerCallbackResult success = ConsumerCallbackResult.SUCCESS;
    try {
        if (_oldWindowScn == -1) {
            initWindowScn();
        }
    } catch (SQLException e) {
        if (null != _statsCollector)
            _statsCollector.registerSQLException();
        LOG.error("Got SQLException in startDataEventSequence Hanlder!! Connections will be reset !!", e);
        try {
            reset();
        } catch (DatabusException e2) {
            DbusPrettyLogUtils.logExceptionAtError("Unable to reset connection", e2, LOG);
        } catch (SQLException sqlEx) {
            DbusPrettyLogUtils.logExceptionAtError("Got exception while resetting connections. Stopping Client !!", sqlEx, LOG);
            return ConsumerCallbackResult.ERROR_FATAL;
        }
        success = ConsumerCallbackResult.ERROR;
    }
    return success;
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) SQLException(java.sql.SQLException) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Example 30 with ConsumerCallbackResult

use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.

the class BatchingDatabusCombinedConsumer method onBootstrapEvent.

@Override
public ConsumerCallbackResult onBootstrapEvent(DbusEvent e, DbusEventDecoder eventDecoder) {
    T eventObj = eventDecoder.getTypedValue(e, (T) null, _payloadClass);
    ConsumerCallbackResult result = addBootstrapEvent(eventObj);
    return result;
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Aggregations

ConsumerCallbackResult (com.linkedin.databus.client.pub.ConsumerCallbackResult)42 DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)9 IdNamePair (com.linkedin.databus.core.util.IdNamePair)3 IOException (java.io.IOException)3 DatabusStreamConsumer (com.linkedin.databus.client.pub.DatabusStreamConsumer)2 ConsumerCallbackStats (com.linkedin.databus.client.pub.mbean.ConsumerCallbackStats)2 UnifiedClientStats (com.linkedin.databus.client.pub.mbean.UnifiedClientStats)2 DbusEvent (com.linkedin.databus.core.DbusEvent)2 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 Checkpoint (com.linkedin.databus.core.Checkpoint)1 DbusErrorEvent (com.linkedin.databus.core.DbusErrorEvent)1 DispatcherRetriesExhaustedException (com.linkedin.databus.core.DispatcherRetriesExhaustedException)1