Java Code Examples for com.alipay.sofa.rpc.core.request.SofaRequest#getInterfaceName()

The following examples show how to use com.alipay.sofa.rpc.core.request.SofaRequest#getInterfaceName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestClientTransport.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
protected Method getMethod(SofaRequest request) throws SofaRpcException {
    String serviceUniqueName = request.getTargetServiceUniqueName();
    String methodName = request.getMethodName();
    String[] methodSigns = request.getMethodArgSigs();

    Method method = ReflectCache.getOverloadMethodCache(serviceUniqueName, methodName, methodSigns);
    if (method == null) {
        try {
            String interfaceName = request.getInterfaceName();
            method = ClassUtils.forName(interfaceName)
                .getMethod(methodName, ClassTypeUtils.getClasses(methodSigns));
            ReflectCache.putOverloadMethodCache(serviceUniqueName, method);
        } catch (NoSuchMethodException e) {
            throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, "Method not found", e);
        }
    }
    return method;
}
 
Example 2
Source File: WeightConsistentHashLoadBalancer.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public ProviderInfo doSelect(SofaRequest request, List<ProviderInfo> providerInfos) {
    String interfaceId = request.getInterfaceName();
    String method = request.getMethodName();
    String key = interfaceId + "#" + method;
    // 判断是否同样的服务列表
    int hashcode = providerInfos.hashCode();
    Selector selector = selectorCache.get(key);
    // 原来没有
    if (selector == null ||
        // 或者服务列表已经变化
        selector.getHashCode() != hashcode) {
        selector = new Selector(interfaceId, method, providerInfos, hashcode);
        selectorCache.put(key, selector);
    }
    return selector.select(request);
}
 
Example 3
Source File: FailFastCluster.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public SofaResponse doInvoke(SofaRequest request) throws SofaRpcException {
    ProviderInfo providerInfo = select(request);
    try {
        SofaResponse response = filterChain(providerInfo, request);
        if (response != null) {
            return response;
        } else {
            throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
                "Failed to call " + request.getInterfaceName() + "." + request.getMethodName()
                    + " on remote server " + providerInfo + ", return null");
        }
    } catch (Exception e) {
        throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
            "Failed to call " + request.getInterfaceName() + "." + request.getMethodName()
                + " on remote server: " + providerInfo + ", cause by: "
                + e.getClass().getName() + ", message is: " + e.getMessage(), e);
    }
}
 
Example 4
Source File: TestGlobalFilter.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
    if (request.getInterfaceName() != null &&
        request.getInterfaceName().equals("com.alipay.sofa.rpc.boot.globalfilter.GlobalFilterService")) {
        if (request.getMethodArgs()[0].equals("globalFilter")) {
            request.getMethodArgs()[0] = "globalFilter_change";
        }
    }
    return invoker.invoke(request);
}
 
Example 5
Source File: ConsistentHashLoadBalancer.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public ProviderInfo doSelect(SofaRequest request, List<ProviderInfo> providerInfos) {
    String interfaceId = request.getInterfaceName();
    String method = request.getMethodName();
    String key = interfaceId + "#" + method;
    int hashcode = providerInfos.hashCode(); // 判断是否同样的服务列表
    Selector selector = selectorCache.get(key);
    if (selector == null // 原来没有
        ||
        selector.getHashCode() != hashcode) { // 或者服务列表已经变化
        selector = new Selector(interfaceId, method, providerInfos, hashcode);
        selectorCache.put(key, selector);
    }
    return selector.select(request);
}
 
Example 6
Source File: AbstractProxyClientTransport.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 同步调用
 *
 * @param request       请求对象
 * @param timeoutMillis 超时时间(毫秒)
 * @return 返回对象
 * @throws InvocationTargetException 反射调用异常
 * @since 5.2.0
 */
protected SofaResponse doInvokeSync(SofaRequest request, int timeoutMillis)
    throws InvocationTargetException, IllegalAccessException {
    SofaResponse response = new SofaResponse();
    Method method = getMethod(request);
    if (method == null) {
        throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
            "Not found method :" + request.getInterfaceName() + "." + request.getMethodName());
    }
    Object o = method.invoke(proxy, request.getMethodArgs());
    response.setAppResponse(o);
    return response;
}
 
Example 7
Source File: TestSyncFilter.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
    interfaceName = request.getInterfaceName();
    targetServiceUniqueName = request.getTargetServiceUniqueName();
    methodName = request.getMethodName();
    invokeType = request.getInvokeType();
    targetAppName = request.getTargetAppName();
    args = request.getMethodArgs();
    return invoker.invoke(request);
}
 
Example 8
Source File: SofaRpcUtils.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static String getInterfaceResourceName(SofaRequest request) {
    return request.getInterfaceName();
}
 
Example 9
Source File: RpcSofaTracer.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Override
public void serverReceived(SofaRequest request) {

    SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();

    Map<String, String> tags = new HashMap<String, String>();
    //server tags 必须设置
    tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);

    String spanStrs = (String) request.getRequestProp(RemotingConstants.NEW_RPC_TRACE_NAME);
    SofaTracerSpanContext spanContext = null;
    if (StringUtils.isBlank(spanStrs)) {
        //老
        Object oldInstanceMap = request.getRequestProp(RemotingConstants.RPC_TRACE_NAME);
        spanContext = this.saveSpanContextAndTags(tags, oldInstanceMap);
    } else {
        //新
        spanContext = SofaTracerSpanContext.deserializeFromString(spanStrs);
    }
    SofaTracerSpan serverSpan;
    //使用客户端的进行初始化,如果上游没有,需要新建
    if (spanContext == null) {
        serverSpan = (SofaTracerSpan) this.sofaTracer.buildSpan(request.getInterfaceName())
            .asChildOf(spanContext)
            .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
            .start();
    } else {
        //有的话,需要new,采样会正确
        serverSpan = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(),
            request.getInterfaceName()
            , spanContext, tags);
    }
    //重新获取
    spanContext = serverSpan.getSofaTracerSpanContext();

    // Record server receive event
    serverSpan.log(LogData.SERVER_RECV_EVENT_VALUE);
    //放到线程上下文
    sofaTraceContext.push(serverSpan);
    //rpc 上下文
    if (RpcInternalContext.isAttachmentEnable()) {
        RpcInternalContext context = RpcInternalContext.getContext();
        context.setAttachment(RpcConstants.INTERNAL_KEY_TRACE_ID, spanContext.getTraceId());
        context.setAttachment(RpcConstants.INTERNAL_KEY_SPAN_ID, spanContext.getSpanId());
    }
}