public class RmiClientInterceptor extends RemoteInvocationBasedAccessor implements MethodInterceptor
MethodInterceptor
。サービス URL は有効な RMIURL である必要があります(例: "rmi://localhost:1099/myservice")。RMI 呼び出し側は RmiInvocationHandler レベルで動作し、サービスに必要なスタブは 1 つだけです。サービスインターフェースは java.rmi.Remote
を継承したり、java.rmi.RemoteException
をスローしたりする必要はありません。Spring のチェックされていない RemoteAccessException は、リモート呼び出しの失敗時にスローされます。もちろん、入出力パラメーターは直列化可能でなければなりません。
従来の RMI サービスでは、この呼び出しは通常 RMI サービスインターフェースで使用されます。または、この呼び出し側は、リモート RMI サービスを、一致する非 RMI ビジネスインターフェース、つまり RMI サービスメソッドをミラーリングするが RemoteExceptions を宣言しないインターフェースでプロキシすることもできます。後者の場合、RMI スタブによってスローされた RemoteExceptions は、Spring の未チェックの RemoteAccessException に自動的に変換されます。
RmiServiceExporter
, RmiProxyFactoryBean
, RmiInvocationHandler
, RemoteAccessException
, RemoteException
SE, Remote
SElogger
コンストラクターと説明 |
---|
RmiClientInterceptor() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterPropertiesSet() |
protected ObjectSE | doInvoke(MethodInvocation invocation, RemoteSE stub) 指定された RMI スタブで指定された呼び出しを実行します。 |
protected ObjectSE | doInvoke(MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler) 指定された RmiInvocationHandler に指定された AOP メソッド呼び出しを適用します。 |
protected RemoteSE | getStub() 使用する RMI スタブを返します。 |
ObjectSE | invoke(MethodInvocation invocation) RMI スタブをフェッチし、 doInvoke に委譲します。 |
protected boolean | isConnectFailure(RemoteExceptionSE ex) 指定された RMI 例外が接続障害を示しているかどうかを判別します。 |
protected RemoteSE | lookupStub() 通常は検索して、RMI スタブを作成します。 |
void | prepare() 必要に応じて、起動時に RMI スタブを取得します。 |
protected ObjectSE | refreshAndRetry(MethodInvocation invocation) RMI スタブをリフレッシュし、指定された呼び出しを再試行します。 |
void | setCacheStub(boolean cacheStub) RMI スタブが見つかったら、キャッシュするかどうかを設定します。 |
void | setLookupStubOnStartup(boolean lookupStubOnStartup) 起動時に RMI スタブを検索するかどうかを設定します。 |
void | setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure) 接続障害時に RMI スタブをリフレッシュするかどうかを設定します。 |
void | setRegistryClientSocketFactory(RMIClientSocketFactorySE registryClientSocketFactory) RMI レジストリへのアクセスに使用するカスタム RMI クライアントソケットファクトリを設定します。 |
createRemoteInvocation, getRemoteInvocationFactory, recreateRemoteInvocationResult, setRemoteInvocationFactory
getServiceUrl, setServiceUrl
getServiceInterface, setServiceInterface
getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public void setLookupStubOnStartup(boolean lookupStubOnStartup)
RMI サーバーの開始を遅らせるためにオフにすることができます。この場合、RMI スタブは最初のアクセスで取得されます。
public void setCacheStub(boolean cacheStub)
RMI サーバーのホットリスタートを可能にするためにオフにすることができます。この場合、呼び出しごとに RMI スタブがフェッチされます。
public void setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)
オンにすると、RMI サーバーのホットリスタートが可能になります。キャッシュされた RMI スタブがリモート接続障害を示す RMI 例外をスローした場合、新しいプロキシがフェッチされ、呼び出しが再試行されます。
public void setRegistryClientSocketFactory(RMIClientSocketFactorySE registryClientSocketFactory)
public void afterPropertiesSet()
InitializingBean
BeanFactoryAware
、ApplicationContextAware
などを満たした後、包含 BeanFactory
によって呼び出されます。このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。
InitializingBean
の afterPropertiesSet
UrlBasedRemoteAccessor
の afterPropertiesSet
public void prepare() throws RemoteLookupFailureException
RemoteLookupFailureException
- RMI スタブの作成が失敗した場合 setLookupStubOnStartup(boolean)
, lookupStub()
protected RemoteSE lookupStub() throws RemoteLookupFailureException
"cacheStub" が "true" の場合はインターセプターの初期化時に呼び出され、それ以外の場合は getStub()
による各呼び出しごとに呼び出されます。
デフォルトの実装では、java.rmi.Naming
を介してサービス URL を検索します。これはサブクラスでオーバーライドできます。
RemoteLookupFailureException
- RMI スタブの作成が失敗した場合 setCacheStub(boolean)
, Naming.lookup(java.lang.String)
SEprotected RemoteSE getStub() throws RemoteLookupFailureException
デフォルトの実装は、初期化時に作成されたスタブを返します(存在する場合)。それ以外の場合は、lookupStub()
を呼び出して、呼び出しごとに新しいスタブを取得します。これは、サブクラスでオーバーライドできます。たとえば、スタブを再作成する前に一定の時間キャッシュするため、またはスタブがまだ生きているかどうかをテストするためです。
RemoteLookupFailureException
- RMI スタブの作成が失敗した場合 lookupStub()
public ObjectSE invoke(MethodInvocation invocation) throws ThrowableSE
doInvoke
に委譲します。接続障害時にリフレッシュするように構成されている場合、対応する RMI 例外で refreshAndRetry(org.aopalliance.intercept.MethodInvocation)
を呼び出します。MethodInterceptor
の invoke
invocation
- メソッド呼び出しジョインポイント Joinpoint.proceed()
の呼び出しの結果。インターセプターによってインターセプトされる可能性があります ThrowableSE
- インターセプターまたはターゲットオブジェクトが例外をスローする場合 getStub()
, doInvoke(MethodInvocation, Remote)
, refreshAndRetry(org.aopalliance.intercept.MethodInvocation)
, ConnectException
SE, ConnectIOException
SE, NoSuchObjectException
SEprotected boolean isConnectFailure(RemoteExceptionSE ex)
デフォルトの実装は RmiClientInterceptorUtils.isConnectFailure(java.rmi.RemoteException)
に委譲します。
ex
- 確認する RMI 例外 @Nullable protected ObjectSE refreshAndRetry(MethodInvocation invocation) throws ThrowableSE
invocation
- AOP メソッドの呼び出し ThrowableSE
- 呼び出しが失敗した場合 invoke(org.aopalliance.intercept.MethodInvocation)
@Nullable protected ObjectSE doInvoke(MethodInvocation invocation, RemoteSE stub) throws ThrowableSE
invocation
- AOP メソッドの呼び出し stub
- 呼び出す RMI スタブ ThrowableSE
- 呼び出しが失敗した場合 @Nullable protected ObjectSE doInvoke(MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler) throws RemoteExceptionSE, NoSuchMethodExceptionSE, IllegalAccessExceptionSE, InvocationTargetExceptionSE
RmiInvocationHandler
に指定された AOP メソッド呼び出しを適用します。 デフォルトの実装は RemoteInvocationBasedAccessor.createRemoteInvocation(org.aopalliance.intercept.MethodInvocation)
に委譲します。
methodInvocation
- 現在の AOP メソッドの呼び出し invocationHandler
- 呼び出しを適用する RmiInvocationHandlerRemoteExceptionSE
- 通信エラーの場合 NoSuchMethodExceptionSE
- メソッド名を解決できなかった場合 IllegalAccessExceptionSE
- メソッドにアクセスできなかった場合 InvocationTargetExceptionSE
- メソッド呼び出しにより例外が発生した場合 RemoteInvocation