use of com.jim.framework.rpc.protocol.RpcMessage in project jim-framework by jiangmin168168.
the class AbstractHeartbeatHandler method sendPong.
protected void sendPong(ChannelHandlerContext channelHandlerContext) {
RpcMessage message = new RpcMessage();
String body = new Date().toString();
RpcResponse rpcResponse = new RpcResponse();
rpcResponse.setResult(body);
RpcMessageHeader messageHeader = new RpcMessageHeader();
messageHeader.setLength(body.length());
messageHeader.setType(Constants.MESSAGE_TYPE_HEARTBEAT_PONG);
message.setMessageHeader(messageHeader);
message.setMessageBody(rpcResponse);
channelHandlerContext.writeAndFlush(message);
}
use of com.jim.framework.rpc.protocol.RpcMessage in project jim-framework by jiangmin168168.
the class RpcClientInvoker method invoke.
@Override
public ResponseFuture invoke(RpcInvocation invocation) {
RpcRequest request = this.getRpcRequest();
ResponseFuture responseFuture = new ResponseFuture(request);
pendingRPC.put(request.getRequestId(), responseFuture);
RpcMessage message = new RpcMessage();
byte[] data = ProtoStuffSerializeUtil.serialize(request);
RpcMessageHeader messageHeader = new RpcMessageHeader();
messageHeader.setLength(data.length);
message.setMessageHeader(messageHeader);
message.setMessageBody(request);
channel.writeAndFlush(message);
return responseFuture;
}
use of com.jim.framework.rpc.protocol.RpcMessage in project jim-framework by jiangmin168168.
the class AbstractHeartbeatHandler method sendPing.
protected void sendPing(ChannelHandlerContext channelHandlerContext) {
RpcMessage message = new RpcMessage();
RpcRequest rpcRequest = new RpcRequest();
rpcRequest.setRequestId("ping");
RpcMessageHeader messageHeader = new RpcMessageHeader();
messageHeader.setLength(1);
messageHeader.setType(Constants.MESSAGE_TYPE_HEARTBEAT_PING);
message.setMessageHeader(messageHeader);
message.setMessageBody(rpcRequest);
channelHandlerContext.writeAndFlush(message);
logger.info("ping:{}", message.getMessageBody());
}
use of com.jim.framework.rpc.protocol.RpcMessage in project jim-framework by jiangmin168168.
the class RpcDecoder method decode.
@Override
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
ByteBuf frame = (ByteBuf) super.decode(ctx, in);
if (null == frame) {
return null;
}
byte[] data = new byte[frame.readInt()];
frame.readBytes(data);
RpcMessage message = ProtoStuffSerializeUtil.deserialize(data, RpcMessage.class);
return message;
}
Aggregations