1.客户端RmiProxyFactoryBean继承关系
# RemotingSupport
# \----RemoteAccessor
# \----UrlBasedRemoteAccessor
# \----RemoteInvocationBasedAccessor
# \----RmiClientInterceptor
# \----RmiProxyFactoryBean
RmiProxyFactoryBean实现了InitializingBean,FactoryBean,MethodInterceptor调用过程如下:
# RmiProxyFactoryBean.afterPropertiesSet
# \----new ProxyFactory(getServiceInterface(), this) 创建代理工厂,没有传入target对象,事实也没有target对象
# \----ProxyFactory.getProxy 返回的代理对象保存到serviceProxy
RmiProxyFactoryBean.getObject 返回serviceProxy
# RmiProxyFactoryBean.invoke 拦截器方法,调用远程服务对象的方法时被此方法拦截并返回
# \----RmiClientInterceptor.invoke 该方法参数是MethodInvocation对象,维护Method对象及若干参数对象
# \----RmiClientInterceptor.getStub
# | \----RmiClientInterceptor.lookupStub 利用jdk原生RMI查找服务
# \----RmiClientInterceptor.doInvoke
# \----RmiClientInterceptor.doInvoke 重载方法,如果服务端是Spring导出的rmi服务,此时stub实现了继承了Remote接口的RmiInvocationHandler接口
# | \----RemoteInvocationBasedAccessor.createRemoteInvocation 将本地MethodInvocation对象封装为RemoteInvocation对象
# | \----RmiInvocationHandler.invoke 该方法为stub(实现了RmiInvocationHandler)的方法,将唯一的参数RemoteInvocation对象,该对象封装了方法名及若干参数对象
# \----RmiClientInterceptorUtils.invokeRemoteMethod 如果服务端是普通的rmi服务,利用反射机制使用stub进行普通的rmi请求
# \----RemoteExporter
# \----RemoteInvocationBasedExporter
# \----RmiBasedExporter
# \----RmiServiceExporter
RmiServiceExporter实现了InitializingBean,调用过程如下:
# RmiServiceExporter.afterPropertiesSet
# \----RmiServiceExporter.prepare
# \----RmiServiceExporter.checkService
# \----RmiBasedExporter.getObjectToExport 如果声明的服务实现了Remote,则直接导出为Rmi服务,否则导出RmiInvocationWrapper,将声明的服务封装到RmiInvocationWrapper
# | \----RemoteExporter.getService 如果实现了Remote接口直接返回
# | \----RemoteExporter.getProxyForService 如果没有实现Remote接口
# | | \----new ProxyFactory
# | | \----ProxyFactory.addInterface 将配置文件中声明的serviceInterface作为代理接口
# | | \----ProxyFactory.getProxy 生成代理对象
# | \----new RmiInvocationWrapper() 返回包装有代理对象的RmiInvocationWrapper返回,该对象继承于Remote的RmiInvocationHandler,可以被rmi导出为服务
# \----UnicastRemoteObject.exportObject
# \----Registry.bind
RmiInvocationWrapper实现了继承了Remote接口的RmiInvocationHandler接口,调用过程如下
# RmiInvocationWrapper.invoke 此时方法参数为客户端通过rmi传来的参数,即为RemoteInvocation对象,封装有方法及若干参数
# \----RmiBasedExporter.invoke 此处RmiInvocationWrapper将自已封装的wrappedObject和RemoteInvocation对象一起传入
# \----RemoteInvocationBasedExporter.invoke
# \----DefaultRemoteInvocationExecutor.invoke
# \----RemoteInvocation.invoke
# \----Method.invoke 调用wrappedObject的相应方法,此处的wrappedObject是经过Spring代理过的服务对象,但最终会调用服务对象的真正方法
# RemotingSupport
# \----RemoteAccessor
# \----UrlBasedRemoteAccessor
# \----RemoteInvocationBasedAccessor
# \----RmiClientInterceptor
# \----RmiProxyFactoryBean
RmiProxyFactoryBean实现了InitializingBean,FactoryBean,MethodInterceptor调用过程如下:
# RmiProxyFactoryBean.afterPropertiesSet
# \----new ProxyFactory(getServiceInterface(), this) 创建代理工厂,没有传入target对象,事实也没有target对象
# \----ProxyFactory.getProxy 返回的代理对象保存到serviceProxy
RmiProxyFactoryBean.getObject 返回serviceProxy
# RmiProxyFactoryBean.invoke 拦截器方法,调用远程服务对象的方法时被此方法拦截并返回
# \----RmiClientInterceptor.invoke 该方法参数是MethodInvocation对象,维护Method对象及若干参数对象
# \----RmiClientInterceptor.getStub
# | \----RmiClientInterceptor.lookupStub 利用jdk原生RMI查找服务
# \----RmiClientInterceptor.doInvoke
# \----RmiClientInterceptor.doInvoke 重载方法,如果服务端是Spring导出的rmi服务,此时stub实现了继承了Remote接口的RmiInvocationHandler接口
# | \----RemoteInvocationBasedAccessor.createRemoteInvocation 将本地MethodInvocation对象封装为RemoteInvocation对象
# | \----RmiInvocationHandler.invoke 该方法为stub(实现了RmiInvocationHandler)的方法,将唯一的参数RemoteInvocation对象,该对象封装了方法名及若干参数对象
# \----RmiClientInterceptorUtils.invokeRemoteMethod 如果服务端是普通的rmi服务,利用反射机制使用stub进行普通的rmi请求
2.服务端RmiServiceExporter继承关系
# RemotingSupport# \----RemoteExporter
# \----RemoteInvocationBasedExporter
# \----RmiBasedExporter
# \----RmiServiceExporter
RmiServiceExporter实现了InitializingBean,调用过程如下:
# RmiServiceExporter.afterPropertiesSet
# \----RmiServiceExporter.prepare
# \----RmiServiceExporter.checkService
# \----RmiBasedExporter.getObjectToExport 如果声明的服务实现了Remote,则直接导出为Rmi服务,否则导出RmiInvocationWrapper,将声明的服务封装到RmiInvocationWrapper
# | \----RemoteExporter.getService 如果实现了Remote接口直接返回
# | \----RemoteExporter.getProxyForService 如果没有实现Remote接口
# | | \----new ProxyFactory
# | | \----ProxyFactory.addInterface 将配置文件中声明的serviceInterface作为代理接口
# | | \----ProxyFactory.getProxy 生成代理对象
# | \----new RmiInvocationWrapper() 返回包装有代理对象的RmiInvocationWrapper返回,该对象继承于Remote的RmiInvocationHandler,可以被rmi导出为服务
# \----UnicastRemoteObject.exportObject
# \----Registry.bind
RmiInvocationWrapper实现了继承了Remote接口的RmiInvocationHandler接口,调用过程如下
# RmiInvocationWrapper.invoke 此时方法参数为客户端通过rmi传来的参数,即为RemoteInvocation对象,封装有方法及若干参数
# \----RmiBasedExporter.invoke 此处RmiInvocationWrapper将自已封装的wrappedObject和RemoteInvocation对象一起传入
# \----RemoteInvocationBasedExporter.invoke
# \----DefaultRemoteInvocationExecutor.invoke
# \----RemoteInvocation.invoke
# \----Method.invoke 调用wrappedObject的相应方法,此处的wrappedObject是经过Spring代理过的服务对象,但最终会调用服务对象的真正方法