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;
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class AvroJsonDtailPrinter 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 {
//eventDecoder.dumpEventValueInJSON(e, _out);
JsonEncoder jsonEnc = _jsonEncoders.get(r.getSchema());
if (null == jsonEnc) {
jsonEnc = new JsonEncoder(r.getSchema(), _out);
_jsonEncoders.put(r.getSchema(), jsonEnc);
}
GenericDatumWriter<GenericRecord> datumWriter = _jsonWriters.get(r.getSchema());
if (null == datumWriter) {
datumWriter = new GenericDatumWriter<GenericRecord>(r.getSchema());
_jsonWriters.put(r.getSchema(), datumWriter);
}
datumWriter.write(r, jsonEnc);
jsonEnc.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;
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class DtailPrinter method processEvent.
protected ConsumerCallbackResult processEvent(DbusEventInternalReadable e, DbusEventDecoder eventDecoder) {
if (_done)
return ConsumerCallbackResult.SUCCESS;
ConsumerCallbackResult result = printEvent(e, eventDecoder);
if (ConsumerCallbackResult.isSuccess(result)) {
_endTs = System.currentTimeMillis();
++_eventsNum;
_eventBytes += e.size();
_payloadBytes += e.payloadLength();
long lag = _endTs * 1000000 - e.timestampInNanos();
_eventLagNs += lag;
if (_eventsNum >= _conf.getMaxEventsNum()) {
_done = true;
LOG.info("event limit reached:" + _eventsNum);
}
long elapsed = _endTs - _startTs;
//LOG.info("elapsed: " + elapsed + "; limit=" + _conf.getMaxDurationMs());
if (elapsed > _conf.getMaxDurationMs()) {
_done = true;
LOG.info("time limit reached; elapsed, ms:" + elapsed);
}
if (_done) {
//printStats();
LOG.info("Dtail shutting down ...");
_client.shutdownAsynchronously();
}
}
return result;
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class GenericDispatcher method doStartDispatchEvents.
protected void doStartDispatchEvents() {
boolean debugEnabled = _log.isDebugEnabled();
if (debugEnabled)
_log.debug("Entered startDispatch");
_asyncCallback.setSourceMap(_internalState.getSources());
getStatus().start();
ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
try {
callbackResult = _asyncCallback.onStartConsumption();
} catch (RuntimeException e) {
_log.error("Internal startConsumption error: " + e.getMessage(), e);
}
Boolean callSuccess = ConsumerCallbackResult.isSuccess(callbackResult);
if (!callSuccess) {
// getStatus().suspendOnError(new RuntimeException("Unable to start processing of events"));
_log.error("StartConsumption failed.");
_internalState.switchToStopDispatch();
doStopDispatch(_internalState);
} else {
_stopDispatch.set(false);
_internalState.switchToExpectEventWindow();
doDispatchEvents();
}
}
use of com.linkedin.databus.client.pub.ConsumerCallbackResult in project databus by linkedin.
the class GenericDispatcher method doEndStreamEventWindow.
protected boolean doEndStreamEventWindow(DispatcherState curState) {
boolean success = true;
boolean debugEnabled = _log.isDebugEnabled();
if (debugEnabled)
_log.debug("Entered endDataEventSequence");
if (!curState.getStateId().equals(StateId.END_STREAM_EVENT_WINDOW)) {
success = false;
_log.error("END_STREAM_EVENT_WINDOW state expected but found :" + curState.getStateId());
} else {
ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
try {
callbackResult = getAsyncCallback().onEndDataEventSequence(curState.getEndWinScn());
} catch (RuntimeException e) {
_log.error("Internal onEndDataEventSequence error: " + e.getMessage(), e);
}
success = ConsumerCallbackResult.isSuccess(callbackResult);
if (success) {
if (debugEnabled)
_log.debug("endDataEventSequence callback succeeded:" + curState.getEndWinScn());
} else {
_log.error("endDataEventSequence callback failed, the end window scn is: " + curState.getEndWinScn());
}
}
return success;
}
Aggregations