Search in sources :

Example 36 with ConsumerCallbackResult

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

the class MultiConsumerCallback method onCheckpoint.

@Override
public ConsumerCallbackResult onCheckpoint(SCN checkpointScn) {
    long curNanos = System.nanoTime();
    for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
        for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
            ConsumerCallable<ConsumerCallbackResult> checkpointCallable = _callbackFactory.createCheckpointCallable(curNanos, checkpointScn, consumer, true);
            _currentBatch.add(checkpointCallable);
            // really "callbacks received"
            if (_consumerStats != null)
                _consumerStats.registerEventsReceived(1);
        }
    }
    if (_loggingConsumer != null) {
        ConsumerCallable<ConsumerCallbackResult> checkpointCallable = _callbackFactory.createCheckpointCallable(curNanos, checkpointScn, _loggingConsumer, false);
        _currentBatch.add(checkpointCallable);
    }
    if (_log.isDebugEnabled()) {
        long endNanos = System.nanoTime();
        _log.debug("Time spent in databus clientlib by onCheckpoint = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
    }
    return submitBatch(curNanos, true, true);
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer)

Example 37 with ConsumerCallbackResult

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

the class MultiConsumerCallback method cleanUpCallQueue.

private ConsumerCallbackResult cleanUpCallQueue(long curNanos) {
    ConsumerCallbackResult result = ConsumerCallbackResult.SUCCESS;
    TimestampedFuture<ConsumerCallbackResult> top = null;
    if (0 > curNanos)
        curNanos = System.nanoTime();
    long timeoutNanos = _timeBudgetNanos > 0 ? curNanos - _timeBudgetNanos : 0;
    //remove completed or expired calls at the head of the queue
    while ((top = _submittedCalls.peek()) != null && (timeoutNanos >= top.getTimestamp() || top.getFuture().isDone())) {
        ConsumerCallbackResult callRes = null;
        if (top.getFuture().isDone()) {
            callRes = getCallResult(top.getFuture(), top.getCallType(), -1);
        } else {
            //timeout
            callRes = ConsumerCallbackResult.ERROR;
            top.getFuture().cancel(true);
            _log.error("callback timeout: " + top.getCallType() + "; runtime = " + ((top.getTimestamp() - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC) + " ms; try increasing client.connectionDefaults.consumerTimeBudgetMs");
        }
        result = ConsumerCallbackResult.max(result, callRes);
        if (ConsumerCallbackResult.isFailure(result)) {
            _log.error("error detected; cancelling all " + _submittedCalls.size() + " outstanding callbacks ");
            cancelCalls();
        }
        //remove the call
        dequeueTopFuture(result);
    }
    return result;
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

Example 38 with ConsumerCallbackResult

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

the class MultiConsumerCallback method getCallResult.

private ConsumerCallbackResult getCallResult(Future<ConsumerCallbackResult> future, String callType, long timeoutNanos) {
    try {
        if (timeoutNanos == 0) {
            _log.error("Exhausted time budget of " + _timeBudgetNanos / DbusConstants.NUM_NSECS_IN_MSEC + "ms. Skipping remaining callbacks of type " + callType);
            throw new TimeoutException("No time remaining in a timeout budget of " + (_timeBudgetNanos / DbusConstants.NUM_NSECS_IN_MSEC) + " ms");
        // Exception caught below
        }
        ConsumerCallbackResult result = timeoutNanos < 0 ? future.get() : future.get(timeoutNanos, TimeUnit.NANOSECONDS);
        if (result == null) {
            result = ConsumerCallbackResult.ERROR;
            _log.error("Client application callback (" + callType + ") returned null");
        } else if (!ConsumerCallbackResult.isSuccess(result)) {
            _log.error("Client application callback (" + callType + ") returned error:" + result);
        }
        return result;
    } catch (ExecutionException ee) {
        // Consumer threw an exception while fielding the callback.
        _log.error("Uncaught exception in client application callback (" + callType + "): " + ee.getCause().getCause(), ee.getCause());
    } catch (InterruptedException ee) {
        _log.warn("Client application callback (" + callType + ") interrupted");
    } catch (TimeoutException te) {
        _log.error("Client application timed out handling callback: " + callType + "; Try increasing client.connectionDefaults.consumerTimeBudgetMs " + " or client.connectionDefaults.bstConsumerTimeBudgetMs");
    }
    return ConsumerCallbackResult.ERROR;
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 39 with ConsumerCallbackResult

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

the class MultiConsumerCallback method onStartDataEventSequence.

@Override
public ConsumerCallbackResult onStartDataEventSequence(SCN startScn) {
    long curNanos = System.nanoTime();
    for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
        for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
            ConsumerCallable<ConsumerCallbackResult> startWindowCallable = _callbackFactory.createStartDataEventSequenceCallable(curNanos, startScn, consumer, true);
            _currentBatch.add(startWindowCallable);
            if (_consumerStats != null)
                _consumerStats.registerEventsReceived(1);
        }
    }
    if (_loggingConsumer != null) {
        ConsumerCallable<ConsumerCallbackResult> startWindowCallable = _callbackFactory.createStartDataEventSequenceCallable(curNanos, startScn, _loggingConsumer, false);
        _currentBatch.add(startWindowCallable);
    }
    if (_log.isDebugEnabled()) {
        long endNanos = System.nanoTime();
        _log.debug("Time spent in databus clientlib by onStartDataEventSequence = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
    }
    return submitBatch(curNanos, true, true);
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer)

Example 40 with ConsumerCallbackResult

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

the class AvroBinaryDtailPrinter method printGenericRecord.

/**
   * @see com.linkedin.databus2.tools.dtail.GenericRecordDtailPrinter#printGenericRecord(org.apache.avro.generic.GenericRecord)
   */
@Override
public ConsumerCallbackResult printGenericRecord(GenericRecord r) {
    ConsumerCallbackResult result = ConsumerCallbackResult.SUCCESS;
    try {
        BinaryEncoder binEnc = _binEncoders.get(r.getSchema());
        if (null == binEnc) {
            binEnc = new BinaryEncoder(_out);
            _binEncoders.put(r.getSchema(), binEnc);
        }
        GenericDatumWriter<GenericRecord> datumWriter = binWriters.get(r.getSchema());
        if (null == datumWriter) {
            datumWriter = new GenericDatumWriter<GenericRecord>(r.getSchema());
            binWriters.put(r.getSchema(), datumWriter);
        }
        datumWriter.write(r, binEnc);
        binEnc.flush();
        _out.write('\n');
    } catch (RuntimeException re) {
        LOG.error("event dump error: " + re.getMessage(), re);
        result = ConsumerCallbackResult.ERROR;
    } catch (IOException ioe) {
        LOG.error("event dump error: " + ioe.getMessage(), ioe);
        result = ConsumerCallbackResult.ERROR;
    }
    return result;
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) IOException(java.io.IOException) GenericRecord(org.apache.avro.generic.GenericRecord)

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