1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 26 import javax.management.MBeanServer ; 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 import java.net.URL ; 30 import java.security.InvalidParameterException ; 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 import java.util.Hashtable ; 34 import java.util.List ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 45 public class ResourceAdapterModule extends J2EEModule 46 implements ResourceAdapterModuleMBean 47 { 48 49 51 private static Logger log = Logger.getLogger(ResourceAdapterModule.class); 53 54 private List resourceAdapters = new ArrayList (); 56 57 60 private static final Map fakeJ2EEApps = new HashMap (); 61 62 64 73 public static ObjectName create(MBeanServer mbeanServer, String earName, 74 String rarName, URL pURL) 75 { 76 String lDD = null; 77 ObjectName lParent = null; 78 ObjectName lCreated = null; 79 ObjectName jsr77Name = null; 80 ObjectName j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer); 82 83 try 84 { 85 Hashtable props = j2eeServerName.getKeyPropertyList(); 86 String j2eeServer = props.get(J2EEManagedObject.TYPE) + "=" + 87 props.get("name"); 88 89 if (earName == null) 92 { 93 lParent = j2eeServerName; 95 } 96 else 97 { 98 ObjectName parentAppQuery = new ObjectName (J2EEDomain.getDomainName() + ":" + 99 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.J2EEApplication + "," + 100 "name=" + earName + "," + 101 j2eeServer + "," + 102 "*"); 103 Set parentApps = mbeanServer.queryNames(parentAppQuery, null); 104 105 if (parentApps.size() == 0) 106 { 107 lCreated = J2EEApplication.create(mbeanServer, 108 earName, 109 null); 110 lParent = lCreated; 111 } else if (parentApps.size() == 1) 113 { 114 lParent = (ObjectName ) parentApps.iterator().next(); 115 } } 117 118 lDD = J2EEDeployedObject.getDeploymentDescriptor(pURL, J2EEDeployedObject.RAR); 120 } 121 catch (Exception e) 122 { 123 log.debug("Could not create JSR-77 ResourceAdapterModule: " + rarName, e); 124 return null; 125 } 126 127 try 128 { 129 String [] jvms = (String []) mbeanServer.getAttribute(j2eeServerName, 131 "javaVMs"); 132 133 ResourceAdapterModule rarModule = new ResourceAdapterModule(rarName, 135 lParent, jvms, lDD); 136 jsr77Name = rarModule.getObjectName(); 137 mbeanServer.registerMBean(rarModule, jsr77Name); 138 139 if (lCreated != null) 140 { 141 fakeJ2EEApps.put(jsr77Name, lCreated); 142 } 143 log.debug("Created JSR-77 EJBModule: " + jsr77Name); 144 } 145 catch (Exception e) 146 { 147 log.debug("Could not create JSR-77 ResourceAdapterModule: " + rarName, e); 148 } 149 return jsr77Name; 150 } 151 152 158 public static void destroy(MBeanServer mbeanServer, ObjectName jsr77Name) 159 { 160 try 161 { 162 log.debug("destroy(), remove RARModule: " + jsr77Name); 163 mbeanServer.unregisterMBean(jsr77Name); 164 165 ObjectName jsr77ParentName = (ObjectName ) fakeJ2EEApps.get(jsr77Name); 166 if (jsr77ParentName != null) 167 { 168 log.debug("Remove fake JSR-77 parent Application: " + jsr77ParentName); 169 J2EEApplication.destroy(mbeanServer, jsr77ParentName); 170 } 171 } 172 catch (Exception e) 173 { 174 log.debug("Could not destroy JSR-77 RARModule: " + jsr77Name, e); 175 } 176 } 177 178 180 190 public ResourceAdapterModule(String rarName, ObjectName jsr77ParentName, 191 String [] pJVMs, String pDeploymentDescriptor) 192 throws MalformedObjectNameException , 193 InvalidParentException 194 { 195 super(J2EETypeConstants.ResourceAdapterModule, rarName, jsr77ParentName, pJVMs, pDeploymentDescriptor); 196 } 197 198 200 202 205 public String [] getresourceAdapters() 206 { 207 return (String []) resourceAdapters.toArray(new String [resourceAdapters.size()]); 208 } 209 210 213 public String getresourceAdapter(int pIndex) 214 { 215 if (pIndex >= 0 && pIndex < resourceAdapters.size()) 216 { 217 return (String ) resourceAdapters.get(pIndex); 218 } 219 else 220 { 221 return null; 222 } 223 } 224 225 227 public void addChild(ObjectName pChild) 228 { 229 String lType = J2EEManagedObject.getType(pChild); 230 if (J2EETypeConstants.ResourceAdapter.equals(lType)) 231 { 232 resourceAdapters.add(pChild.getCanonicalName()); 233 } 234 } 235 236 public void removeChild(ObjectName pChild) 237 { 238 String lType = J2EEManagedObject.getType(pChild); 239 if (J2EETypeConstants.ResourceAdapter.equals(lType)) 240 { 241 resourceAdapters.remove(pChild.getCanonicalName()); 242 } 243 } 244 245 247 public String toString() 248 { 249 return "ResourceAdapterModule[ " + super.toString() + 250 "ResourceAdapters: " + resourceAdapters + 251 " ]"; 252 } 253 254 256 258 262 protected Hashtable getParentKeys(ObjectName jsr77ParentName) 263 { 264 Hashtable parentKeys = new Hashtable (); 265 Hashtable parentProps = jsr77ParentName.getKeyPropertyList(); 266 String parentName = (String ) parentProps.get("name"); 267 String j2eeType = (String ) parentProps.get(J2EEManagedObject.TYPE); 268 269 if (j2eeType.equals(J2EETypeConstants.J2EEApplication) == false) 271 { 272 parentKeys.put(J2EETypeConstants.J2EEServer, parentName); 274 parentKeys.put(J2EETypeConstants.J2EEApplication, "null"); 275 } 276 else 277 { 278 parentKeys.put(J2EETypeConstants.J2EEApplication, parentName); 280 String j2eeServerName = (String ) parentProps.get(J2EETypeConstants.J2EEServer); 281 parentKeys.put(J2EETypeConstants.J2EEServer, j2eeServerName); 282 } 283 284 return parentKeys; 285 } 286 287 289 } 291 | Popular Tags |