use of org.honu.util.Tracer in project Honu by jboulon.
the class MessageSender method run.
public void run() {
TChunk chunk = null;
long timeOut = DEFAULT_POLL_TIMEOUT;
long curr = 0l;
while (running || (chunkQueue.size() != 0)) {
try {
curr = System.currentTimeMillis();
if (shutDownNow()) {
logApp.info("[==HONU==] Honu message sender [" + Thread.currentThread().getId() + "] ShutdownNow");
break;
}
if (curr >= nextStatPeriod) {
kv.startMessage("HonuSenderStats");
kv.addKeyValue("chunkCount", chunkCount);
kv.addKeyValue("lineCount", lineCount);
kv.addKeyValue("exceptionCount", exceptionCount);
kv.addKeyValue("period", statFrequency);
log.info(kv.generateMessage());
// Keep System.out for debug purpose
if (log.isDebugEnabled()) {
System.out.println(Thread.currentThread().getId() + " - " + new java.util.Date() + " - Chunk sent:" + chunkCount + " - lines:" + lineCount + " - in: 1 min+" + (curr - nextStatPeriod) + " ms");
}
lineCount = 0;
chunkCount = 0;
exceptionCount = 0;
nextStatPeriod = System.currentTimeMillis() + statFrequency;
}
chunk = chunkQueue.poll(timeOut, TimeUnit.MILLISECONDS);
// increment sleep time up to maxPollTimeOut
if (chunk == null) {
if (timeOut < MAX_POLL_TIMEOUT) {
timeOut += DEFAULT_POLL_TIMEOUT;
}
continue;
}
timeOut = DEFAULT_POLL_TIMEOUT;
Tracer t = Tracer.startNewTracer("honu.client.sendChunk");
try {
(new Tracer("honu.client.chunkQueueSize [chunks, not msec]", chunkQueue.size())).logTracer();
(new Tracer("honu.client." + chunk.getApplication() + ".chunkQueueSize [chunks, not msec]", chunkQueue.size())).logTracer();
} catch (Exception ignored) {
}
if (System.currentTimeMillis() > leaseTs) {
logApp.info("Time for lease renewal");
closeConnection();
}
sendChunk(chunk);
if (t != null) {
t.stopAndLogTracer();
}
chunkCount++;
lineCount += chunk.getLogEventsSize();
Thread.yield();
} catch (Throwable e) {
logApp.warn("Error in main loop", e);
}
}
if (messageManager != null) {
messageManager.senderShutdownCallback();
}
logApp.info("[==HONU==] Honu message sender [" + Thread.currentThread().getId() + "] shutdown completed, messageQueue:" + chunkQueue.size());
}
Aggregations