org.springframework.remoting.rmi

## 类 RmiClientInterceptor

- java.lang.Object
- - org.springframework.remoting.support.RemotingSupport
  - - org.springframework.remoting.support.RemoteAccessor
    - - org.springframework.remoting.support.UrlBasedRemoteAccessor
      - - org.springframework.remoting.support.RemoteInvocationBasedAccessor
        - - org.springframework.remoting.rmi.RmiClientInterceptor

- 所有已实现的接口:
    org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.InitializingBean
  直接已知子类:
    RmiProxyFactoryBean

      public class RmiClientInterceptor
      extends RemoteInvocationBasedAccessor
      implements org.aopalliance.intercept.MethodInterceptor

  `MethodInterceptor` for accessing conventional RMI services or RMI invokers. The service URL must be a valid RMI URL (e.g. "rmi://localhost:1099/myservice").

  RMI invokers work at the RmiInvocationHandler level, needing only one stub for any service. Service interfaces do not have to extend `java.rmi.Remote` or throw `java.rmi.RemoteException`. Spring's unchecked RemoteAccessException will be thrown on remote invocation failure. Of course, in and out parameters have to be serializable.

  With conventional RMI services, this invoker is typically used with the RMI service interface. Alternatively, this invoker can also proxy a remote RMI service with a matching non-RMI business interface, i.e. an interface that mirrors the RMI service methods but does not declare RemoteExceptions. In the latter case, RemoteExceptions thrown by the RMI stub will automatically get converted to Spring's unchecked RemoteAccessException.

  从以下版本开始:
    29.09.2003
  作者:
    Juergen Hoeller
  另请参阅:
    `RmiServiceExporter`, `RmiProxyFactoryBean`, `RmiInvocationHandler`, `RemoteAccessException`, `RemoteException`, `Remote`

