1 6 7 package org.jfox.ioc.connector; 8 9 import java.lang.reflect.InvocationTargetException ; 10 import java.rmi.RemoteException ; 11 import java.util.Date ; 12 13 import org.jfox.ioc.ComponentContext; 14 import org.jfox.ioc.Registry; 15 import org.jfox.ioc.common.AbstractService; 16 import org.jfox.ioc.ext.ActiveComponent; 17 18 22 23 public abstract class AbstractConnectorRemote extends AbstractService implements ConnectorRemote, ActiveComponent { 24 25 28 private transient HandlerManager handlerManager = HandlerManager.getInstance(); 29 30 private int port = 0; 31 32 protected transient Registry registry; 33 34 public Object invoke(Invocation invocation) throws RemoteException , Exception { 35 try { 36 return handlerManager.execute(invocation); 37 } 38 catch(Throwable e) { 39 Exception ex = (Exception ) e; 40 if(e instanceof InvocationTargetException ) { 41 Throwable t = ((InvocationTargetException ) e).getTargetException(); 42 if(t instanceof Exception ) { 43 ex = (Exception ) t; 44 } 45 else { 46 ex = new Exception (t); 47 } 48 } 49 logger.warn(ex.getMessage(), ex); 50 if(ex instanceof RuntimeException ) { 51 throw new RemoteException (((RuntimeException ) ex).getMessage(), ex); 52 } 53 else { 54 throw ex; 55 } 56 } 57 } 58 59 public void ping() throws RemoteException { 60 logger.debug("ping pang - " + new Date ()); 61 } 62 63 public void setPort(int port) { 64 this.port = port; 65 } 66 67 public int getPort() { 68 return port; 69 } 70 71 public void setComponentContext(ComponentContext ctx) { 72 super.setComponentContext(ctx); 73 registry = context.getRegistry(); 74 } 75 76 public void run() { 77 while(isStarted()) { 78 try { 79 Thread.sleep(30 * 60 * 1000L); 80 ping(); 81 } 82 catch(Exception e) { 83 84 } 85 } 86 } 87 88 public static void main(String [] args) { 89 90 } 91 } 92 | Popular Tags |