1 17 18 19 package org.apache.catalina.startup; 20 21 22 import org.apache.tomcat.util.digester.Digester; 23 import org.apache.tomcat.util.digester.RuleSetBase; 24 import java.lang.reflect.Constructor ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import java.lang.reflect.InvocationTargetException ; 30 public class ClusterRuleSetFactory { 31 32 public static Log log = LogFactory.getLog(ClusterRuleSetFactory.class); 33 34 public static RuleSetBase getClusterRuleSet(String prefix) { 35 36 try { 39 return loadRuleSet(prefix,"org.apache.catalina.cluster.ClusterRuleSet",ClusterRuleSetFactory.class.getClassLoader()); 40 } catch ( Exception x ) { 41 if ( log.isDebugEnabled() ) log.debug("Unable to load ClusterRuleSet (org.apache.catalina.cluster.ClusterRuleSet), falling back on context classloader"); 43 } 44 try { 46 return loadRuleSet(prefix,"org.apache.catalina.cluster.ClusterRuleSet",Thread.currentThread().getContextClassLoader()); 47 } catch ( Exception x ) { 48 if ( log.isDebugEnabled() ) log.debug("Unable to load ClusterRuleSet (org.apache.catalina.cluster.ClusterRuleSet), will try to load the HA cluster"); 50 } 51 52 try { 55 return loadRuleSet(prefix,"org.apache.catalina.ha.ClusterRuleSet",ClusterRuleSetFactory.class.getClassLoader()); 56 } catch ( Exception x ) { 57 if ( log.isDebugEnabled() ) log.debug("Unable to load HA ClusterRuleSet (org.apache.catalina.ha.ClusterRuleSet), falling back on context classloader"); 59 } 60 try { 62 return loadRuleSet(prefix,"org.apache.catalina.ha.ClusterRuleSet",Thread.currentThread().getContextClassLoader()); 63 } catch ( Exception x ) { 64 if ( log.isDebugEnabled() ) log.debug("Unable to load HA ClusterRuleSet (org.apache.catalina.ha.ClusterRuleSet), falling back on DefaultClusterRuleSet"); 66 } 67 68 log.info("Unable to find a cluster rule set in the classpath. Will load the default rule set."); 69 return new DefaultClusterRuleSet(prefix); 70 } 71 72 73 protected static RuleSetBase loadRuleSet(String prefix, String className, ClassLoader cl) 74 throws ClassNotFoundException , InstantiationException , 75 NoSuchMethodException ,IllegalAccessException , 76 InvocationTargetException { 77 Class clazz = Class.forName(className,true,cl); 78 Constructor cons = clazz.getConstructor(new Class [] {String .class}); 79 return (RuleSetBase)cons.newInstance(prefix); 80 } 81 82 90 91 public static class DefaultClusterRuleSet extends RuleSetBase { 92 93 94 96 97 100 protected String prefix = null; 101 102 103 105 106 110 public DefaultClusterRuleSet() { 111 112 this(""); 113 114 } 115 116 117 124 public DefaultClusterRuleSet(String prefix) { 125 super(); 126 this.namespaceURI = null; 127 this.prefix = prefix; 128 } 129 130 131 133 134 143 public void addRuleInstances(Digester digester) { 144 digester.addObjectCreate(prefix + "Membership", 146 null, "className"); 148 digester.addSetProperties(prefix + "Membership"); 149 digester.addSetNext(prefix + "Membership", 150 "setMembershipService", 151 "org.apache.catalina.cluster.MembershipService"); 152 153 digester.addObjectCreate(prefix + "Sender", 154 null, "className"); 156 digester.addSetProperties(prefix + "Sender"); 157 digester.addSetNext(prefix + "Sender", 158 "setClusterSender", 159 "org.apache.catalina.cluster.ClusterSender"); 160 161 digester.addObjectCreate(prefix + "Receiver", 162 null, "className"); 164 digester.addSetProperties(prefix + "Receiver"); 165 digester.addSetNext(prefix + "Receiver", 166 "setClusterReceiver", 167 "org.apache.catalina.cluster.ClusterReceiver"); 168 169 digester.addObjectCreate(prefix + "Valve", 170 null, "className"); 172 digester.addSetProperties(prefix + "Valve"); 173 digester.addSetNext(prefix + "Valve", 174 "addValve", 175 "org.apache.catalina.Valve"); 176 177 digester.addObjectCreate(prefix + "Deployer", 178 null, "className"); 180 digester.addSetProperties(prefix + "Deployer"); 181 digester.addSetNext(prefix + "Deployer", 182 "setClusterDeployer", 183 "org.apache.catalina.cluster.ClusterDeployer"); 184 185 digester.addObjectCreate(prefix + "Listener", 186 null, "className"); 188 digester.addSetProperties(prefix + "Listener"); 189 digester.addSetNext(prefix + "Listener", 190 "addLifecycleListener", 191 "org.apache.catalina.LifecycleListener"); 192 193 digester.addObjectCreate(prefix + "ClusterListener", 194 null, "className"); 196 digester.addSetProperties(prefix + "ClusterListener"); 197 digester.addSetNext(prefix + "ClusterListener", 198 "addClusterListener", 199 "org.apache.catalina.cluster.MessageListener"); 200 } 202 203 204 } 205 } 206 | Popular Tags |