- - ### 字段概要

    - ### 从类继承的字段 org.springframework.remoting.support.RemotingSupport

      `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `RmiClientInterceptor()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `afterPropertiesSet()`
    `protected Object` | `doInvoke(org.aopalliance.intercept.MethodInvocation invocation, Remote stub)` Perform the given invocation on the given RMI stub.
    `protected Object` | `doInvoke(org.aopalliance.intercept.MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler)` Apply the given AOP method invocation to the given `RmiInvocationHandler`.
    `protected Remote` | `getStub()` Return the RMI stub to use.
    `Object` | `invoke(org.aopalliance.intercept.MethodInvocation invocation)` Fetches an RMI stub and delegates to `doInvoke`.
    `protected boolean` | `isConnectFailure(RemoteException ex)` Determine whether the given RMI exception indicates a connect failure.
    `protected Remote` | `lookupStub()` Create the RMI stub, typically by looking it up.
    `void` | `prepare()` Fetches RMI stub on startup, if necessary.
    `protected Object` | `refreshAndRetry(org.aopalliance.intercept.MethodInvocation invocation)` Refresh the RMI stub and retry the given invocation.
    `void` | `setCacheStub(boolean cacheStub)` Set whether to cache the RMI stub once it has been located.
    `void` | `setLookupStubOnStartup(boolean lookupStubOnStartup)` Set whether to look up the RMI stub on startup.
    `void` | `setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)` Set whether to refresh the RMI stub on connect failure.
    `void` | `setRegistryClientSocketFactory(RMIClientSocketFactory registryClientSocketFactory)` Set a custom RMI client socket factory to use for accessing the RMI registry.

    - ### 从类继承的方法 org.springframework.remoting.support.RemoteInvocationBasedAccessor

      `createRemoteInvocation, getRemoteInvocationFactory, recreateRemoteInvocationResult, setRemoteInvocationFactory`

    - ### 从类继承的方法 org.springframework.remoting.support.UrlBasedRemoteAccessor

      `getServiceUrl, setServiceUrl`

    - ### 从类继承的方法 org.springframework.remoting.support.RemoteAccessor

      `getServiceInterface, setServiceInterface`

    - ### 从类继承的方法 org.springframework.remoting.support.RemotingSupport

      `getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### RmiClientInterceptor

          public RmiClientInterceptor()

  - ### 方法详细资料

    - #### setLookupStubOnStartup

          public void setLookupStubOnStartup(boolean lookupStubOnStartup)

      Set whether to look up the RMI stub on startup. Default is "true".

      Can be turned off to allow for late start of the RMI server. In this case, the RMI stub will be fetched on first access.

      另请参阅:
        `setCacheStub(boolean)`

    - #### setCacheStub

          public void setCacheStub(boolean cacheStub)

      Set whether to cache the RMI stub once it has been located. Default is "true".

      Can be turned off to allow for hot restart of the RMI server. In this case, the RMI stub will be fetched for each invocation.

      另请参阅:
        `setLookupStubOnStartup(boolean)`

    - #### setRefreshStubOnConnectFailure

          public void setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)

      Set whether to refresh the RMI stub on connect failure. Default is "false".

      Can be turned on to allow for hot restart of the RMI server. If a cached RMI stub throws an RMI exception that indicates a remote connect failure, a fresh proxy will be fetched and the invocation will be retried.

      另请参阅:
        `ConnectException`, `ConnectIOException`, `NoSuchObjectException`

    - #### setRegistryClientSocketFactory

          public void setRegistryClientSocketFactory(RMIClientSocketFactory registryClientSocketFactory)

      Set a custom RMI client socket factory to use for accessing the RMI registry.
      另请参阅:
        `RMIClientSocketFactory`, `LocateRegistry.getRegistry(String, int, RMIClientSocketFactory)`

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      指定者:
        `afterPropertiesSet` 在接口中 `org.springframework.beans.factory.InitializingBean`
      覆盖:
        `afterPropertiesSet` 在类中 `UrlBasedRemoteAccessor`

    - #### prepare

          public void prepare()
                       throws RemoteLookupFailureException

      Fetches RMI stub on startup, if necessary.
      抛出:
        `RemoteLookupFailureException` - if RMI stub creation failed
      另请参阅:
        `setLookupStubOnStartup(boolean)`, `lookupStub()`

    - #### lookupStub

          protected Remote lookupStub()
                               throws RemoteLookupFailureException

      Create the RMI stub, typically by looking it up.

      Called on interceptor initialization if "cacheStub" is "true"; else called for each invocation by `getStub()`.

      The default implementation looks up the service URL via `java.rmi.Naming`. This can be overridden in subclasses.

      返回:
        the RMI stub to store in this interceptor
      抛出:
        `RemoteLookupFailureException` - if RMI stub creation failed
      另请参阅:
        `setCacheStub(boolean)`, `Naming.lookup(java.lang.String)`

    - #### getStub

          protected Remote getStub()
                            throws RemoteLookupFailureException

      Return the RMI stub to use. Called for each invocation.

      The default implementation returns the stub created on initialization, if any. Else, it invokes `lookupStub()` to get a new stub for each invocation. This can be overridden in subclasses, for example in order to cache a stub for a given amount of time before recreating it, or to test the stub whether it is still alive.

      返回:
        the RMI stub to use for an invocation
      抛出:
        `RemoteLookupFailureException` - if RMI stub creation failed
      另请参阅:
        `lookupStub()`

    - #### invoke

          public Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                        throws Throwable

      Fetches an RMI stub and delegates to `doInvoke`. If configured to refresh on connect failure, it will call `refreshAndRetry(org.aopalliance.intercept.MethodInvocation)` on corresponding RMI exceptions.
      指定者:
        `invoke` 在接口中 `org.aopalliance.intercept.MethodInterceptor`
      抛出:
        `Throwable`
      另请参阅:
        `getStub()`, `doInvoke(MethodInvocation, Remote)`, `refreshAndRetry(org.aopalliance.intercept.MethodInvocation)`, `ConnectException`, `ConnectIOException`, `NoSuchObjectException`

    - #### isConnectFailure

          protected boolean isConnectFailure(RemoteException ex)

      Determine whether the given RMI exception indicates a connect failure.

      The default implementation delegates to `RmiClientInterceptorUtils.isConnectFailure(java.rmi.RemoteException)`.

      参数:
        `ex` - the RMI exception to check
      返回:
        whether the exception should be treated as connect failure

    - #### refreshAndRetry

          @Nullable
          protected Object refreshAndRetry(org.aopalliance.intercept.MethodInvocation invocation)
                                               throws Throwable

      Refresh the RMI stub and retry the given invocation. Called by invoke on connect failure.
      参数:
        `invocation` - the AOP method invocation
      返回:
        the invocation result, if any
      抛出:
        `Throwable` - in case of invocation failure
      另请参阅:
        `invoke(org.aopalliance.intercept.MethodInvocation)`

    - #### doInvoke

          @Nullable
          protected Object doInvoke(org.aopalliance.intercept.MethodInvocation invocation,
                                               Remote stub)
                                        throws Throwable

      Perform the given invocation on the given RMI stub.
      参数:
        `invocation` - the AOP method invocation
        `stub` - the RMI stub to invoke
      返回:
        the invocation result, if any
      抛出:
        `Throwable` - in case of invocation failure

    - #### doInvoke

          @Nullable
          protected Object doInvoke(org.aopalliance.intercept.MethodInvocation methodInvocation,
                                               RmiInvocationHandler invocationHandler)
                                        throws RemoteException,
                                               NoSuchMethodException,
                                               IllegalAccessException,
                                               InvocationTargetException

      Apply the given AOP method invocation to the given `RmiInvocationHandler`.

      The default implementation delegates to `RemoteInvocationBasedAccessor.createRemoteInvocation(org.aopalliance.intercept.MethodInvocation)`.

      参数:
        `methodInvocation` - the current AOP method invocation
        `invocationHandler` - the RmiInvocationHandler to apply the invocation to
      返回:
        the invocation result
      抛出:
        `RemoteException` - in case of communication errors
        `NoSuchMethodException` - if the method name could not be resolved
        `IllegalAccessException` - if the method could not be accessed
        `InvocationTargetException` - if the method invocation resulted in an exception
      另请参阅:
        `RemoteInvocation`