CamusWrapper wrapper;
try {
wrapper = getWrappedRecord(key.getTopic(), bytes);
} catch (Exception e) {
if (exceptionCount < getMaximumDecoderExceptionsToPrint(context)) {
mapperContext.write(key, new ExceptionWritable(e));
exceptionCount++;
} else if (exceptionCount == getMaximumDecoderExceptionsToPrint(context)) {
exceptionCount = Integer.MAX_VALUE; //Any random value
log.info("The same exception has occured for more than " + getMaximumDecoderExceptionsToPrint(context) + " records. All further exceptions will not be printed");
}
continue;
}
if (wrapper == null) {
mapperContext.write(key, new ExceptionWritable(new RuntimeException(
"null record")));
continue;
}
long timeStamp = wrapper.getTimestamp();
try {
key.setTime(timeStamp);
key.addAllPartitionMap(wrapper.getPartitionMap());
setServerService();
} catch (Exception e) {
mapperContext.write(key, new ExceptionWritable(e));
continue;
}
if (timeStamp < beginTimeStamp) {
mapperContext.getCounter("total", "skip-old").increment(1);
} else if (endTimeStamp == 0) {
DateTime time = new DateTime(timeStamp);
statusMsg += " begin read at " + time.toString();
context.setStatus(statusMsg);
log.info(key.getTopic() + " begin read at " + time.toString());
endTimeStamp = (time.plusHours(this.maxPullHours)).getMillis();
} else if (timeStamp > endTimeStamp || System.currentTimeMillis() > maxPullTime) {
if (timeStamp > endTimeStamp)
log.info("Kafka Max history hours reached");
if (System.currentTimeMillis() > maxPullTime)
log.info("Kafka pull time limit reached");
statusMsg += " max read at " + new DateTime(timeStamp).toString();
context.setStatus(statusMsg);
log.info(key.getTopic() + " max read at "
+ new DateTime(timeStamp).toString());
mapperContext.getCounter("total", "request-time(ms)").increment(
reader.getFetchTime());
mapperContext.write(key, new ExceptionWritable("Topic not fully pulled, max partition hours reached"));
closeReader();
} else if (System.currentTimeMillis() > maxPullTime) {
log.info("Max pull time reached");
mapperContext.write(key, new ExceptionWritable("Topic not fully pulled, max task time reached"));
closeReader();
}
long secondTime = System.currentTimeMillis();
value = wrapper;
long decodeTime = ((secondTime - tempTime));
mapperContext.getCounter("total", "decode-time(ms)").increment(decodeTime);
if (reader != null) {
mapperContext.getCounter("total", "request-time(ms)").increment(
reader.getFetchTime());
}
return true;
}
log.info("Records read : " + count);
count = 0;
reader = null;
} catch (Throwable t) {
Exception e = new Exception(t.getLocalizedMessage(), t);
e.setStackTrace(t.getStackTrace());
mapperContext.write(key, new ExceptionWritable(e));
reader = null;
continue;
}
}
}