Search in sources :

Example 11 with RpcContext

use of org.apache.dubbo.rpc.RpcContext in project dubbo by alibaba.

the class FailoverClusterInvoker method calculateInvokeTimes.

private int calculateInvokeTimes(String methodName) {
    int len = getUrl().getMethodParameter(methodName, RETRIES_KEY, DEFAULT_RETRIES) + 1;
    RpcContext rpcContext = RpcContext.getContext();
    Object retry = rpcContext.getObjectAttachment(RETRIES_KEY);
    if (null != retry && retry instanceof Number) {
        len = ((Number) retry).intValue() + 1;
        rpcContext.removeAttachment(RETRIES_KEY);
    }
    if (len <= 0) {
        len = 1;
    }
    return len;
}
Also used : RpcContext(org.apache.dubbo.rpc.RpcContext)

Example 12 with RpcContext

use of org.apache.dubbo.rpc.RpcContext in project dubbo by alibaba.

the class ZoneAwareClusterInterceptor method before.

@Override
public void before(AbstractClusterInvoker<?> clusterInvoker, Invocation invocation) {
    RpcContext rpcContext = RpcContext.getContext();
    String zone = (String) rpcContext.getAttachment(REGISTRY_ZONE);
    String force = (String) rpcContext.getAttachment(REGISTRY_ZONE_FORCE);
    ExtensionLoader<ZoneDetector> loader = ExtensionLoader.getExtensionLoader(ZoneDetector.class);
    if (StringUtils.isEmpty(zone) && loader.hasExtension(DEFAULT_KEY)) {
        ZoneDetector detector = loader.getExtension(DEFAULT_KEY);
        zone = detector.getZoneOfCurrentRequest(invocation);
        force = detector.isZoneForcingEnabled(invocation, zone);
    }
    if (StringUtils.isNotEmpty(zone)) {
        invocation.setAttachment(REGISTRY_ZONE, zone);
    }
    if (StringUtils.isNotEmpty(force)) {
        invocation.setAttachment(REGISTRY_ZONE_FORCE, force);
    }
}
Also used : RpcContext(org.apache.dubbo.rpc.RpcContext) ZoneDetector(org.apache.dubbo.rpc.ZoneDetector)

Example 13 with RpcContext

use of org.apache.dubbo.rpc.RpcContext in project dubbo by alibaba.

the class HttpClientConnectionFactory method open.

@Override
public HessianConnection open(URL url) {
    HttpClientConnection httpClientConnection = new HttpClientConnection(httpClient, url);
    RpcContext context = RpcContext.getContext();
    for (String key : context.getObjectAttachments().keySet()) {
        httpClientConnection.addHeader(DEFAULT_EXCHANGER + key, context.getAttachment(key));
    }
    return httpClientConnection;
}
Also used : RpcContext(org.apache.dubbo.rpc.RpcContext)

Example 14 with RpcContext

use of org.apache.dubbo.rpc.RpcContext in project dubbo by alibaba.

the class JsonRemoteInvocation method invoke.

@Override
public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    RpcContext context = RpcContext.getContext();
    context.setAttachments((Map<String, String>) getAttribute(DUBBO_ATTACHMENTS_ATTR_NAME));
    String generic = (String) getAttribute(GENERIC_KEY);
    if (StringUtils.isNotEmpty(generic)) {
        context.setAttachment(GENERIC_KEY, generic);
    }
    try {
        return super.invoke(targetObject);
    } finally {
        context.setAttachments(null);
    }
}
Also used : RpcContext(org.apache.dubbo.rpc.RpcContext)

Example 15 with RpcContext

use of org.apache.dubbo.rpc.RpcContext in project dubbo by alibaba.

the class DubboHessianURLConnectionFactory method open.

@Override
public HessianConnection open(URL url) throws IOException {
    HessianConnection connection = super.open(url);
    RpcContext context = RpcContext.getContext();
    for (String key : context.getObjectAttachments().keySet()) {
        connection.addHeader(Constants.DEFAULT_EXCHANGER + key, context.getAttachment(key));
    }
    return connection;
}
Also used : RpcContext(org.apache.dubbo.rpc.RpcContext) HessianConnection(com.caucho.hessian.client.HessianConnection)

Aggregations

RpcContext (org.apache.dubbo.rpc.RpcContext)18 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)5 Test (org.junit.jupiter.api.Test)5 Result (org.apache.dubbo.rpc.Result)4 RpcException (org.apache.dubbo.rpc.RpcException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)2 Span (brave.Span)1 Kind (brave.Span.Kind)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 Scope (brave.propagation.CurrentTraceContext.Scope)1 TraceContext (brave.propagation.TraceContext)1 HessianConnection (com.caucho.hessian.client.HessianConnection)1 ForwardingServerCallListener (io.grpc.ForwardingServerCallListener)1 Metadata (io.grpc.Metadata)1 InetSocketAddress (java.net.InetSocketAddress)1 MetricsService (org.apache.dubbo.monitor.MetricsService)1 Protocol (org.apache.dubbo.rpc.Protocol)1 TimeoutCountDown (org.apache.dubbo.rpc.TimeoutCountDown)1