}
outputBufferWatermark.decrementAndGet();
incomingMessages.mark();
final Message msg = event.getMessage();
LOG.debug("Processing message <{}> from OutputBuffer.", msg.getId());
final Set<MessageOutput> messageOutputs = outputRouter.getOutputsForMessage(msg);
final CountDownLatch doneSignal = new CountDownLatch(messageOutputs.size());
for (final MessageOutput output : messageOutputs) {
if (output == null) {
LOG.error("Got null output!");
continue;
}
if (!output.isRunning()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping stopped output {}", output.getClass().getName());
}
continue;
}
try {
LOG.debug("Writing message to [{}].", output.getName());
if (LOG.isTraceEnabled()) {
LOG.trace("Message id for [{}]: <{}>", output.getName(), msg.getId());
}
executor.submit(new Runnable() {
@Override
public void run() {
try (Timer.Context context = processTime.time()) {
output.write(msg);
} catch (Exception e) {
LOG.error("Error in output [" + output.getName() + "].", e);
} finally {
doneSignal.countDown();
}
}
});
} catch (Exception e) {
LOG.error("Could not write message batch to output [" + output.getName() + "].", e);
doneSignal.countDown();
}
}
// Wait until all writer threads have finished or timeout is reached.
if (!doneSignal.await(configuration.getOutputModuleTimeout(), TimeUnit.MILLISECONDS)) {
LOG.warn("Timeout reached. Not waiting any longer for writer threads to complete.");
}
if (serverStatus.hasCapability(ServerStatus.Capability.STATSMODE)) {
throughputStats.getBenchmarkCounter().increment();
}
throughputStats.getThroughputCounter().increment();
LOG.debug("Wrote message <{}> to all outputs. Finished handling.", msg.getId());
}