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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations