1 22 package org.jboss.ejb3.stateless; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import org.jboss.annotation.ejb.Clustered; 26 import org.jboss.annotation.ejb.RemoteBinding; 27 import org.jboss.aop.Advisor; 28 import org.jboss.aop.AspectManager; 29 import org.jboss.aop.advice.AdviceStack; 30 import org.jboss.aspects.remoting.FamilyWrapper; 31 import org.jboss.ejb3.JBossProxy; 32 import org.jboss.ejb3.ProxyFactoryHelper; 33 import org.jboss.ejb3.remoting.RemoteProxyFactory; 34 import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository; 35 import org.jboss.ha.framework.interfaces.HAPartition; 36 import org.jboss.ha.framework.interfaces.LoadBalancePolicy; 37 import org.jboss.ha.framework.interfaces.RandomRobin; 38 import org.jboss.ha.framework.server.HATarget; 39 import org.jboss.remoting.InvokerLocator; 40 41 42 48 public class StatelessClusterProxyFactory extends BaseStatelessProxyFactory implements RemoteProxyFactory 49 { 50 private RemoteBinding binding; 51 private InvokerLocator locator; 52 private HATarget hatarget; 53 private String proxyFamilyName; 54 private LoadBalancePolicy lbPolicy; 55 private FamilyWrapper wrapper; 56 57 public void setRemoteBinding(RemoteBinding binding) 58 { 59 this.binding = binding; 60 } 61 62 protected Class [] getInterfaces() 63 { 64 Class [] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container); 65 Class [] interfaces = new Class [remoteInterfaces.length + 1]; 66 System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length); 67 interfaces[remoteInterfaces.length] = JBossProxy.class; 68 return interfaces; 69 } 70 71 protected void initializeJndiName() 72 { 73 jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding); 74 } 75 76 public void start() throws Exception 77 { 78 String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding); 79 locator = new InvokerLocator(clientBindUrl); 80 Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class); 81 if (clustered == null) throw new RuntimeException ("Could not find @Clustered annotation. Cannot deploy."); 82 String partitionName = clustered.partition(); 83 proxyFamilyName = container.getEjbName() + locator.getProtocol() + partitionName; 84 HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName); 85 hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS); 86 ClusteringTargetsRepository.initTarget(proxyFamilyName, hatarget.getReplicants()); 87 ((StatelessContainer) container).getClusterFamilies().put(proxyFamilyName, hatarget); 88 if (clustered.loadBalancePolicy() == null || clustered.loadBalancePolicy().equals(LoadBalancePolicy.class)) 89 { 90 lbPolicy = new RandomRobin(); 91 } 92 else 93 { 94 lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance(); 95 } 96 wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants()); 97 super.start(); 98 } 99 100 public void stop() throws Exception 101 { 102 super.stop(); 103 hatarget.destroy(); 104 ((StatelessContainer) container).getClusterFamilies().remove(proxyFamilyName); 105 } 106 107 public Object createProxy() 108 { 109 { 111 Object containerId = container.getObjectName().getCanonicalName(); 112 String stackName = "ClusteredStatelessSessionClientInterceptors"; 113 if (binding.interceptorStack() != null && !binding.interceptorStack().equals("")) 114 { 115 stackName = binding.interceptorStack(); 116 } 117 AdviceStack stack = AspectManager.instance().getAdviceStack(stackName); 118 122 return constructProxy(new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), wrapper, lbPolicy)); 123 } 124 142 } 143 144 protected StatelessHandleImpl getHandle() 145 { 146 StatelessHandleImpl handle = new StatelessHandleImpl(); 147 RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class); 148 if (remoteBinding != null) 149 handle.jndiName = remoteBinding.jndiBinding(); 150 151 return handle; 152 } 153 } 154 | Popular Tags |