Search in sources :

Example 1 with DbusErrorEvent

use of com.linkedin.databus.core.DbusErrorEvent in project databus by linkedin.

the class RemoteExceptionHandler method suspendConnectionOnError.

private void suspendConnectionOnError(Throwable exception) throws InvalidEventException, InterruptedException {
    // suspend pull threads
    _sourcesConn.getConnectionStatus().suspendOnError(exception);
    // send an error event to dispatcher through dbusEventBuffer
    DbusEventInternalReadable errorEvent = null;
    if (exception instanceof BootstrapDatabaseTooOldException) {
        errorEvent = _eventFactory.createErrorEvent(new DbusErrorEvent(exception, DbusEventInternalWritable.BOOTSTRAPTOOOLD_ERROR_SRCID));
    } else if (exception instanceof PullerRetriesExhaustedException) {
        errorEvent = _eventFactory.createErrorEvent(new DbusErrorEvent(exception, DbusEventInternalWritable.PULLER_RETRIES_EXPIRED));
    } else {
        throw new InvalidEventException("Got an unrecognizable exception ");
    }
    byte[] errorEventBytes = new byte[errorEvent.getRawBytes().limit()];
    if (LOG.isDebugEnabled()) {
        LOG.debug("error event size: " + errorEventBytes.length);
        LOG.debug("error event:" + errorEvent.toString());
    }
    errorEvent.getRawBytes().get(errorEventBytes);
    ByteArrayInputStream errIs = new ByteArrayInputStream(errorEventBytes);
    ReadableByteChannel errRbc = Channels.newChannel(errIs);
    boolean success = false;
    int retryCounter = 0;
    while (!success && retryCounter < 10) {
        String errMsg = "Sending an internal system event to dispatcher. Retry count = " + retryCounter;
        DbusPrettyLogUtils.logExceptionAtInfo(errMsg, exception, LOG);
        success = _dbusEventBuffer.readEvents(errRbc) > 0 ? true : false;
        if (!success) {
            LOG.warn("Unable to send an internal system event to dispatcher. Will retry later " + retryCounter);
            retryCounter++;
            Thread.sleep(1000);
        }
    }
}
Also used : BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ReadableByteChannel(java.nio.channels.ReadableByteChannel) ChunkedBodyReadableByteChannel(com.linkedin.databus.client.ChunkedBodyReadableByteChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) DbusEventInternalReadable(com.linkedin.databus.core.DbusEventInternalReadable) DbusErrorEvent(com.linkedin.databus.core.DbusErrorEvent) InvalidEventException(com.linkedin.databus.core.InvalidEventException) PullerRetriesExhaustedException(com.linkedin.databus.core.PullerRetriesExhaustedException)

Example 2 with DbusErrorEvent

use of com.linkedin.databus.core.DbusErrorEvent in project databus by linkedin.

the class GenericDispatcher method processErrorEvent.

private boolean processErrorEvent(DispatcherState curState, DbusEventInternalReadable nextEvent) {
    boolean success = false;
    DbusErrorEvent errorEvent = null;
    if (nextEvent.isErrorEvent()) {
        errorEvent = DbusEventSerializable.getErrorEventFromDbusEvent(nextEvent);
        if (null == errorEvent) {
            _log.error("Null error event received at dispatcher");
        } else {
            _log.info("Delivering error event to consumers: " + errorEvent);
            ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
            try {
                callbackResult = _asyncCallback.onError(errorEvent.returnActualException());
            } catch (RuntimeException e) {
                _log.error("Internal onError error: " + e.getMessage(), e);
            }
            success = ConsumerCallbackResult.isSuccess(callbackResult);
        }
    } else {
        _log.error("Unexcpected event received while DbusErrorEvent is expected! " + nextEvent);
    }
    return success;
}
Also used : DbusErrorEvent(com.linkedin.databus.core.DbusErrorEvent) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Aggregations

DbusErrorEvent (com.linkedin.databus.core.DbusErrorEvent)2 ChunkedBodyReadableByteChannel (com.linkedin.databus.client.ChunkedBodyReadableByteChannel)1 ConsumerCallbackResult (com.linkedin.databus.client.pub.ConsumerCallbackResult)1 DbusEventInternalReadable (com.linkedin.databus.core.DbusEventInternalReadable)1 InvalidEventException (com.linkedin.databus.core.InvalidEventException)1 PullerRetriesExhaustedException (com.linkedin.databus.core.PullerRetriesExhaustedException)1 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1