Search in sources :

Example 1 with RpcRequest

use of com.duangframework.rpc.common.RpcRequest in project duangframework by tcrct.

the class RpcClientProxy method doProxy.

@Override
public Object doProxy(ProxyChain proxyChain) throws Exception {
    Method method = proxyChain.getTargetMethod();
    Class<?> targetClass = proxyChain.getTargetClass();
    // 发现服务
    RpcAction action = RpcFactory.discoverService(targetClass);
    if (ToolsKit.isEmpty(action)) {
        throw new RpcException("Can't Discover " + targetClass.getName() + " RpcAction! Please Check ZooKeep Server");
    }
    // 创建并初始化 RPC 请求
    RpcRequest request = new RpcRequest(System.currentTimeMillis(), RpcUtils.getRequestId());
    request.setIface(targetClass.getName());
    request.setMethodName(method.getName());
    request.setParameterTypes(method.getParameterTypes());
    request.setParameters(proxyChain.getMethodParams());
    request.setService(action.getService().getName());
    logger.warn("[" + RpcUtils.formatDate(request.getStartTime()) + "] request[" + request.getRequestId() + "] [" + action.getRemoteip() + "/" + action.getIntranetip() + ":" + action.getPort() + "] " + request.getIface() + "." + request.getMethodName());
    RpcResponse response = RpcClient.getInstance().call(request, action);
    if (response != null) {
        if (response.isError()) {
            logger.warn("response error:" + response.getError().getMessage());
            throw new RpcException(response.getError());
        } else {
            return response.getResult();
        }
    }
    return null;
}
Also used : RpcAction(com.duangframework.rpc.common.RpcAction) RpcException(com.duangframework.core.exceptions.RpcException) RpcRequest(com.duangframework.rpc.common.RpcRequest) Method(java.lang.reflect.Method) RpcResponse(com.duangframework.rpc.common.RpcResponse)

Aggregations

RpcException (com.duangframework.core.exceptions.RpcException)1 RpcAction (com.duangframework.rpc.common.RpcAction)1 RpcRequest (com.duangframework.rpc.common.RpcRequest)1 RpcResponse (com.duangframework.rpc.common.RpcResponse)1 Method (java.lang.reflect.Method)1