Search in sources :

Example 1 with RpcMessage

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);
}
Also used : RpcMessageHeader(com.jim.framework.rpc.protocol.RpcMessageHeader) RpcMessage(com.jim.framework.rpc.protocol.RpcMessage) RpcResponse(com.jim.framework.rpc.common.RpcResponse) Date(java.util.Date)

Example 2 with RpcMessage

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;
}
Also used : RpcMessageHeader(com.jim.framework.rpc.protocol.RpcMessageHeader) ResponseFuture(com.jim.framework.rpc.proxy.ResponseFuture) RpcMessage(com.jim.framework.rpc.protocol.RpcMessage)

Example 3 with RpcMessage

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());
}
Also used : RpcMessageHeader(com.jim.framework.rpc.protocol.RpcMessageHeader) RpcRequest(com.jim.framework.rpc.common.RpcRequest) RpcMessage(com.jim.framework.rpc.protocol.RpcMessage)

Example 4 with RpcMessage

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;
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) RpcMessage(com.jim.framework.rpc.protocol.RpcMessage)

Aggregations

RpcMessage (com.jim.framework.rpc.protocol.RpcMessage)4 RpcMessageHeader (com.jim.framework.rpc.protocol.RpcMessageHeader)3 RpcRequest (com.jim.framework.rpc.common.RpcRequest)1 RpcResponse (com.jim.framework.rpc.common.RpcResponse)1 ResponseFuture (com.jim.framework.rpc.proxy.ResponseFuture)1 ByteBuf (io.netty.buffer.ByteBuf)1 Date (java.util.Date)1