1 22 package org.jboss.invocation.http.server; 23 24 import java.io.Serializable ; 25 import java.util.ArrayList ; 26 import java.util.Hashtable ; 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServer ; 30 import javax.naming.InitialContext ; 31 32 import org.jboss.invocation.Invoker; 33 import org.jboss.invocation.InvokerInterceptor; 34 import org.jboss.invocation.http.interfaces.ClientMethodInterceptorHA; 35 import org.jboss.invocation.http.interfaces.HttpInvokerProxyHA; 36 import org.jboss.system.server.ServerConfigUtil; 37 import org.jboss.ha.framework.interfaces.LoadBalancePolicy; 38 import org.jboss.ha.framework.interfaces.HAPartition; 39 import org.jboss.ha.framework.server.HATarget; 40 41 50 public class HttpProxyFactoryHA extends HttpProxyFactory 51 implements HttpProxyFactoryHAMBean 52 { 53 private ObjectName realJmxInvokerName; 54 private ObjectName wrappedJmxInvokerName; 55 private String partitionName = ServerConfigUtil.getDefaultPartitionName(); 56 private Class policyClass; 57 private HAInvokerWrapper invokerWrapper; 58 private HATarget invokerTarget; 59 60 62 public Class getLoadBalancePolicy() 63 { 64 return this.policyClass; 65 } 66 68 public void setLoadBalancePolicy(Class policyClass) 69 { 70 this.policyClass = policyClass; 71 } 72 73 75 public String getPartitionName() 76 { 77 return this.partitionName; 78 } 79 81 public void setPartitionName(String name) 82 { 83 this.partitionName = name; 84 } 85 86 93 public void setInvokerName(ObjectName jmxInvokerName) 94 { 95 realJmxInvokerName = jmxInvokerName; 96 ObjectName factoryName = getServiceName(); 97 Hashtable props = factoryName.getKeyPropertyList(); 98 props.put("wrapperType", "httpHA"); 99 try 100 { 101 wrappedJmxInvokerName = new ObjectName (factoryName.getDomain(), props); 102 super.setInvokerName(wrappedJmxInvokerName); 103 } 104 catch(MalformedObjectNameException e) 105 { 106 throw new IllegalStateException ("Was not able to create wrapped ObjectName"); 107 } 108 } 109 110 113 public ObjectName getRealJmxInvokerName() 114 { 115 return realJmxInvokerName; 116 } 117 118 121 protected ArrayList defineInterceptors() 122 { 123 ArrayList interceptorClasses = new ArrayList (); 124 interceptorClasses.add(ClientMethodInterceptorHA.class); 125 interceptorClasses.add(InvokerInterceptor.class); 126 return interceptorClasses; 127 } 128 129 133 protected Invoker createInvoker() throws Exception 134 { 135 InitialContext iniCtx = new InitialContext (); 136 HAPartition partition = (HAPartition) iniCtx.lookup("/HAPartition/" + partitionName); 137 138 143 checkInvokerURL(); 144 Serializable invokerStub = super.getInvokerURL(); 145 invokerTarget = new HATarget(partition, wrappedJmxInvokerName.toString(), 146 invokerStub, HATarget.MAKE_INVOCATIONS_WAIT); 147 log.debug("Created invoker: "+invokerTarget); 148 MBeanServer mbeanServer = super.getServer(); 150 invokerWrapper = new HAInvokerWrapper(mbeanServer, realJmxInvokerName, invokerTarget); 151 mbeanServer.registerMBean(invokerWrapper, wrappedJmxInvokerName); 152 153 LoadBalancePolicy policy = (LoadBalancePolicy) policyClass.newInstance(); 155 156 String clusterFamilyName = partitionName + "/" + wrappedJmxInvokerName.toString(); 158 Invoker delegateInvoker = new HttpInvokerProxyHA(invokerTarget.getReplicants(), invokerTarget.getCurrentViewId (), 159 policy, clusterFamilyName); 160 return delegateInvoker; 161 } 162 163 168 protected void stopService() throws Exception 169 { 170 try 171 { 172 MBeanServer mbeanServer = super.getServer(); 173 mbeanServer.unregisterMBean(wrappedJmxInvokerName); 174 } 175 catch(Exception e) 176 { 177 log.debug("Failed to unregister HAInvokerWrapper: "+wrappedJmxInvokerName, e); 178 } 179 super.stopService(); 180 } 181 182 184 public void destroy() 185 { 186 super.destroy(); 187 try 188 { 189 invokerTarget.destroy(); 190 } 191 catch(Exception ignore) 192 { 193 } 194 } 195 196 } 197 | Popular Tags |