Search in sources :

Example 1 with Packet

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);
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) HeartbeatResponsePacket(org.mobicents.tools.heartbeat.packets.HeartbeatResponsePacket) ShutdownResponsePacket(org.mobicents.tools.heartbeat.packets.ShutdownResponsePacket) StartResponsePacket(org.mobicents.tools.heartbeat.packets.StartResponsePacket) Packet(org.mobicents.tools.heartbeat.api.Packet) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) StartResponsePacket(org.mobicents.tools.heartbeat.packets.StartResponsePacket) HeartbeatResponsePacket(org.mobicents.tools.heartbeat.packets.HeartbeatResponsePacket) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ShutdownResponsePacket(org.mobicents.tools.heartbeat.packets.ShutdownResponsePacket) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 2 with Packet

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));
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) NodeStopRequestPacket(org.mobicents.tools.heartbeat.api.NodeStopRequestPacket) NodeShutdownRequestPacket(org.mobicents.tools.heartbeat.api.NodeShutdownRequestPacket) StartRequestPacket(org.mobicents.tools.heartbeat.api.StartRequestPacket) Packet(org.mobicents.tools.heartbeat.api.Packet) SwitchoverRequestPacket(org.mobicents.tools.heartbeat.packets.SwitchoverRequestPacket) HeartbeatRequestPacket(org.mobicents.tools.heartbeat.api.HeartbeatRequestPacket) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress) SwitchoverRequestPacket(org.mobicents.tools.heartbeat.packets.SwitchoverRequestPacket) ClientPipelineFactory(org.mobicents.tools.heartbeat.client.ClientPipelineFactory)

Example 3 with 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);
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) Packet(org.mobicents.tools.heartbeat.api.Packet) StopResponsePacket(org.mobicents.tools.heartbeat.packets.StopResponsePacket) StopResponsePacket(org.mobicents.tools.heartbeat.packets.StopResponsePacket) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 4 with Packet

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);
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) HeartbeatResponsePacket(org.mobicents.tools.heartbeat.packets.HeartbeatResponsePacket) ShutdownResponsePacket(org.mobicents.tools.heartbeat.packets.ShutdownResponsePacket) StartResponsePacket(org.mobicents.tools.heartbeat.packets.StartResponsePacket) Packet(org.mobicents.tools.heartbeat.api.Packet) StopResponsePacket(org.mobicents.tools.heartbeat.packets.StopResponsePacket) StopResponsePacket(org.mobicents.tools.heartbeat.packets.StopResponsePacket) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) StartResponsePacket(org.mobicents.tools.heartbeat.packets.StartResponsePacket) HeartbeatResponsePacket(org.mobicents.tools.heartbeat.packets.HeartbeatResponsePacket) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ShutdownResponsePacket(org.mobicents.tools.heartbeat.packets.ShutdownResponsePacket) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 5 with Packet

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);
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) Packet(org.mobicents.tools.heartbeat.api.Packet) StopResponsePacket(org.mobicents.tools.heartbeat.packets.StopResponsePacket) StopResponsePacket(org.mobicents.tools.heartbeat.packets.StopResponsePacket) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

ChannelFuture (org.jboss.netty.channel.ChannelFuture)5 Packet (org.mobicents.tools.heartbeat.api.Packet)5 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)4 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)4 StopResponsePacket (org.mobicents.tools.heartbeat.packets.StopResponsePacket)3 HeartbeatResponsePacket (org.mobicents.tools.heartbeat.packets.HeartbeatResponsePacket)2 ShutdownResponsePacket (org.mobicents.tools.heartbeat.packets.ShutdownResponsePacket)2 StartResponsePacket (org.mobicents.tools.heartbeat.packets.StartResponsePacket)2 InetSocketAddress (java.net.InetSocketAddress)1 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)1 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)1 HeartbeatRequestPacket (org.mobicents.tools.heartbeat.api.HeartbeatRequestPacket)1 NodeShutdownRequestPacket (org.mobicents.tools.heartbeat.api.NodeShutdownRequestPacket)1 NodeStopRequestPacket (org.mobicents.tools.heartbeat.api.NodeStopRequestPacket)1 StartRequestPacket (org.mobicents.tools.heartbeat.api.StartRequestPacket)1 ClientPipelineFactory (org.mobicents.tools.heartbeat.client.ClientPipelineFactory)1 SwitchoverRequestPacket (org.mobicents.tools.heartbeat.packets.SwitchoverRequestPacket)1