在看 injvm 协议的时候,我们还是从 InjvmProtocol 类开始看.
这是它最重要的两个方法,按照我们前面分析的内容,export 方法是启动服务,但是这个是本地服务,所以不需要启动服务.
public Exporter export(Invoker invoker) throws RpcException {
return new InjvmExporter(invoker, invoker.getUrl().getServiceKey(), exporterMap);
}
@Override
public <T> Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url) throws RpcException {
return new InjvmInvoker<T>(serviceType, url, url.getServiceKey(), exporterMap);
}
其实仔细的对比下其他协议的实现,发现讨论都是一个套路.
一般来说,都会在 Invoker 类的 doInvoker 方法中发起一次调用,要么是通过网络,要么是直接调用.
public Result doInvoke(Invocation invocation) throws Throwable {
Exporter<?> exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
if (exporter == null) {
throw new RpcException(“Service [” + key + “] not found.”);
}
RpcContext.getContext().setRemoteAddress(LOCALHOST_VALUE, 0);
return exporter.getInvoker().invoke(invocation);
}
然后就没有啥了,直接调用实现类的方法了.
本文深入探讨了InjvmProtocol类中的关键方法,包括export和protocolBindingRefer,这两个方法分别用于本地服务的导出和引用。同时,文章还详细解释了Invoker类的doInvoke方法在调用过程中的作用。
1万+

被折叠的 条评论
为什么被折叠?



