Search in sources :

Example 21 with ConsumerCallbackResult

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

Example 22 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 23 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)

Example 24 with ConsumerCallbackResult

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

Example 25 with ConsumerCallbackResult

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