1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.management.j2ee.statistics.JMSStatsImpl; 26 27 import javax.management.MBeanServer ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.ObjectName ; 30 import javax.management.j2ee.statistics.Stats ; 31 import java.util.Iterator ; 32 import java.util.Map ; 33 34 41 public class JMSResource extends J2EEResource 42 implements JMSResourceMBean 43 { 44 private static Logger log = Logger.getLogger(JMSResource.class); 46 47 49 private ObjectName jmsServiceName; 50 private JMSStatsImpl stats; 51 52 54 public static ObjectName create(MBeanServer mbeanServer, String resName, 55 ObjectName jmsServiceName) 56 { 57 ObjectName j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer); 58 ObjectName jsr77Name = null; 59 try 60 { 61 JMSResource jmsRes = new JMSResource(resName, j2eeServerName, jmsServiceName); 62 jsr77Name = jmsRes.getObjectName(); 63 mbeanServer.registerMBean(jmsRes, jsr77Name); 64 log.debug("Created JSR-77 JMSResource: " + resName); 65 } 66 catch (Exception e) 67 { 68 log.debug("Could not create JSR-77 JMSResource: " + resName, e); 69 } 70 return jsr77Name; 71 } 72 73 public static void destroy(MBeanServer pServer, String pName) 74 { 75 try 76 { 77 J2EEManagedObject.removeObject(pServer, 78 J2EEDomain.getDomainName() + ":" + 79 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.JMSResource + "," + 80 "name=" + pName + "," + 81 "*"); 82 } 83 catch (Exception e) 84 { 85 log.error("Could not destroy JSR-77 JMSResource Resource", e); 86 } 87 } 88 89 93 97 public JMSResource(String resName, ObjectName j2eeServerName, 98 ObjectName jmsServiceName) 99 throws MalformedObjectNameException , 100 InvalidParentException 101 { 102 super(J2EETypeConstants.JMSResource, resName, j2eeServerName); 103 this.jmsServiceName = jmsServiceName; 104 stats = new JMSStatsImpl(null); 105 } 106 107 109 115 public Stats getstats() 116 { 117 try 118 { 119 Map clients = (Map ) server.getAttribute(jmsServiceName, "Clients"); 121 Iterator iter = clients.keySet().iterator(); 122 } 123 catch (Exception e) 124 { 125 log.debug("Failed to obtain stats", e); 126 } 127 return stats; 128 } 129 130 135 public void resetStats() 136 { 137 stats.reset(); 138 } 139 141 142 144 public String toString() 145 { 146 return "JMSResource { " + super.toString() + " } []"; 147 } 148 } 149 | Popular Tags |