我想为 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)。但是,如果可能,我们希望使用可以跨不同应用程序服务器使用的异常处理程序。
另一件事是,一些应用服务器提供了某种故障转移机制,但我们的要求有点具体,我们可以直接在客户端代码中实现它。