use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class MultiConsumerCallback method onDataEvent.
@Override
public ConsumerCallbackResult onDataEvent(DbusEvent e, DbusEventDecoder eventDecoder) {
boolean debugEnabled = _log.isDebugEnabled();
long curNanos = System.nanoTime();
if (null == _sourceMap) {
_log.error("No sources map specified");
if (_consumerStats != null)
_consumerStats.registerSrcErrors();
return ConsumerCallbackResult.ERROR;
}
long srcid = e.srcId();
short lPartitionId = e.logicalPartitionId();
IdNamePair eventSource = _sourceMap.get(srcid);
if (null == eventSource) {
_log.error("Unknown source");
if (_consumerStats != null)
_consumerStats.registerSrcErrors();
return ConsumerCallbackResult.ERROR;
}
for (DatabusV2ConsumerRegistration reg : _registrations) {
DatabusSubscription eventSourceName = DatabusSubscription.createSubscription(eventSource, lPartitionId);
if (debugEnabled)
_log.debug("event source=" + eventSource + " lpart=" + lPartitionId);
if (reg.checkSourceSubscription(eventSourceName)) {
if (debugEnabled)
_log.debug("consumer matches:" + reg.getConsumer());
ConsumerCallable<ConsumerCallbackResult> dataEventCallable = _callbackFactory.createDataEventCallable(curNanos, e, eventDecoder, reg.getConsumer(), true);
_currentBatch.add(dataEventCallable);
if (_consumerStats != null)
_consumerStats.registerDataEventReceived(e);
if (_unifiedClientStats != null)
_unifiedClientStats.registerDataEventReceived(e);
}
}
if (_loggingConsumer != null) {
ConsumerCallable<ConsumerCallbackResult> dataEventCallable = _callbackFactory.createDataEventCallable(curNanos, e, eventDecoder, _loggingConsumer, false);
_currentBatch.add(dataEventCallable);
}
if (debugEnabled) {
long endNanos = System.nanoTime();
_log.debug("Time spent in databus clientlib by onDataEvent = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
}
return submitBatch(curNanos, false, false);
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class MultiConsumerCallback method flushCallQueue.
/** Acts as a barrier for all outstanding calls in the call queue */
public ConsumerCallbackResult flushCallQueue(long curTime) {
ConsumerCallbackResult result = ConsumerCallbackResult.SUCCESS;
if (0 >= curTime)
curTime = System.nanoTime();
TimestampedFuture<ConsumerCallbackResult> top = null;
while (_submittedCalls.size() > 0) {
top = _submittedCalls.peek();
ConsumerCallbackResult topResult = null;
Future<ConsumerCallbackResult> topFuture = top.getFuture();
if (!topFuture.isDone()) {
if (0 >= curTime)
curTime = System.nanoTime();
long calcTimeout = getEstimatedTimeout(_timeBudgetNanos, curTime, top);
long timeoutNanos = _timeBudgetNanos > 0 ? (calcTimeout > 0 ? calcTimeout : 0) : -1;
topResult = getCallResult(topFuture, top.getCallType(), timeoutNanos);
curTime = -1;
}
if (topFuture.isDone() && null == topResult)
topResult = getCallResult(topFuture, top.getCallType(), -1);
if (null == topResult)
topResult = ConsumerCallbackResult.ERROR;
result = ConsumerCallbackResult.max(result, topResult);
if (ConsumerCallbackResult.isFailure(result)) {
_log.error("error detected; cancelling all " + _submittedCalls.size() + " outstanding callbacks");
cancelCalls();
}
if (topFuture.isDone() && result != ConsumerCallbackResult.ERROR) {
boolean debugEnabled = _log.isDebugEnabled();
if (top.getCallType().equals("StartSourceCallable")) {
long runTime = top.getCallable().getNanoRunTime() / DbusConstants.NUM_NSECS_IN_MSEC;
if (debugEnabled) {
StartSourceCallable tf = (StartSourceCallable) top.getCallable();
_log.debug("StartSourceCallable time taken for source " + tf.getSource() + " = " + runTime);
}
} else if (top.getCallType().equals("StartDataEventSequenceCallable")) {
long runTime = top.getCallable().getNanoRunTime() / DbusConstants.NUM_NSECS_IN_MSEC;
if (debugEnabled) {
StartDataEventSequenceCallable tf = (StartDataEventSequenceCallable) top.getCallable();
_log.debug("StartDataEventSequenceCallable time taken for source " + tf.getSCN() + " = " + runTime);
}
}
}
dequeueTopFuture(result);
}
return result;
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class MultiConsumerCallback method submitBatch.
private ConsumerCallbackResult submitBatch(long curNanos, boolean barrierBefore, boolean barrierAfter) {
++_runCallsCounter;
ConsumerCallbackResult retValue = ConsumerCallbackResult.SUCCESS;
if (0 >= curNanos)
curNanos = System.nanoTime();
try {
if (barrierBefore)
retValue = flushCallQueue(curNanos);
if (ConsumerCallbackResult.isSuccess(retValue)) {
String batchName = _currentBatch.size() > 0 ? _currentBatch.get(0).getClass().getSimpleName() : "";
for (ConsumerCallable<ConsumerCallbackResult> call : _currentBatch) {
Future<ConsumerCallbackResult> future = _executorService.submit(call);
_submittedCalls.add(new TimestampedFuture<ConsumerCallbackResult>(call, future, batchName, ++_runCallsCounter));
}
}
_currentBatch.clear();
if (ConsumerCallbackResult.isSuccess(retValue)) {
ConsumerCallbackResult retValue2 = barrierAfter ? flushCallQueue(curNanos) : cleanUpCallQueue(curNanos);
retValue = ConsumerCallbackResult.max(retValue, retValue2);
}
} catch (RuntimeException e) {
_log.error("internal callback error: " + e.getMessage(), e);
retValue = ConsumerCallbackResult.ERROR;
}
return retValue;
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class MultiConsumerCallback method onStartConsumption.
@Override
public ConsumerCallbackResult onStartConsumption() {
long curNanos = System.nanoTime();
for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
ConsumerCallable<ConsumerCallbackResult> startConsumptionCallable = _callbackFactory.createStartConsumptionCallable(curNanos, consumer, true);
_currentBatch.add(startConsumptionCallable);
if (_consumerStats != null)
_consumerStats.registerEventsReceived(1);
}
}
if (_loggingConsumer != null) {
ConsumerCallable<ConsumerCallbackResult> startConsumptionCallable = _callbackFactory.createStartConsumptionCallable(curNanos, _loggingConsumer, false);
_currentBatch.add(startConsumptionCallable);
}
if (_log.isDebugEnabled()) {
long endNanos = System.nanoTime();
_log.debug("Time spent in databus clientlib by onStartConsumption = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
}
return submitBatch(curNanos, false, true);
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class MultiConsumerCallback method onEndSource.
@Override
public ConsumerCallbackResult onEndSource(String source, Schema sourceSchema) {
long curNanos = System.nanoTime();
for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
ConsumerCallable<ConsumerCallbackResult> endSourceCallable = _callbackFactory.createEndSourceCallable(curNanos, source, sourceSchema, consumer, true);
_currentBatch.add(endSourceCallable);
if (_consumerStats != null)
_consumerStats.registerEventsReceived(1);
}
}
if (_loggingConsumer != null) {
ConsumerCallable<ConsumerCallbackResult> endSourceCallable = _callbackFactory.createEndSourceCallable(curNanos, source, sourceSchema, _loggingConsumer, false);
_currentBatch.add(endSourceCallable);
}
if (_log.isDebugEnabled()) {
long endNanos = System.nanoTime();
_log.debug("Time spent in databus clientlib by onEndSource = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
}
return submitBatch(curNanos, true, true);
}
Aggregations