use of org.mobicents.tools.heartbeat.packets.StartResponsePacket in project load-balancer by RestComm.
the class TestNodeRegister method writeResponse.
private void writeResponse(MessageEvent e, HttpResponseStatus status, String command) {
Packet packet = null;
switch(command) {
case Protocol.HEARTBEAT:
packet = new HeartbeatResponsePacket(Protocol.OK);
break;
case Protocol.START:
packet = new StartResponsePacket(Protocol.OK);
break;
case Protocol.SHUTDOWN:
packet = new ShutdownResponsePacket(Protocol.OK);
break;
}
ChannelBuffer buf = ChannelBuffers.copiedBuffer(gson.toJson(packet), Charset.forName("UTF-8"));
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, APPLICATION_JSON);
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buf.readableBytes());
response.setContent(buf);
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
use of org.mobicents.tools.heartbeat.packets.StartResponsePacket in project load-balancer by RestComm.
the class NodeRegisterImpl method writeResponse.
private synchronized void writeResponse(MessageEvent e, HttpResponseStatus status, String command, String responceString) {
Packet packet = null;
switch(command) {
case Protocol.HEARTBEAT:
packet = new HeartbeatResponsePacket(responceString);
break;
case Protocol.START:
packet = new StartResponsePacket(responceString);
break;
case Protocol.SHUTDOWN:
packet = new ShutdownResponsePacket(responceString);
break;
case Protocol.STOP:
packet = new StopResponsePacket(responceString);
break;
}
ChannelBuffer buf = ChannelBuffers.copiedBuffer(gson.toJson(packet), Charset.forName("UTF-8"));
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, APPLICATION_JSON);
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buf.readableBytes());
response.setContent(buf);
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
Aggregations