1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.management.j2ee.statistics.CountStatisticImpl; 26 import org.jboss.management.j2ee.statistics.JTAStatsImpl; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MalformedObjectNameException ; 30 import javax.management.ObjectName ; 31 import javax.management.j2ee.statistics.Stats ; 32 33 41 public class JTAResource extends J2EEResource 42 implements JTAResourceMBean 43 { 44 private static Logger log = Logger.getLogger(JTAResource.class); 46 47 49 private ObjectName jtaServiceName; 50 private JTAStatsImpl stats; 51 52 54 public static ObjectName create(MBeanServer mbeanServer, String resName, 55 ObjectName jtaServiceName) 56 { 57 ObjectName j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer); 58 ObjectName jsr77Name = null; 59 try 60 { 61 JTAResource jtaRes = new JTAResource(resName, j2eeServerName, jtaServiceName); 62 jsr77Name = jtaRes.getObjectName(); 63 mbeanServer.registerMBean(jtaRes, jsr77Name); 64 log.debug("Created JSR-77 JTAResource: " + resName); 65 } 66 catch (Exception e) 67 { 68 log.debug("Could not create JSR-77 JTAResource: " + resName, e); 69 } 70 return jsr77Name; 71 } 72 73 public static void destroy(MBeanServer mbeanServer, String resName) 74 { 75 try 76 { 77 J2EEManagedObject.removeObject(mbeanServer, 78 J2EEDomain.getDomainName() + ":" + 79 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.JTAResource + "," + 80 "name=" + resName + "," + 81 "*"); 82 } 83 catch (Exception e) 84 { 85 log.error("Could not destroy JSR-77 JTAResource: " + resName, e); 86 } 87 } 88 89 91 95 public JTAResource(String resName, ObjectName j2eeServerName, ObjectName jtaServiceName) 96 throws 97 MalformedObjectNameException , 98 InvalidParentException 99 { 100 super(J2EETypeConstants.JTAResource, resName, j2eeServerName); 101 if (log.isDebugEnabled()) 102 log.debug("Service name: " + jtaServiceName); 103 this.jtaServiceName = jtaServiceName; 104 stats = new JTAStatsImpl(); 105 } 106 107 109 115 public Stats getstats() 116 { 117 try 118 { 119 CountStatisticImpl readyCount = (CountStatisticImpl) stats.getActiveCount(); 120 Long count = (Long ) server.getAttribute(jtaServiceName, "TransactionCount"); 121 readyCount.set(count.longValue()); 122 CountStatisticImpl commitCount = (CountStatisticImpl) stats.getCommittedCount(); 123 count = (Long ) server.getAttribute(jtaServiceName, "CommitCount"); 124 commitCount.set(count.longValue()); 125 CountStatisticImpl rollbackCount = (CountStatisticImpl) stats.getRolledbackCount(); 126 count = (Long ) server.getAttribute(jtaServiceName, "RollbackCount"); 127 rollbackCount.set(count.longValue()); 128 } 129 catch (Exception e) 130 { 131 log.debug("Failed to retrieve stats", e); 132 } 133 return stats; 134 } 135 136 public void resetStats() 137 { 138 stats.reset(); 139 } 140 141 143 145 public String [] getEventTypes() 146 { 147 return StateManagement.stateTypes; 148 } 149 150 public String getEventType(int pIndex) 151 { 152 if (pIndex >= 0 && pIndex < StateManagement.stateTypes.length) 153 { 154 return StateManagement.stateTypes[pIndex]; 155 } 156 else 157 { 158 return null; 159 } 160 } 161 162 164 public String toString() 165 { 166 return "JTAResource { " + super.toString() + " } [ " + 167 " ]"; 168 } 169 170 } 171 | Popular Tags |