1 22 package org.jboss.management.j2ee.factory; 23 24 import org.jboss.deployment.DeploymentInfo; 25 import org.jboss.logging.Logger; 26 import org.jboss.management.j2ee.MBean; 27 import org.jboss.management.j2ee.ServiceModule; 28 29 import javax.management.MBeanServer ; 30 import javax.management.ObjectName ; 31 import java.util.List ; 32 import java.util.ListIterator ; 33 34 38 public class ServiceModuleFactory 39 implements ManagedObjectFactory 40 { 41 private static Logger log = Logger.getLogger(ServiceModuleFactory.class); 42 43 49 public ObjectName create(MBeanServer server, Object data) 50 { 51 if ((data instanceof DeploymentInfo) == false) 52 return null; 53 54 DeploymentInfo di = (DeploymentInfo) data; 55 String moduleName = di.shortName; 56 ObjectName sarName = ServiceModule.create(server, moduleName, di.localUrl); 57 if (sarName != null) 58 { 59 log.debug("Created ServiceModule: " + sarName); 60 } 61 62 try 63 { 64 List mbeans = di.mbeans; 65 for (int i = 0; i < mbeans.size(); i++) 66 { 67 ObjectName mbeanName = (ObjectName ) mbeans.get(i); 68 MBean.create(server, sarName.toString(), mbeanName); 70 log.debug("Create MBean, name: " + mbeanName + ", SAR Module: " + sarName); 71 } 72 } 73 catch (Throwable e) 74 { 75 log.debug("Failed to create MBean, sarName:" + sarName, e); 76 } 77 78 return sarName; 79 } 80 81 public void destroy(MBeanServer server, Object data) 82 { 83 if ((data instanceof DeploymentInfo) == false) 84 return; 85 86 DeploymentInfo di = (DeploymentInfo) data; 87 List services = di.mbeans; 88 int lastService = services.size(); 89 90 for (ListIterator i = services.listIterator(lastService); i.hasPrevious();) 91 { 92 ObjectName name = (ObjectName ) i.previous(); 93 try 94 { 95 MBean.destroy(server, name.toString()); 97 log.debug("Destroy MBean, name: " + name); 98 } 99 catch (Throwable e) 100 { 101 log.debug("Failed to remove remove JSR-77 MBean", e); 102 } } 104 105 String moduleName = di.shortName; 107 try 108 { 109 ServiceModule.destroy(server, moduleName); 110 log.debug("Removed JSR-77 SAR: " + moduleName); 111 } 112 catch (Throwable e) 113 { 114 log.debug("Failed to remove JSR-77 SAR: " + moduleName); 115 } 116 } 117 } 118 | Popular Tags |