use of org.apache.metron.profiler.clock.Clock in project metron by apache.
the class ProfileSplitterBolt method doExecute.
private void doExecute(Tuple input) throws ParseException, UnsupportedEncodingException {
// retrieve the input message
byte[] data = input.getBinary(0);
JSONObject message = (JSONObject) parser.parse(new String(data, "UTF8"));
// ensure there is a valid profiler configuration
ProfilerConfig config = getProfilerConfig();
if (config != null && config.getProfiles().size() > 0) {
// what time is it?
Clock clock = clockFactory.createClock(config);
Optional<Long> timestamp = clock.currentTimeMillis(message);
// route the message. if a message does not contain the timestamp field, it cannot be routed.
timestamp.ifPresent(ts -> routeMessage(input, message, config, ts));
} else {
LOG.debug("No Profiler configuration found. Nothing to do.");
}
}
use of org.apache.metron.profiler.clock.Clock in project metron by apache.
the class StandAloneProfiler method apply.
/**
* Apply a message to a set of profiles.
* @param message The message to apply.
*/
public void apply(JSONObject message) {
// what time is it?
Clock clock = clockFactory.createClock(config);
Optional<Long> timestamp = clock.currentTimeMillis(message);
// can only route the message, if we have a timestamp
if (timestamp.isPresent()) {
// route the message to the correct profile builders
List<MessageRoute> routes = router.route(message, config, context);
for (MessageRoute route : routes) {
distributor.distribute(message, timestamp.get(), route, context);
}
routeCount += routes.size();
messageCount += 1;
} else {
LOG.warn("No timestamp available for the message. The message will be ignored.");
}
}
Aggregations