EJB クライアント アプリケーションがアプリケーション サーバーとの接続を失ったときに発生する特定のケースの例外ハンドラーを作成したいと考えています。私たちが作成しているコードは、フェイルオーバー環境で同じサーバーまたは別のサーバーへの再接続を試行するユーザー フレンドリーな方法でクライアント アプリケーションを処理できます。「接続を失う」とは、再接続が必要なものを意味します。原因としては、ネットワークの問題、サーバーのロックアップ、サービスのダウンなどが考えられます。
これが私たちが探しているもののアイデアです(クライアントコード):
private void doSomething() throws RecoverableException {
//(...)
BusinessRemoteEJB ejb=ctx.lookup("BusinessRemoteEJB");
try {
List<product> list=ejb.getProducts();
//(...)
} catch (EJBException e){
Exception e = e.getCausedByException();
//Here is what I'm looking for: some excpetion that indicates a connection problem
if(e !=null && e instanceof EJBConnectionException){
//This will be catched in a proper place to try to reconnect
throw new RecoverableException(e);
} else {
//If it is any other excpetion, just let it work up the stack
throw e;
}
もちろんEJBConnectionExceptionは存在しません。そのようなものはありますか?
OpenEJB 1.4 (EJB 3.x 準拠) を使用しています。ただし、可能であれば、異なるアプリケーション サーバー間で使用できる例外ハンドラーを使用したいと考えています。
もう 1 つのことは、一部のアプリケーション サーバーは何らかのフェイルオーバー メカニズムを提供することですが、私たちの要件は少し特殊であり、クライアント コードに直接実装することができます。