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