Search in sources :

Example 11 with RpcException

use of com.duangframework.core.exceptions.RpcException 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)11 EmptyNullException (com.duangframework.core.exceptions.EmptyNullException)5 NotFoundException (javassist.NotFoundException)4 CtClass (javassist.CtClass)3 RpcAction (com.duangframework.rpc.common.RpcAction)2 Method (java.lang.reflect.Method)2 CtMethod (javassist.CtMethod)2 Service (com.duangframework.core.annotation.mvc.Service)1 Rpc (com.duangframework.core.annotation.rpc.Rpc)1 IProxy (com.duangframework.core.interfaces.IProxy)1 RpcRequest (com.duangframework.rpc.common.RpcRequest)1 RpcResponse (com.duangframework.rpc.common.RpcResponse)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 File (java.io.File)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ClassPool (javassist.ClassPool)1