use of com.predic8.membrane.core.exchangestore.ClientStatistics in project service-proxy by membrane.
the class AdminRESTInterceptor method getClients.
@Mapping("/admin/rest/clients(/?\\?.*)?")
public Response getClients(QueryParameter params, String relativeRootPath) throws Exception {
final List<? extends ClientStatistics> clients = getRouter().getExchangeStore().getClientStatistics();
Collections.sort(clients, ComparatorFactory.getClientStatisticsComparator(params.getString("sort", "name"), params.getString("order", "asc")));
int offset = params.getInt("offset", 0);
int max = params.getInt("max", clients.size());
final int total = clients.size();
final List<? extends ClientStatistics> paginated = clients.subList(offset, Math.min(offset + max, clients.size()));
return json(new JSONContent() {
public void write(JsonGenerator gen) throws Exception {
gen.writeStartObject();
gen.writeArrayFieldStart("clients");
for (ClientStatistics s : paginated) {
gen.writeStartObject();
gen.writeStringField("name", s.getClient());
gen.writeNumberField("count", s.getCount());
gen.writeNumberField("min", s.getMinDuration());
gen.writeNumberField("max", s.getMaxDuration());
gen.writeNumberField("avg", s.getAvgDuration());
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeNumberField("total", total);
gen.writeEndObject();
}
});
}
Aggregations