KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jndi > ClusterableJNDIContainerImpl


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.jndi;
8
9 import java.lang.reflect.Method JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12
13 import javax.naming.Name JavaDoc;
14 import javax.naming.Context JavaDoc;
15
16 import org.jfox.ioc.connector.ClusterableContainer;
17 import org.jfox.ioc.connector.Invocation;
18
19 /**
20  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
21  */

22
23 public class ClusterableJNDIContainerImpl extends JNDIContainerImpl implements ClusterableContainer {
24
25     /**
26      * 储存需要进行Cluster同步的方法名
27      */

28     private List JavaDoc<String JavaDoc> clusterMethods = new ArrayList JavaDoc<String JavaDoc>();
29     {
30         clusterMethods.add("bind");
31         clusterMethods.add("rebind");
32         clusterMethods.add("unbind");
33         clusterMethods.add("createSubcontext");
34         clusterMethods.add("destroySubcontext");
35         clusterMethods.add("closeSubcontext");
36     }
37
38     /**
39      * ClusterableContainer 接口方法,由ClusterHandler调用
40      * @param invocation
41      */

42     public void syncInvocation(Invocation invocation) {
43         try {
44             Method JavaDoc method = invocation.getMethod();
45             Object JavaDoc[] args = invocation.getArgs();
46             if(clusterMethods.contains(method.getName())){
47                 logger.debug("syncInvocation " + invocation);
48                 // 需要进行同步的方法
49
if(method.getName().equals("bind")) {
50                     Context JavaDoc ctx = (Context JavaDoc) args[0];
51                     Name JavaDoc name = (Name JavaDoc) args[1];
52                     Object JavaDoc bindObject = args[2];
53                     String JavaDoc className = (String JavaDoc) args[3];
54                     this.rebind(ctx, name, bindObject, className);
55                 }
56                 else {
57                     method.invoke(this, args);
58                 }
59             }
60         }
61         catch(Exception JavaDoc e){
62              logger.warn("syncInvocation " + invocation + " error.",e);
63         }
64     }
65
66     public static void main(String JavaDoc[] args) {
67
68     }
69 }
70
Popular Tags