KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > connector > AbstractConnectorRemote


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.connector;
8
9 import java.lang.reflect.InvocationTargetException JavaDoc;
10 import java.rmi.RemoteException JavaDoc;
11 import java.util.Date JavaDoc;
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 /**
19  * 远程接入服务的超类
20  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
21  */

22
23 public abstract class AbstractConnectorRemote extends AbstractService implements ConnectorRemote, ActiveComponent {
24
25     /**
26      * ConnectorHandler 控制中心
27      */

28     private transient HandlerManager handlerManager = HandlerManager.getInstance();
29
30     private int port = 0;
31
32     protected transient Registry registry;
33
34     public Object JavaDoc invoke(Invocation invocation) throws RemoteException JavaDoc, Exception JavaDoc {
35         try {
36             return handlerManager.execute(invocation);
37         }
38         catch(Throwable JavaDoc e) {
39             Exception JavaDoc ex = (Exception JavaDoc) e;
40             if(e instanceof InvocationTargetException JavaDoc) {
41                 Throwable JavaDoc t = ((InvocationTargetException JavaDoc) e).getTargetException();
42                 if(t instanceof Exception JavaDoc) {
43                     ex = (Exception JavaDoc) t;
44                 }
45                 else {
46                     ex = new Exception JavaDoc(t);
47                 }
48             }
49             logger.warn(ex.getMessage(), ex);
50             if(ex instanceof RuntimeException JavaDoc) {
51                 throw new RemoteException JavaDoc(((RuntimeException JavaDoc) ex).getMessage(), ex);
52             }
53             else {
54                 throw ex;
55             }
56         }
57     }
58
59     public void ping() throws RemoteException JavaDoc {
60         logger.debug("ping pang - " + new Date JavaDoc());
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 JavaDoc e) {
83
84             }
85         }
86     }
87
88     public static void main(String JavaDoc[] args) {
89
90     }
91 }
92
Popular Tags