1 22 package org.jboss.invocation.pooled.server; 23 24 import org.jboss.system.Registry; 25 import java.rmi.MarshalledObject ; 26 import javax.management.ObjectName ; 27 import org.jboss.invocation.Invocation; 28 import org.jboss.invocation.MarshalledInvocation; 29 import org.jboss.invocation.pooled.interfaces.PooledInvokerProxy; 30 import org.jboss.invocation.pooled.interfaces.ServerAddress; 31 import java.util.HashMap ; 32 import org.jboss.invocation.Invoker; 33 import org.jboss.invocation.InvokerHA; 34 import org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxyHA; 35 import org.jboss.ha.framework.interfaces.HARMIResponse; 36 import org.jboss.ha.framework.server.HATarget; 37 import org.jboss.ha.framework.interfaces.LoadBalancePolicy; 38 import org.jboss.ha.framework.interfaces.GenericClusteringException; 39 import javax.management.InstanceNotFoundException ; 40 import javax.management.ReflectionException ; 41 42 import java.util.ArrayList ; 43 44 65 public final class PooledInvokerHA extends PooledInvoker implements InvokerHA 66 { 67 protected HashMap beanMap = new HashMap (); 68 69 protected void jmxBind() 70 { 71 Registry.bind(getServiceName(), this); 72 } 73 74 76 public java.io.Serializable getStub() 77 { 78 ServerAddress sa = new ServerAddress(clientConnectAddress, 79 clientConnectPort, enableTcpNoDelay, timeout, clientSocketFactory); 80 return new PooledInvokerProxy(sa, clientMaxPoolSize); 81 } 82 83 public void registerBean(ObjectName beanName, HATarget target) throws Exception 84 { 85 Integer hash = new Integer (beanName.hashCode()); 86 log.debug("registerBean: "+beanName); 87 88 if (beanMap.containsKey(hash)) 89 { 90 throw new IllegalStateException ("Trying to register bean with the existing hashCode"); 92 } 93 beanMap.put(hash, target); 94 } 95 96 public Invoker createProxy(ObjectName beanName, LoadBalancePolicy policy, 97 String proxyFamilyName) throws Exception 98 { 99 Integer hash = new Integer (beanName.hashCode()); 100 HATarget target = (HATarget) beanMap.get(hash); 101 if (target == null) 102 { 103 throw new IllegalStateException ("The bean hashCode not found"); 104 } 105 106 String familyName = proxyFamilyName; 107 if (familyName == null) 108 familyName= target.getAssociatedPartition().getPartitionName() + "/" + beanName; 109 110 JRMPInvokerProxyHA proxy = new JRMPInvokerProxyHA(target.getReplicants(), 111 policy, 112 familyName, 113 target.getCurrentViewId ()); 114 return proxy; 115 } 116 117 public void unregisterBean(ObjectName beanName) throws Exception 118 { 119 Integer hash = new Integer (beanName.hashCode()); 120 beanMap.remove(hash); 121 } 122 123 126 public Object invoke(Invocation invocation) 127 throws Exception 128 { 129 ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); 130 try 131 { 132 invocation.setTransaction(importTPC(((MarshalledInvocation) invocation).getTransactionPropagationContext())); 134 135 ObjectName mbean = (ObjectName ) Registry.lookup(invocation.getObjectName()); 137 long clientViewId = ((Long )invocation.getValue("CLUSTER_VIEW_ID")).longValue(); 138 139 HATarget target = (HATarget)beanMap.get(invocation.getObjectName()); 140 if (target == null) 141 { 142 throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, 151 "target is not/no more registered on this node"); 152 } 153 154 if (!target.invocationsAllowed ()) 155 throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, 156 "invocations are currently not allowed on this target"); 157 158 Object rtn = getServer().invoke(mbean, 160 "invoke", 161 new Object [] { invocation }, 162 Invocation.INVOKE_SIGNATURE); 163 164 HARMIResponse rsp = new HARMIResponse(); 165 166 if (clientViewId != target.getCurrentViewId()) 167 { 168 rsp.newReplicants = new ArrayList (target.getReplicants()); 169 rsp.currentViewId = target.getCurrentViewId(); 170 } 171 rsp.response = rtn; 172 return rsp; 173 } 174 catch (InstanceNotFoundException e) 175 { 176 throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, e); 177 } 178 catch (ReflectionException e) 179 { 180 throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, e); 181 } 182 catch (Exception e) 183 { 184 org.jboss.mx.util.JMXExceptionDecoder.rethrow(e); 185 186 throw new org.jboss.util.UnreachableStatementException(); 188 } 189 finally 190 { 191 Thread.currentThread().setContextClassLoader(oldCl); 192 } 193 } 194 } 195 | Popular Tags |