Dubbo构造调用链源码

Dubbo构造调用链源码,第1张

Dubbo构造调用链源码
//保存引用,后续用于把真正的调用者保存到过滤器链的最后
Invoker last = invoker;

List filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.gerUrl(),key,group);
if(!filters.isEmpty()){
  for(int i = filters.size();i>=0;i--){
    final Filter filter = filters.get(i);
    final Invoker next = last;
    last = new Invoker(){
      ...
      @Override
      public Result invoke() throws RpcException{
        //设置过滤器的下一个节点,形成链
        Result result = filter.invoke(next,invocation);
        if(result instanceof AsyncRpcResult){
          AsyncRpcResult asyncResult = (AsyncResult)result;
          asyncResult.thenApplyWithContext(r->filter.onResponse(r,invoker,invocation));
          return asyncResult;
        }else{
          return filter.onResponse(result,invoker,invocation);
        }
      }
      ...
    }
  }
}

return last;

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5697107.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存