@Override public BatchResponse onNextBatch(BatchSource source, Collection<JetstreamEvent> events) throws EventException { // check if it's time to send the batch, check the delay time of the // lastEvent, if it's no time to send the batch, tell the IKC to wait // and resend this batch long start = System.currentTimeMillis(); if (getReplayConfig().getTimestampKey() != null && getReplayConfig().getDelayInMs() > 0) { JetstreamEvent[] eventArr = events .toArray(new JetstreamEvent[events.size()]); JetstreamEvent lastEvent = eventArr[eventArr.length - 1]; Long ts = (Long) lastEvent.get(getReplayConfig().getTimestampKey()); if (ts != null) { long v = ts + getReplayConfig().getDelayInMs() - start; if (v > 0) { incrementEventRecievedCounter(events.size()); incrementEventDelayedCounter(events.size()); return BatchResponse.getNextBatch() .setOffset(source.getHeadOffset()) .setWaitTimeInMs(v); } } } return super.onNextBatch(source, events); }
private String getKey(BatchSource source) { return new StringBuilder().append(source.getTopic()).append("-") .append(source.getPartition()).toString(); }
private EventMetaInfo genEventMeta(BatchSourceCommand action, PartitionReader p) { BatchSource source = new BatchSource(p.getTopic(), p.getPartition()); return new EventMetaInfo(action, source); }
private EventMetaInfo genEventMeta(BatchSourceCommand action, PartitionReader p, Exception ex) { BatchSource source = new BatchSource(p.getTopic(), p.getPartition()); return new EventMetaInfo(action, source, ex); }
@Override public BatchResponse onException(BatchSource source, Exception ex) { return BatchResponse.getNextBatch().setOffset(source.getHeadOffset()); }
protected BatchResponse autoAdvanceResponse(BatchSource source) { if (isAutoAdvanceEveryBatch()) { return BatchResponse.advanceAndGetNextBatch(); } else { String key = new StringBuilder().append(source.getTopic()) .append("-").append(source.getPartition()).toString(); Long lastTs = m_lastAdvanceTimes.get(key); long curTime = System.currentTimeMillis(); boolean advance = false; if (lastTs != null && (curTime - lastTs.longValue()) >= m_config .getAutoAdvanceInterval()) { advance = true; m_lastAdvanceTimes.put(key, curTime); } if (advance) { return BatchResponse.advanceAndGetNextBatch(); } else { return BatchResponse.getNextBatch(); } } }
private EventMetaInfo genEventMeta(BatchSourceCommand action, PartitionReader p, int batchSize) { BatchSource source = new BatchSource(p.getTopic(), p.getPartition(), p.getReadOffset() - batchSize); return new EventMetaInfo(action, source); }
incrementEventDroppedCounter(events.size()); return BatchResponse.getNextBatch().setOffset( source.getHeadOffset()); long startOffset = source.getHeadOffset(); int index = 0; try {