Search in sources :

Example 41 with ConsumerCallbackResult

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;
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) IOException(java.io.IOException) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 42 with ConsumerCallbackResult

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;
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult)

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