use of org.mobicents.tools.heartbeat.api.Packet 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.api.Packet in project load-balancer by RestComm.
the class Client method switchover.
@Override
public void switchover(String fromJvmRoute, String toJvmRoute) {
Packet packet = new SwitchoverRequestPacket(fromJvmRoute, toJvmRoute);
ClientBootstrap clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(executor, executor));
clientBootstrap.setPipelineFactory(new ClientPipelineFactory(clientListener));
ChannelFuture future = clientBootstrap.connect(new InetSocketAddress(lbAddress, lbPort));
future.awaitUninterruptibly();
future.getChannel().write(createRequest(Protocol.SWITCHOVER, packet));
}
use of org.mobicents.tools.heartbeat.api.Packet in project load-balancer by RestComm.
the class HeartbeatService method writeResponse.
private synchronized void writeResponse(MessageEvent e, HttpResponseStatus status, String command, String responceString) {
Packet packet = null;
switch(command) {
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);
}
use of org.mobicents.tools.heartbeat.api.Packet 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);
}
use of org.mobicents.tools.heartbeat.api.Packet in project load-balancer by RestComm.
the class AppServer method writeResponse.
private synchronized void writeResponse(MessageEvent e, HttpResponseStatus status, String command, String responceString) {
Packet packet = null;
switch(command) {
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