/** * Apply a message to a set of profiles. * @param message The message to apply. */ public void apply(JSONObject message) { // route the message to the correct profile builders List<MessageRoute> routes = router.route(message, config, context); for (MessageRoute route : routes) { distributor.distribute(route, context); } routeCount += routes.size(); messageCount += 1; }
/** * Flush the set of profiles. * @return A ProfileMeasurement for each (Profile, Entity) pair. */ public List<ProfileMeasurement> flush() { return distributor.flush(); }
distributor.distribute(route, context); List<ProfileMeasurement> measurements = distributor.flush(); if(measurements.size() > 1) { throw new IllegalStateException("No more than 1 profile measurement is expected");
/** * Flushes all expired profiles. * * <p>If a profile has not received a message for an extended period of time then it is * marked as expired. Periodically we need to flush these expired profiles to ensure * that their state is not lost. */ protected void flushExpired() { List<ProfileMeasurement> measurements = null; try { // flush the expired profiles synchronized (messageDistributor) { measurements = messageDistributor.flushExpired(); emitMeasurements(measurements); } } catch(Throwable t) { // need to catch the exception, otherwise subsequent executions would be suppressed. // see java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate LOG.error("Failed to flush expired profiles", t); } LOG.debug("Flushed expired profiles and found {} measurement(s).", CollectionUtils.size(measurements)); }
/** * Flush all active profiles. */ protected void flushActive() { activeFlushSignal.reset(); // flush the active profiles List<ProfileMeasurement> measurements; synchronized(messageDistributor) { measurements = messageDistributor.flush(); emitMeasurements(measurements); } LOG.debug("Flushed active profiles and found {} measurement(s).", measurements.size()); }
/** * Handles the processing of a single tuple. * * @param input The tuple containing a telemetry message. */ private void handleMessage(Tuple input) { // crack open the tuple JSONObject message = getField(MESSAGE_TUPLE_FIELD, input, JSONObject.class); ProfileConfig definition = getField(PROFILE_TUPLE_FIELD, input, ProfileConfig.class); String entity = getField(ENTITY_TUPLE_FIELD, input, String.class); Long timestamp = getField(TIMESTAMP_TUPLE_FIELD, input, Long.class); // keep track of time activeFlushSignal.update(timestamp); // distribute the message MessageRoute route = new MessageRoute(definition, entity, message, timestamp); synchronized (messageDistributor) { messageDistributor.distribute(route, getStellarContext()); } LOG.debug("Message distributed: profile={}, entity={}, timestamp={}", definition.getProfile(), entity, timestamp); }