KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jetty > cluster > ClusterStore


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.jetty.cluster;
8
9 import java.lang.reflect.Method JavaDoc;
10
11 import org.jfox.ioc.connector.ClusterInvocation;
12 import org.jfox.ioc.connector.ClusterServer;
13 import org.jfox.ioc.connector.ClusterableContainer;
14 import org.jfox.ioc.connector.ConnectorServer;
15 import org.jfox.ioc.connector.Container;
16 import org.jfox.ioc.connector.Handler;
17 import org.jfox.ioc.connector.Invocation;
18 import org.jfox.ioc.connector.ServerNode;
19 import org.jfox.ioc.logger.Logger;
20 import org.mortbay.j2ee.session.AbstractReplicatedStore;
21
22 /**
23  * 使用ClusterServer发送和接收Session信息
24  * ClusterStore 作为 Session容器
25  * <p/>
26  * 主要需要覆盖 publish方法,改用ClusterServer.cast来发布消息
27  *
28  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
29  */

30
31 public class ClusterStore extends AbstractReplicatedStore implements ClusterableContainer, Handler {
32     protected Logger _log = Logger.getLogger(ClusterStore.class);
33
34     public ClusterStore() {
35         super();
36     }
37
38     public void start() throws Exception JavaDoc {
39         super.start();
40     }
41
42     public void stop() {
43         super.stop();
44     }
45
46     public void destroy() {
47         super.destroy();
48     }
49
50     protected void publish(String JavaDoc id, Method JavaDoc method, Object JavaDoc[] argInstances) {
51         HttpSessionInvocation invocation = new HttpSessionInvocation(null, null, argInstances);
52         invocation.setSessionId(id);
53         invocation.setMethodId((Integer JavaDoc) _methodToInteger.get(method));
54         // 使用 ClusterServer cast invocation
55
ClusterInvocation clusterInvocation = new ClusterInvocation(invocation, ServerNode.THE_NODE);
56         ClusterServer clusterServer = ConnectorServer.getClusterServer();
57         if (clusterServer != null) { // clusterServer 存在
58
try {
59                 clusterServer.cast(clusterInvocation);
60             }
61             catch (Exception JavaDoc e) {
62                 _log.warn("session publish failed.", e);
63             }
64         }
65
66     }
67
68     /**
69      * 进行 Session 同步
70      *
71      * @param invocation
72      */

73     public void syncInvocation(Invocation invocation) {
74         HttpSessionInvocation sessionInvocation = (HttpSessionInvocation) invocation;
75         String JavaDoc id = sessionInvocation.getSessionId();
76         Integer JavaDoc method = sessionInvocation.getMethodId();
77         Object JavaDoc[] args = sessionInvocation.getArgs();
78         //TODO:使用dispatch分发消息
79
// dispatch(id,method,args);
80
}
81
82     public Class JavaDoc getHandlerClass() {
83         return this.getClass();
84     }
85
86     public Class JavaDoc getInvocationClass() {
87         return HttpSessionInvocation.class;
88     }
89
90     public Container getContainer() {
91         return this;
92     }
93
94     /**
95      * 直接调用 syncInvocation
96      *
97      * @param invocation
98      * @return
99      * @throws Throwable
100      */

101     public Object JavaDoc execute(Invocation invocation) throws Throwable JavaDoc {
102         syncInvocation(invocation);
103         return null;
104     }
105
106     /**
107      * 无需调用到
108      *
109      * @param hashId
110      */

111     public Method JavaDoc getMethodByHash(String JavaDoc hashId) {
112         return null;
113     }
114
115     public static void main(String JavaDoc[] args) {
116
117     }
118 }
119
Popular Tags