/** * executed on consumer side * * 构造将在消费端执行 */ publicRmiRemoteInvocation(MethodInvocation methodInvocation){ super(methodInvocation); addAttribute(dubboAttachmentsAttrName, new HashMap<String, String>(RpcContext.getContext().getAttachments())); }
/** * Need to restore context on provider side (Though context will be overridden by Invocation's attachment * when ContextFilter gets executed, we will restore the attachment when Invocation is constructed, check more * from {@link com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler} * * 服务端执行时,重新放入上下文(虽然这时上下文在ContextFilter执行时将被Invocation的attachments覆盖,我们在Invocation构造时还原attachments, see InvokerInvocationHandler) */ @SuppressWarnings("unchecked") @Override public Object invoke(Object targetObject)throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { RpcContext context = RpcContext.getContext(); context.setAttachments((Map<String, String>) getAttribute(dubboAttachmentsAttrName)); try { returnsuper.invoke(targetObject); } finally { context.setAttachments(null); } } }