1 22 package org.jboss.ejb3.embedded.resource; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.Timer ; 27 28 import javax.management.AttributeNotFoundException ; 29 import javax.management.MBeanAttributeInfo ; 30 import javax.management.MBeanException ; 31 import javax.management.MBeanOperationInfo ; 32 import javax.management.MBeanParameterInfo ; 33 import javax.management.ObjectName ; 34 import javax.management.ReflectionException ; 35 import javax.resource.spi.ActivationSpec ; 36 import javax.resource.spi.BootstrapContext ; 37 import javax.resource.spi.ResourceAdapter ; 38 import javax.resource.spi.UnavailableException ; 39 import javax.resource.spi.XATerminator ; 40 import javax.resource.spi.endpoint.MessageEndpointFactory ; 41 import javax.resource.spi.work.WorkManager ; 42 43 import org.jboss.deployment.DeploymentException; 44 import org.jboss.deployment.DeploymentInfo; 45 import org.jboss.logging.Logger; 46 import org.jboss.resource.deployment.ActivationSpecFactory; 47 import org.jboss.resource.deployment.ResourceAdapterFactory; 48 import org.jboss.resource.metadata.ConfigPropertyMetaData; 49 import org.jboss.resource.metadata.ConnectorMetaData; 50 import org.jboss.resource.metadata.DescriptionGroupMetaData; 51 import org.jboss.resource.metadata.MessageListenerMetaData; 52 import org.jboss.system.ServiceDynamicMBeanSupport; 53 import org.jboss.system.server.ServerConfigUtil; 54 55 59 public class RARDeployment implements BootstrapContext 60 { 61 private static final Logger log = Logger.getLogger(RARDeployment.class); 62 63 64 protected DeploymentInfo di; 65 66 67 protected WorkManager workManager; 68 69 70 protected XATerminator xaTerminator; 71 72 73 protected ConnectorMetaData cmd; 74 75 76 protected ResourceAdapter resourceAdapter; 77 78 protected ObjectName serviceName; 79 80 85 public RARDeployment(DeploymentInfo di) throws Exception 86 { 87 this.di = di; 88 this.cmd = (ConnectorMetaData) di.metaData; 89 90 resourceAdapter = ResourceAdapterFactory.createResourceAdapter(cmd); 91 resourceAdapter.start(this); 92 } 93 94 96 public ObjectName getServiceName() 97 { 98 return serviceName; 99 } 100 101 public void setServiceName(ObjectName serviceName) 102 { 103 this.serviceName = serviceName; 104 } 105 106 public Timer createTimer() throws UnavailableException 107 { 108 return new Timer (true); 109 } 110 111 public WorkManager getWorkManager() 112 { 113 return workManager; 114 } 115 116 public void setWorkManager(WorkManager workManager) 117 { 118 this.workManager = workManager; 119 } 120 121 public XATerminator getXATerminator() 122 { 123 return xaTerminator; 124 } 125 126 public void setXATerminator(XATerminator xaTerminator) 127 { 128 this.xaTerminator = xaTerminator; 129 } 130 131 protected String getInternalDescription() 132 { 133 String description = null; 134 DescriptionGroupMetaData dgmd = cmd.getDescription(); 135 if (dgmd != null) 136 description = dgmd.getDescription(); 137 if (description == null) 138 description = "RAR Deployment " + di.url; 139 return description; 140 } 141 142 protected MBeanAttributeInfo [] getInternalAttributeInfo() 143 { 144 Collection properties = cmd.getProperties(); 145 MBeanAttributeInfo [] attrs = new MBeanAttributeInfo [11+properties.size()]; 146 attrs[0] = new MBeanAttributeInfo ("MetaData", ConnectorMetaData.class.getName(), "The meta data", true, false, false); 147 attrs[1] = new MBeanAttributeInfo ("AuthenticationMechanism", String .class.getName(), "The authentication mechanism", true, false, false); 148 attrs[2] = new MBeanAttributeInfo ("EISType", String .class.getName(), "The EIS type", true, false, false); 149 attrs[3] = new MBeanAttributeInfo ("License", String .class.getName(), "The license", true, false, false); 150 attrs[4] = new MBeanAttributeInfo ("RAClass", String .class.getName(), "The resource adapter class", true, false, false); 151 attrs[5] = new MBeanAttributeInfo ("RAVersion", String .class.getName(), "The resource adapter version", true, false, false); 152 attrs[6] = new MBeanAttributeInfo ("TransactionSupport", String .class.getName(), "The transaction support", true, false, false); 153 attrs[7] = new MBeanAttributeInfo ("VendorName", String .class.getName(), "The vendor name", true, false, false); 154 attrs[8] = new MBeanAttributeInfo ("Version", String .class.getName(), "The spec version", true, false, false); 155 attrs[9] = new MBeanAttributeInfo ("ReauthenticationSupport", Boolean.TYPE.getName(), "Whether reauthentication support is supported", true, false, false); 156 attrs[10] = new MBeanAttributeInfo ("ResourceAdapter", ResourceAdapter .class.getName(), "The resource adapter instance", true, false, false); 157 int n = 11; 158 for (Iterator i = properties.iterator(); i.hasNext();) 159 { 160 ConfigPropertyMetaData cpmd = (ConfigPropertyMetaData) i.next(); 161 attrs[n++] = new MBeanAttributeInfo (cpmd.getName(), cpmd.getType(), cpmd.getDescription().getDescription(), true, false, false); 162 } 163 return attrs; 164 } 165 166 protected Object getInternalAttribute(String attribute) 167 throws AttributeNotFoundException , MBeanException , ReflectionException 168 { 169 if ("MetaData".equals(attribute)) 170 return cmd; 171 else if ("AuthenticationMechanism".equals(attribute)) 172 return cmd.getAuthenticationMechanism().getAuthenticationMechansimType(); 173 else if ("EISType".equals(attribute)) 174 return cmd.getEISType(); 175 else if ("License".equals(attribute)) 176 return cmd.getLicense().getDescription().getDescription(); 177 else if ("RAClass".equals(attribute)) 178 return cmd.getRAClass(); 179 else if ("RAVersion".equals(attribute)) 180 return cmd.getRAVersion(); 181 else if ("TransactionSupport".equals(attribute)) 182 return cmd.getTransactionSupport(); 183 else if ("VendorName".equals(attribute)) 184 return cmd.getVendorName(); 185 else if ("Version".equals(attribute)) 186 return cmd.getVersion(); 187 else if ("ReauthenticationSupport".equals(attribute)) 188 return new Boolean (cmd.getReauthenticationSupport()); 189 else if ("ResourceAdapter".equals(attribute)) 190 return resourceAdapter; 191 Object property = cmd.getProperty(attribute); 192 if (property != null) 193 return property; 194 195 return null; 196 } 197 198 protected MBeanOperationInfo [] getInternalOperationInfo() 199 { 200 MBeanOperationInfo [] ops = new MBeanOperationInfo [3]; 201 202 MBeanParameterInfo [] createActivationSpecParams = new MBeanParameterInfo [] 203 { 204 new MBeanParameterInfo ("MessagingType", Class .class.getName(), "The type of the message listener"), 205 new MBeanParameterInfo ("ActivationConfig", Collection .class.getName(), "A collection of activation config properties") 206 }; 207 ops[0] = new MBeanOperationInfo ("createActivationSpec", "Create an activation spec", 208 createActivationSpecParams, ActivationSpec .class.getName(), MBeanOperationInfo.ACTION); 209 210 MBeanParameterInfo [] activationParams = new MBeanParameterInfo [] 211 { 212 new MBeanParameterInfo ("MessageEndpointFactory", MessageEndpointFactory .class.getName(), "The message endpoint factory"), 213 new MBeanParameterInfo ("ActivationSpec", ActivationSpec .class.getName(), "The activation spec") 214 }; 215 ops[1] = new MBeanOperationInfo ("endpointActivation", "Active the endpoint", 216 activationParams, Void .class.getName(), MBeanOperationInfo.ACTION); 217 ops[2] = new MBeanOperationInfo ("endpointDeactivation", "Deactive the endpoint", 218 activationParams, Void .class.getName(), MBeanOperationInfo.ACTION); 219 220 return ops; 221 } 222 223 public Object invoke(String actionName, Object [] params, String [] signature) throws MBeanException , 224 ReflectionException 225 { 226 Object result = null; 227 if ("createActivationSpec".equals(actionName)) 228 { 229 if (params.length != 2) 230 throw new IllegalArgumentException ("Wrong number of parameters for " + actionName); 231 Class messagingType = (Class ) params[0]; 232 Collection activationConfig = (Collection ) params[1]; 233 result = createActivationSpec(messagingType, activationConfig); 234 } 235 else if ("endpointActivation".equals(actionName)) 236 { 237 if (params.length != 2) 238 throw new IllegalArgumentException ("Wrong number of parameters for " + actionName); 239 MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory ) params[0]; 240 ActivationSpec activationSpec = (ActivationSpec ) params[1]; 241 endpointActivation(messageEndpointFactory, activationSpec); 242 } 243 else if ("endpointDeactivation".equals(actionName)) 244 { 245 if (params.length != 2) 246 throw new IllegalArgumentException ("Wrong number of parameters for " + actionName); 247 MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory ) params[0]; 248 ActivationSpec activationSpec = (ActivationSpec ) params[1]; 249 endpointDeactivation(messageEndpointFactory, activationSpec); 250 } 251 252 return result; 253 } 254 255 protected ActivationSpec createActivationSpec(Class messagingType, Collection activationConfig) throws MBeanException 256 { 257 boolean trace = log.isTraceEnabled(); 258 if (trace) 259 log.trace("CreateActivateSpec rar=" + getServiceName() + " messagingType=" + messagingType.getName() + " activationConfig=" + activationConfig); 260 261 try 262 { 263 MessageListenerMetaData mlmd = cmd.getMessageListener(messagingType.getName()); 265 if (mlmd == null) 266 throw new DeploymentException("MessagingType '" + messagingType.getName() + "' not found in resource deployment " + getServiceName()); 267 268 return ActivationSpecFactory.createActivationSpec(getServiceName(), messagingType.getName(), activationConfig, mlmd); 269 } 270 catch (Exception e) 271 { 272 throw new MBeanException (e, "Error in create activation spec " + getServiceName()); 273 } 274 } 275 276 protected void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws MBeanException 277 { 278 boolean trace = log.isTraceEnabled(); 279 if (trace) 280 log.trace("EndpointActivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec); 281 282 try 283 { 284 activationSpec.setResourceAdapter(resourceAdapter); 285 resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec); 286 } 287 catch (Exception e) 288 { 289 throw new MBeanException (e, "Error in endpoint activation " + getServiceName()); 290 } 291 } 292 293 protected void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws MBeanException 294 { 295 boolean trace = log.isTraceEnabled(); 296 if (trace) 297 log.trace("EndpointDeactivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec); 298 299 try 300 { 301 resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec); 302 } 303 catch (Exception e) 304 { 305 throw new MBeanException (e, "Error in endpoint deactivation " + getServiceName()); 306 } 307 } 308 } 309 | Popular Tags |