use of org.mobicents.tools.sip.balancer.StatisticObject in project load-balancer by RestComm.
the class HttpRequestHandler method writeStatisticResponse.
private void writeStatisticResponse(MessageEvent e) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.setPrettyPrinting().create();
JsonElement je = gson.toJsonTree(new StatisticObject(balancerRunner));
JsonObject jo = new JsonObject();
jo.add("Metrics", je);
String output = jo.toString();
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, APPLICATION_JSON);
ChannelBuffer buf = ChannelBuffers.copiedBuffer(output, Charset.forName("UTF-8"));
response.setContent(buf);
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
Aggregations