1 22 package org.jboss.management.j2ee.factory; 23 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 import javax.management.MBeanServer ; 28 import javax.management.ObjectName ; 29 30 import org.jboss.deployment.DeploymentInfo; 31 import org.jboss.ejb.EjbModule; 32 import org.jboss.logging.Logger; 33 import org.jboss.management.j2ee.EJB; 34 import org.jboss.management.j2ee.EJBModule; 35 import org.jboss.metadata.BeanMetaData; 36 import org.jboss.metadata.SessionMetaData; 37 38 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 39 40 46 public class EJBModuleFactory 47 implements ManagedObjectFactory 48 { 49 private static Logger log = Logger.getLogger(EJBModuleFactory.class); 50 private static Map moduleServiceToMgmtMap = new ConcurrentReaderHashMap(); 51 private Map deploymentToModuleNameMap = new ConcurrentReaderHashMap(); 52 private Map containerToModuleNameMap = new ConcurrentReaderHashMap(); 53 54 static ObjectName getEJBModuleName(ObjectName ejbModuleService) 55 { 56 ObjectName jsr77Name = (ObjectName ) moduleServiceToMgmtMap.get(ejbModuleService); 57 return jsr77Name; 58 } 59 60 66 public ObjectName create(MBeanServer server, Object data) 67 { 68 if ((data instanceof DeploymentInfo) == false) 69 return null; 70 71 DeploymentInfo di = (DeploymentInfo) data; 72 String ejbJarName = di.shortName; 73 ObjectName ejbModuleService = di.deployedObject; 74 ObjectName jsr77Name = EJBModule.create(server, 75 (di.parent == null ? null : di.parent.shortName), 76 ejbJarName, 77 di.localUrl, 78 ejbModuleService); 79 moduleServiceToMgmtMap.put(ejbModuleService, jsr77Name); 80 deploymentToModuleNameMap.put(di, jsr77Name); 81 log.debug("Created module: " + jsr77Name); 82 Iterator ejbs = di.mbeans.iterator(); 83 while (ejbs.hasNext()) 84 { 85 ObjectName containerName = (ObjectName ) ejbs.next(); 86 createEJB(server, containerName); 87 } 88 return jsr77Name; 89 } 90 91 97 public void destroy(MBeanServer server, Object data) 98 { 99 if ((data instanceof DeploymentInfo) == false) 100 return; 101 102 DeploymentInfo di = (DeploymentInfo) data; 103 ObjectName jsr77Name = (ObjectName ) deploymentToModuleNameMap.remove(di); 104 105 log.debug("Destroy module: " + jsr77Name); 106 Iterator ejbs = di.mbeans.iterator(); 107 while (ejbs.hasNext()) 108 { 109 ObjectName containerName = (ObjectName ) ejbs.next(); 110 destroyEJB(server, containerName); 111 } 112 113 if (jsr77Name != null) 114 { 115 EJBModule.destroy(server, jsr77Name); 116 } 117 118 ObjectName ejbModuleService = di.deployedObject; 119 if (ejbModuleService != null) 120 containerToModuleNameMap.remove(ejbModuleService); 121 } 122 123 130 public ObjectName createEJB(MBeanServer server, ObjectName containerName) 131 { 132 ObjectName jsr77Name = null; 133 try 134 { 135 BeanMetaData metaData = (BeanMetaData) server.getAttribute(containerName, "BeanMetaData"); 136 EjbModule ejbModule = (EjbModule) server.getAttribute(containerName, "EjbModule"); 137 ObjectName ejbModName = EJBModuleFactory.getEJBModuleName(ejbModule.getServiceName()); 138 String ejbName = metaData.getEjbName(); 139 String jndiName = metaData.getJndiName(); 140 String localJndiName = metaData.getLocalJndiName(); 141 int type = EJB.STATELESS_SESSION_BEAN; 142 if (metaData.isSession()) 143 { 144 SessionMetaData smetaData = (SessionMetaData) metaData; 145 if (smetaData.isStateful()) 146 type = EJB.STATEFUL_SESSION_BEAN; 147 } 148 else if (metaData.isMessageDriven()) 149 type = EJB.MESSAGE_DRIVEN_BEAN; 150 else 151 type = EJB.ENTITY_BEAN; 152 153 154 jsr77Name = EJB.create(server, ejbModName, containerName, type, 155 ejbName, jndiName, localJndiName); 156 containerToModuleNameMap.put(containerName, jsr77Name); 157 log.debug("Create container: " + containerName + ", module: " + jsr77Name); 158 } 159 catch (Exception e) 160 { 161 log.debug("", e); 162 } 163 164 return jsr77Name; 165 } 166 167 173 public void destroyEJB(MBeanServer server, ObjectName containerName) 174 { 175 ObjectName jsr77Name = (ObjectName ) containerToModuleNameMap.get(containerName); 176 177 log.debug("Destroy container: " + containerName + ", module: " + jsr77Name); 178 if (jsr77Name != null) 179 { 180 EJB.destroy(server, jsr77Name); 181 } 182 } 183 184 } 185 | Popular Tags |