Spring框架学习[Spring HTTP调用器实现远程调用](十)

2014-11-24 03:00:37 · 作者: · 浏览: 4
ct targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  • if (logger.isTraceEnabled()) { logger.trace("Executing " + invocation);
  • } try {
  • //获取远程调用执行器,由远程调用执行器调用目标对象的方法,即通过 //DefaultRemoteInvocationExecutor了调用目标对象的方法
  • return getRemoteInvocationExecutor().invoke(invocation, targetObject); }
  • catch (NoSuchMethodException ex) { if (logger.isDebugEnabled()) {
  • logger.warn("Could not find target method for " + invocation, ex); }
  • throw ex; }
  • catch (IllegalAccessException ex) { if (logger.isDebugEnabled()) {
  • logger.warn("Could not access target method for " + invocation, ex); }
  • throw ex; }
  • catch (InvocationTargetException ex) { if (logger.isDebugEnabled()) {
  • logger.debug("Target method failed for " + invocation, ex.getTargetException()); }
  • throw ex; }
  • } }

    通过上面对RemoteInvocationBasedExporter源码分析我们看到,真正调用目标对象的是DefaultRemoteInvocationExecutor的invoke方法,下面我们继续分析DefaultRemoteInvocationExecutor调用目标对象方法的实现。

    10.DefaultRemoteInvocationExecutor调用目标对象的方法实现远程调用:

    DefaultRemoteInvocationExecutor用于调用目标对象的指定方法实现远程对象调用服务,其源码如下:

    [java] view plaincopyprint
    1. public class DefaultRemoteInvocationExecutor implements RemoteInvocationExecutor { //调用目标对象的方法
    2. public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException{
    3. Assert.notNull(invocation, "RemoteInvocation must not be null"); Assert.notNull(targetObject, "Target object must not be null");
    4. //调用RemoteInvocation的invoke方法 return invocation.invoke(targetObject);
    5. } }
    6. RemoteInvocation的invoke方法源码如下: public Ob