Spring RMI源码分析

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请求


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代理过的服务对象,但最终会调用服务对象的真正方法
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值