1 22 package org.jboss.resource.deployers; 23 24 import java.net.URL ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.Timer ; 28 29 import javax.management.Attribute ; 30 import javax.management.AttributeNotFoundException ; 31 import javax.management.InvalidAttributeValueException ; 32 import javax.management.MBeanAttributeInfo ; 33 import javax.management.MBeanException ; 34 import javax.management.MBeanOperationInfo ; 35 import javax.management.MBeanParameterInfo ; 36 import javax.management.ReflectionException ; 37 import javax.resource.spi.ActivationSpec ; 38 import javax.resource.spi.BootstrapContext ; 39 import javax.resource.spi.ResourceAdapter ; 40 import javax.resource.spi.UnavailableException ; 41 import javax.resource.spi.XATerminator ; 42 import javax.resource.spi.endpoint.MessageEndpointFactory ; 43 import javax.resource.spi.work.WorkManager ; 44 45 import org.jboss.deployment.DeploymentException; 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 61 public class RARDeployment extends ServiceDynamicMBeanSupport implements BootstrapContext 62 { 63 64 65 66 67 protected ConnectorMetaData cmd; 68 69 70 71 72 73 protected ResourceAdapter resourceAdapter; 74 75 76 private WorkManager workManager; 77 78 79 private XATerminator xaTerminator; 80 81 86 public RARDeployment(ConnectorMetaData cmd) 87 { 88 if (cmd == null) 89 throw new IllegalArgumentException ("Null metadata"); 90 this.cmd = cmd; 91 92 93 } 94 95 public Timer createTimer() throws UnavailableException 96 { 97 return new Timer (true); 98 } 99 100 105 public WorkManager getWorkManager() 106 { 107 return workManager; 108 } 109 110 115 public void setWorkManager(WorkManager workManager) 116 { 117 this.workManager = workManager; 118 } 119 120 125 public XATerminator getXATerminator() 126 { 127 return xaTerminator; 128 } 129 130 135 public void setXATerminator(XATerminator xaTerminator) 136 { 137 this.xaTerminator = xaTerminator; 138 } 139 140 protected void startService() throws Exception 141 { 142 URL url = cmd.getURL(); 143 144 if (cmd.getLicense().getRequired()) 145 { 146 log.info ("Required license terms exist, view " + ServerConfigUtil.shortUrlFromServerHome(url.toString())); 147 log.debug("License terms full URL: " + url); 148 } 149 resourceAdapter = ResourceAdapterFactory.createResourceAdapter(cmd); 150 resourceAdapter.start(this); 151 } 152 153 protected void stopService() throws Exception 154 { 155 resourceAdapter.stop(); 156 } 157 158 protected String getInternalDescription() 159 { 160 String description = null; 161 DescriptionGroupMetaData dgmd = cmd.getDescription(); 162 if (dgmd != null) 163 description = dgmd.getDescription(); 164 if (description == null) 165 description = "RAR Deployment " + cmd.getURL(); 166 return description; 167 } 168 169 protected MBeanAttributeInfo [] getInternalAttributeInfo() 170 { 171 Collection properties = cmd.getProperties(); 172 MBeanAttributeInfo [] attrs = new MBeanAttributeInfo [13+properties.size()]; 173 attrs[0] = new MBeanAttributeInfo ("MetaData", ConnectorMetaData.class.getName(), "The meta data", true, false, false); 174 attrs[1] = new MBeanAttributeInfo ("AuthenticationMechanism", String .class.getName(), "The authentication mechanism", true, false, false); 175 attrs[2] = new MBeanAttributeInfo ("EISType", String .class.getName(), "The EIS type", true, false, false); 176 attrs[3] = new MBeanAttributeInfo ("License", String .class.getName(), "The license", true, false, false); 177 attrs[4] = new MBeanAttributeInfo ("RAClass", String .class.getName(), "The resource adapter class", true, false, false); 178 attrs[5] = new MBeanAttributeInfo ("RAVersion", String .class.getName(), "The resource adapter version", true, false, false); 179 attrs[6] = new MBeanAttributeInfo ("TransactionSupport", String .class.getName(), "The transaction support", true, false, false); 180 attrs[7] = new MBeanAttributeInfo ("VendorName", String .class.getName(), "The vendor name", true, false, false); 181 attrs[8] = new MBeanAttributeInfo ("Version", String .class.getName(), "The spec version", true, false, false); 182 attrs[9] = new MBeanAttributeInfo ("ReauthenticationSupport", Boolean.TYPE.getName(), "Whether reauthentication support is supported", true, false, false); 183 attrs[10] = new MBeanAttributeInfo ("ResourceAdapter", ResourceAdapter .class.getName(), "The resource adapter instance", true, false, false); 184 attrs[11] = new MBeanAttributeInfo ("WorkManager", WorkManager .class.getName(), "The work manager", true, true, false); 185 attrs[12] = new MBeanAttributeInfo ("XATerminator", XATerminator .class.getName(), "The xa terminator", true, true, false); 186 int n = 13; 187 for (Iterator i = properties.iterator(); i.hasNext();) 188 { 189 ConfigPropertyMetaData cpmd = (ConfigPropertyMetaData) i.next(); 190 attrs[n++] = new MBeanAttributeInfo (cpmd.getName(), cpmd.getType(), cpmd.getDescription().getDescription(), true, false, false); 191 } 192 return attrs; 193 } 194 195 protected Object getInternalAttribute(String attribute) 196 throws AttributeNotFoundException , MBeanException , ReflectionException 197 { 198 if ("MetaData".equals(attribute)) 199 return cmd; 200 else if ("AuthenticationMechanism".equals(attribute)) 201 return cmd.getAuthenticationMechanism().getAuthenticationMechansimType(); 202 else if ("EISType".equals(attribute)) 203 return cmd.getEISType(); 204 else if ("License".equals(attribute)) 205 return cmd.getLicense().getDescription().getDescription(); 206 else if ("RAClass".equals(attribute)) 207 return cmd.getRAClass(); 208 else if ("RAVersion".equals(attribute)) 209 return cmd.getRAVersion(); 210 else if ("TransactionSupport".equals(attribute)) 211 return cmd.getTransactionSupport(); 212 else if ("VendorName".equals(attribute)) 213 return cmd.getVendorName(); 214 else if ("Version".equals(attribute)) 215 return cmd.getVersion(); 216 else if ("ReauthenticationSupport".equals(attribute)) 217 return new Boolean (cmd.getReauthenticationSupport()); 218 else if ("ResourceAdapter".equals(attribute)) 219 return resourceAdapter; 220 else if ("WorkManager".equals(attribute)) 221 return workManager; 222 else if ("XATerminator".equals(attribute)) 223 return xaTerminator; 224 Object property = cmd.getProperty(attribute); 225 if (property != null) 226 return property; 227 228 return super.getInternalAttribute(attribute); 229 } 230 231 protected void setInternalAttribute(Attribute attribute) throws AttributeNotFoundException , InvalidAttributeValueException , MBeanException , ReflectionException 232 { 233 String name = attribute.getName(); 234 if ("WorkManager".equals(name)) 235 this.workManager = (WorkManager ) attribute.getValue(); 236 else if ("XATerminator".equals(name)) 237 this.xaTerminator = (XATerminator ) attribute.getValue(); 238 else 239 super.setInternalAttribute(attribute); 240 } 241 242 protected MBeanOperationInfo [] getInternalOperationInfo() 243 { 244 MBeanOperationInfo [] ops = new MBeanOperationInfo [3]; 245 246 MBeanParameterInfo [] createActivationSpecParams = new MBeanParameterInfo [] 247 { 248 new MBeanParameterInfo ("MessagingType", Class .class.getName(), "The type of the message listener"), 249 new MBeanParameterInfo ("ActivationConfig", Collection .class.getName(), "A collection of activation config properties") 250 }; 251 ops[0] = new MBeanOperationInfo ("createActivationSpec", "Create an activation spec", 252 createActivationSpecParams, ActivationSpec .class.getName(), MBeanOperationInfo.ACTION); 253 254 MBeanParameterInfo [] activationParams = new MBeanParameterInfo [] 255 { 256 new MBeanParameterInfo ("MessageEndpointFactory", MessageEndpointFactory .class.getName(), "The message endpoint factory"), 257 new MBeanParameterInfo ("ActivationSpec", ActivationSpec .class.getName(), "The activation spec") 258 }; 259 ops[1] = new MBeanOperationInfo ("endpointActivation", "Active the endpoint", 260 activationParams, Void .class.getName(), MBeanOperationInfo.ACTION); 261 ops[2] = new MBeanOperationInfo ("endpointDeactivation", "Deactive the endpoint", 262 activationParams, Void .class.getName(), MBeanOperationInfo.ACTION); 263 264 return ops; 265 } 266 267 protected Object internalInvoke(String actionName, Object [] params, String [] signature) throws MBeanException , 268 ReflectionException 269 { 270 if ("createActivationSpec".equals(actionName)) 271 { 272 if (params.length != 2) 273 throw new IllegalArgumentException ("Wrong number of parameters for " + actionName); 274 Class messagingType = (Class ) params[0]; 275 Collection activationConfig = (Collection ) params[1]; 276 return createActivationSpec(messagingType, activationConfig); 277 } 278 else if ("endpointActivation".equals(actionName)) 279 { 280 if (params.length != 2) 281 throw new IllegalArgumentException ("Wrong number of parameters for " + actionName); 282 MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory ) params[0]; 283 ActivationSpec activationSpec = (ActivationSpec ) params[1]; 284 endpointActivation(messageEndpointFactory, activationSpec); 285 return null; 286 } 287 else if ("endpointDeactivation".equals(actionName)) 288 { 289 if (params.length != 2) 290 throw new IllegalArgumentException ("Wrong number of parameters for " + actionName); 291 MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory ) params[0]; 292 ActivationSpec activationSpec = (ActivationSpec ) params[1]; 293 endpointDeactivation(messageEndpointFactory, activationSpec); 294 return null; 295 } 296 return super.internalInvoke(actionName, params, signature); 297 } 298 299 protected ActivationSpec createActivationSpec(Class messagingType, Collection activationConfig) throws MBeanException 300 { 301 boolean trace = log.isTraceEnabled(); 302 if (trace) 303 log.trace("CreateActivateSpec rar=" + getServiceName() + " messagingType=" + messagingType.getName() + " activationConfig=" + activationConfig); 304 305 try 306 { 307 MessageListenerMetaData mlmd = cmd.getMessageListener(messagingType.getName()); 309 if (mlmd == null) 310 throw new DeploymentException("MessagingType '" + messagingType.getName() + "' not found in resource deployment " + getServiceName()); 311 312 return ActivationSpecFactory.createActivationSpec(getServiceName(), messagingType.getName(), activationConfig, mlmd); 313 } 314 catch (Exception e) 315 { 316 throw new MBeanException (e, "Error in create activation spec " + getServiceName()); 317 } 318 } 319 320 protected void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws MBeanException 321 { 322 boolean trace = log.isTraceEnabled(); 323 if (trace) 324 log.trace("EndpointActivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec); 325 326 try 327 { 328 activationSpec.setResourceAdapter(resourceAdapter); 329 resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec); 330 } 331 catch (Exception e) 332 { 333 throw new MBeanException (e, "Error in endpoint activation " + getServiceName()); 334 } 335 } 336 337 protected void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws MBeanException 338 { 339 boolean trace = log.isTraceEnabled(); 340 if (trace) 341 log.trace("EndpointDeactivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec); 342 343 try 344 { 345 resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec); 346 } 347 catch (Exception e) 348 { 349 throw new MBeanException (e, "Error in endpoint deactivation " + getServiceName()); 350 } 351 } 352 } 353 | Popular Tags |