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;
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations