@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (tracer == null) return invoker.invoke(invocation); String service = invoker.getInterface().getSimpleName(); String method = RpcUtils.getMethodName(invocation); span.name(service + "/" + method); Result result = invoker.invoke(invocation); if (result.hasException()) { onError(result.getException(), span); isOneway = RpcUtils.isOneway(invoker.getUrl(), invocation);
for (int i = 0; invokers != null && i < invokers.size(); i++) { Invoker<T> invoker = invokers.get(i); URL invokerUrl = invoker.getUrl(); RemoteAddr remoteAddr = new RemoteAddr(); remoteAddr.setServerHost(invokerUrl.getHost()); if (invoker.isAvailable()) { return invoker;
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { String application = invoker.getUrl().getParameter(Constants.APPLICATION_KEY); if (application != null) { RpcContext.getContext().setAttachment(DubboUtils.DUBBO_APPLICATION_KEY, application); } return invoker.invoke(invocation); } }
@Override public void referred(Invoker<?> invoker) throws RpcException { Class<?> interfaceClass = invoker.getInterface(); URL url = invoker.getUrl(); String group = url.getParameter(DubboSpringBootStarterConstants.GROUP); String version = url.getParameter(DubboSpringBootStarterConstants.VERSION); ClassIdBean classIdBean = new ClassIdBean(interfaceClass, group, version); SUBSCRIBEDINTERFACES_SET.add(classIdBean); }
@Override @SuppressWarnings("unchecked") public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException { String methodName = invocation.getMethodName(); Class clazz = invoker.getInterface(); Class[] args = invocation.getParameterTypes(); Method method; Myth myth = null; try { method = clazz.getDeclaredMethod(methodName, args); myth = method.getAnnotation(Myth.class); } catch (NoSuchMethodException e) { e.printStackTrace(); } if (Objects.nonNull(myth)) { final MythTransactionContext mythTransactionContext = TransactionContextLocal.getInstance().get(); if (Objects.nonNull(mythTransactionContext)) { RpcContext.getContext() .setAttachment(CommonConstant.MYTH_TRANSACTION_CONTEXT, GsonUtils.getInstance().toJson(mythTransactionContext)); } } return invoker.invoke(invocation); }
@Override public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { for (Invoker<T> invoker : invokers) { if (invoker.isAvailable()) { return invoker.invoke(invocation); } } throw new RpcException("No provider available in " + invokers); } };
public Result wrapResultForProvider(Invoker<?> invoker, Invocation invocation, String propagatedBy, boolean attachRequired) { try { RpcResult result = (RpcResult) invoker.invoke(invocation); if (result.hasException()) { return this.createErrorResultForProvider(result.getException(), propagatedBy, attachRequired); } else { return this.convertResultForProvider(result, propagatedBy, attachRequired); } } catch (Throwable rex) { return this.createErrorResultForProvider(rex, propagatedBy, attachRequired); } }
@Override public void destroy() { this.invoker.destroy(); }
@Override public boolean isAvailable() { if (registryInvoker == null) return false; return registryInvoker.isAvailable(); }
protected String getResourceName(Invoker<?> invoker, Invocation invocation) { StringBuilder buf = new StringBuilder(64); buf.append(invoker.getInterface().getName()) .append(":") .append(invocation.getMethodName()) .append("("); boolean isFirst = true; for (Class<?> clazz : invocation.getParameterTypes()) { if (!isFirst) { buf.append(","); } buf.append(clazz.getName()); isFirst = false; } buf.append(")"); return buf.toString(); } }
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Entry interfaceEntry = null; Entry methodEntry = null; try { String resourceName = getResourceName(invoker, invocation); interfaceEntry = SphU.entry(invoker.getInterface().getName(), EntryType.OUT); methodEntry = SphU.entry(resourceName, EntryType.OUT); Result result = invoker.invoke(invocation); if (result.hasException()) { // Record common exception. Tracer.trace(result.getException()); } return result; } catch (BlockException e) { return DubboFallbackRegistry.getConsumerFallback().handle(invoker, invocation, e); } catch (RpcException e) { Tracer.trace(e); throw e; } finally { if (methodEntry != null) { methodEntry.exit(); } if (interfaceEntry != null) { interfaceEntry.exit(); } } } }
@Override public void destroyed(Invoker<?> invoker) { Class<?> interfaceClass = invoker.getInterface(); URL url = invoker.getUrl(); String group = url.getParameter(DubboSpringBootStarterConstants.GROUP); String version = url.getParameter(DubboSpringBootStarterConstants.VERSION); ClassIdBean classIdBean = new ClassIdBean(interfaceClass, group, version); SUBSCRIBEDINTERFACES_SET.remove(classIdBean); } }
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { for (Invoker<T> invoker : invokers) { if (invoker.isAvailable()) { return invoker.invoke(invocation); } } throw new RpcException("No provider available in " + invokers); } };
public Result wrapResultForProvider(Invoker<?> invoker, Invocation invocation, String propagatedBy, boolean attachRequired) { try { RpcResult result = (RpcResult) invoker.invoke(invocation); if (result.hasException()) { return this.createErrorResultForProvider(result.getException(), propagatedBy, attachRequired); } else { return this.convertResultForProvider(result, propagatedBy, attachRequired); } } catch (Throwable rex) { return this.createErrorResultForProvider(rex, propagatedBy, attachRequired); } }
static <T> Invoker<T> chooseInvoker(List<Invoker<T>> invokers, URL url, Invocation invocation, TxLcnLoadBalance loadBalance) { String localKey = RpcContext.getContext().getLocalAddressString(); List<String> appList = sleuthParamListener.beforeBalance(localKey); Invoker<T> chooseInvoker = null; for (Invoker<T> tInvoker : invokers) { String serverKey = tInvoker.getUrl().getAddress(); for (String appKey : appList) { if (appKey.equals(serverKey)) { chooseInvoker = tInvoker; } } } if (chooseInvoker == null) { Invoker<T> invoker = loadBalance.select(invokers, url, invocation); sleuthParamListener.afterNewBalance(invoker.getUrl().getAddress()); return invoker; } else { return chooseInvoker; } }
@Override public void destroy() { invoker.destroy(); }
public boolean isAvailable() { if (registryInvoker == null) return false; return registryInvoker.isAvailable(); }
private AtomicInteger getConcurrent(Invoker<?> invoker, Invocation invocation) { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); AtomicInteger concurrent = concurrents.get(key); if (concurrent == null) { concurrents.putIfAbsent(key, new AtomicInteger()); concurrent = concurrents.get(key); } return concurrent; }
public Result invoke(Invoker<?> invoker, Invocation invocation) throws JahhanException { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); if (! logged.contains(key)) { logged.add(key); if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) { log.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } return invoker.invoke(invocation); }