/** * Distribute a message along a MessageRoute. * * @param route The message route. * @param context The Stellar execution context. */ @Override public void distribute(MessageRoute route, Context context) { try { ProfileBuilder builder = getBuilder(route, context); builder.apply(route.getMessage(), route.getTimestamp()); } catch(ExecutionException e) { LOG.error("Unexpected error", e); throw new RuntimeException(e); } }
/** * Creates the {@link Values} attached to the outgoing tuple. * * @param route The route the message must take. * @return */ private Values createValues(MessageRoute route) { // the order here must match `declareOutputFields` return new Values(route.getMessage(), route.getTimestamp(), route.getEntity(), route.getProfileDefinition()); }
/** * Route a message based on the Profiler configuration. * @param input The input tuple on which to anchor. * @param message The telemetry message. * @param config The Profiler configuration. */ private void routeMessage(Tuple input, JSONObject message, ProfilerConfig config) { // emit a tuple for each 'route' List<MessageRoute> routes = router.route(message, config, getStellarContext()); for (MessageRoute route : routes) { Values values = createValues(route); collector.emit(input, values); LOG.debug("Found route for message; profile={}, entity={}, timestamp={}", route.getProfileDefinition().getProfile(), route.getEntity(), route.getTimestamp()); } LOG.debug("Found {} route(s) for message", routes.size()); }
.sorted(comparing(rt -> rt.getTimestamp())) .collect(Collectors.toList()); LOG.debug("Building a profile for group '{}' from {} message(s)", group, routes.size());
@Override public String call(MessageRoute route) { ProfilePeriod period = ProfilePeriod.fromTimestamp(route.getTimestamp(), periodDuration, periodDurationUnits); return route.getProfileDefinition().getProfile() + "-" + route.getEntity() + "-" + period.getPeriod(); } }