public void sendRealtimeAgentHealth(Account account, List<JvmAgentStatus> statusList) { VelocityContext ctx = new VelocityContext(); ctx.put("username", account.username()); List<Cluster> clusters = new ArrayList<>(); statusList.forEach(jas -> { Cluster c = new Cluster(); c.name = jas.getAnalysis().name(); List<Jvm> jvms = new ArrayList<>(); jas.getJvms().forEach(p -> { Jvm jvm = new Jvm(); jvm.name = p.getKey(); Duration dur = Duration.of(p.getValue(), ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD); jvm.period = PrettyTime.of(Locale.ENGLISH).print(dur, TextWidth.ABBREVIATED); jvms.add(jvm); }); c.jvms = jvms; clusters.add(c); }); ctx.put("clusters", clusters); String template = config.readString(ConfigProperty.EMAIL_AGENT_HEALTH_TEMPLATE); StringWriter msg = new StringWriter((int) (template.length() * 1.5)); if (Velocity.evaluate(ctx, msg, account.username(), template)) { sendNotification(account, "Real-time Agent Health Status", msg.toString()); } else { LOG.info("Unable to generate velocity template for message."); } }