com.github.houbb.rpc.client.handler.RpcClientHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rpc-client Show documentation
Show all versions of rpc-client Show documentation
The client module of rpc framework.
The newest version!
/*
* Copyright (c) 2019. houbinbin Inc.
* rpc All rights reserved.
*/
package com.github.houbb.rpc.client.handler;
import com.github.houbb.log.integration.core.Log;
import com.github.houbb.log.integration.core.LogFactory;
import com.github.houbb.rpc.common.rpc.domain.RpcResponse;
import com.github.houbb.rpc.common.support.invoke.InvokeManager;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
/**
* 客户端处理类
*
* Created: 2019/10/16 11:30 下午
* Project: rpc
*
* @author houbinbin
* @since 0.0.2
*/
@ChannelHandler.Sharable
public class RpcClientHandler extends SimpleChannelInboundHandler {
private static final Log log = LogFactory.getLog(RpcClientHandler.class);
/**
* 调用服务管理类
*
* @since 0.0.6
*/
private final InvokeManager invokeManager;
public RpcClientHandler(InvokeManager invokeManager) {
this.invokeManager = invokeManager;
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
RpcResponse rpcResponse = (RpcResponse)msg;
invokeManager.addResponse(rpcResponse.seqId(), rpcResponse);
log.info("[Client] server response is :{}", rpcResponse);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.error("[Rpc Client] meet ex ", cause);
ctx.close();
}
}