}
}
public void serialize(@Nonnull Iterable<QueryResult> counters, @Nonnull Iterable<QueryResult> gauges, @Nonnull OutputStream out) throws IOException {
JsonGenerator g = jsonFactory.createGenerator(out, JsonEncoding.UTF8);
g.writeStartObject();
g.writeArrayFieldStart("counters");
for (QueryResult counter : counters) {
g.writeStartObject();
g.writeStringField("name", counter.getName());
if (source != null && !source.isEmpty()) {
g.writeStringField("source", source);
}
g.writeNumberField("measure_time", counter.getEpoch(TimeUnit.SECONDS));
if (counter.getValue() instanceof Integer) {
g.writeNumberField("value", (Integer) counter.getValue());
} else if (counter.getValue() instanceof Long) {
g.writeNumberField("value", (Long) counter.getValue());
} else if (counter.getValue() instanceof Float) {
g.writeNumberField("value", (Float) counter.getValue());
} else if (counter.getValue() instanceof Double) {
g.writeNumberField("value", (Double) counter.getValue());
}
g.writeEndObject();
}
g.writeEndArray();
g.writeArrayFieldStart("gauges");
for (QueryResult gauge : gauges) {
g.writeStartObject();
g.writeStringField("name", gauge.getName());
if (source != null && !source.isEmpty()) {
g.writeStringField("source", source);
}
g.writeNumberField("measure_time", gauge.getEpoch(TimeUnit.SECONDS));
if (gauge.getValue() instanceof Integer) {
g.writeNumberField("value", (Integer) gauge.getValue());
} else if (gauge.getValue() instanceof Long) {
g.writeNumberField("value", (Long) gauge.getValue());
} else if (gauge.getValue() instanceof Float) {
g.writeNumberField("value", (Float) gauge.getValue());
} else if (gauge.getValue() instanceof Double) {
g.writeNumberField("value", (Double) gauge.getValue());
}
g.writeEndObject();
}
g.writeEndArray();
g.writeEndObject();
g.flush();
g.close();
}