Search in sources :

Example 1 with ClientStatistics

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();
        }
    });
}
Also used : JSONContent(com.predic8.membrane.core.interceptor.rest.JSONContent) ClientStatistics(com.predic8.membrane.core.exchangestore.ClientStatistics) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) SQLException(java.sql.SQLException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException)

Aggregations

JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ClientStatistics (com.predic8.membrane.core.exchangestore.ClientStatistics)1 JSONContent (com.predic8.membrane.core.interceptor.rest.JSONContent)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1