1 21 22 package com.rift.coad.util.connection; 24 25 import java.lang.reflect.InvocationHandler ; 27 import java.lang.reflect.Method ; 28 import java.lang.reflect.InvocationTargetException ; 29 30 36 public class ConnectionHandler implements InvocationHandler { 37 38 private RMIConnection rmiConnection = null; 40 private Object rmiRef = null; 41 42 43 49 public ConnectionHandler(RMIConnection rmiConnection, Object rmiRef) { 50 this.rmiConnection = rmiConnection; 51 this.rmiRef = rmiRef; 52 } 53 54 55 63 public Object invoke(Object proxy, Method method, Object [] args) throws 64 Throwable { 65 try { 66 Method rmiMethod = rmiRef.getClass().getMethod(method.getName(), 68 method.getParameterTypes()); 69 70 return rmiMethod.invoke(rmiRef,args); 72 } catch (InvocationTargetException ex) { 73 Throwable ex2 = ex.getTargetException(); 74 if ((ex2 instanceof java.rmi.RemoteException ) || 75 (ex2 instanceof java.lang.RuntimeException )) 76 { 77 rmiConnection.invalidateConnection(); 78 } 79 throw ex2; 80 } catch (Throwable ex) { 81 if ((ex instanceof java.rmi.RemoteException ) || 82 (ex instanceof java.lang.RuntimeException )) 83 { 84 rmiConnection.invalidateConnection(); 85 } 86 throw ex; 87 } 88 } 89 90 } 91 | Popular Tags |