1 23 24 package com.sun.enterprise.transaction.monitor; 25 26 import com.sun.enterprise.admin.monitor.registry.*; 27 import com.sun.enterprise.admin.monitor.stats.*; 28 import com.sun.enterprise.admin.monitor.stats.JTAStats; 29 import javax.management.j2ee.statistics.*; 30 31 import java.util.logging.Logger ; 32 import java.util.logging.Level ; 33 import java.util.Map ; 34 import java.util.List ; 35 import com.sun.logging.LogDomains; 36 37 38 public class JTAStatsImpl implements JTAStats, MonitoringLevelListener { 39 40 private JTSMonitorMBean mBean = null; 41 private GenericStatsImpl gStatsDelegate = null; 42 43 static Logger _logger = LogDomains.getLogger(LogDomains.JTA_LOGGER); 44 private static JTAStatsImpl instance = null; 45 46 private JTAStatsImpl(JTSMonitorMBean mBean) { 48 this.mBean = mBean; 49 try { 50 gStatsDelegate = new GenericStatsImpl("com.sun.enterprise.admin.monitor.stats.JTAStats",this); 51 } catch (ClassNotFoundException clex) { 52 _logger.log(Level.WARNING,"transaction.monitor.error_creating_jtastatsimpl",clex); 53 } 55 } 56 57 public static void createInstance(JTSMonitorMBean mBean) { 58 if (instance == null) 59 instance = new JTAStatsImpl(mBean); 60 } 61 public static JTAStatsImpl getInstance() { 62 if (instance == null) 63 throw new UnsupportedOperationException (); 64 return instance; 65 } 66 67 public void setLevel(MonitoringLevel level) { 69 if (level == MonitoringLevel.OFF) { 70 mBean.stopMonitoring(); 71 } 72 else if (level == MonitoringLevel.LOW || level == MonitoringLevel.HIGH) { 73 mBean.startMonitoring(); 74 } 75 } 76 77 public void changeLevel(MonitoringLevel from, MonitoringLevel to, 79 javax.management.j2ee.statistics.Stats handback) { 80 if (from != to) { 81 _logger.log(Level.FINE,"JTAStats Monitoring level changed from " + from + " to " + to); 82 if (to == MonitoringLevel.OFF) { 83 mBean.stopMonitoring(); 84 } 85 else if (to == MonitoringLevel.LOW || to == MonitoringLevel.HIGH) { 86 mBean.startMonitoring(); 87 } 88 } 89 } 90 91 public StringStatistic getActiveIds() { 92 String activeStr = null; 93 try { 94 activeStr = (String )mBean.getAttribute(JTSMonitorMBean.INFLIGHT_TRANSACTIONS); 95 }catch (javax.management.AttributeNotFoundException jmxex) { 96 _logger.log(Level.WARNING,"transaction.monitor.attribute_not_found",jmxex); 97 } 98 return new StringStatisticImpl(activeStr, 99 "ActiveIds", 100 "List", 102 "List of inflight transactions", 103 mBean.getStartTime(), 104 System.currentTimeMillis()); 105 } 106 107 public StringStatistic getState() { 108 String str = null; 109 try { 110 str = (String )mBean.getAttribute(JTSMonitorMBean.IS_FROZEN); 111 }catch (javax.management.AttributeNotFoundException jmxex) { 112 _logger.log(Level.WARNING,"transaction.monitor.attribute_not_found",jmxex); 113 } 115 116 return new StringStatisticImpl(str, 117 "State", 118 "String", 120 "Transaction system state: frozen?", 121 mBean.getStartTime(), 122 System.currentTimeMillis()); 123 } 124 125 public CountStatistic getActiveCount() { 126 Integer count = null; 127 try { 128 count = (Integer )mBean.getAttribute(JTSMonitorMBean.NUM_TRANSACTIONS_INFLIGHT); 129 }catch (javax.management.AttributeNotFoundException jmxex) { 130 _logger.log(Level.WARNING,"transaction.monitor.attribute_not_found",jmxex); 131 } 133 return new CountStatisticImpl(count.longValue(), 134 "ActiveCount", 135 CountStatisticImpl.DEFAULT_UNIT, 137 "number of active transactions", 138 System.currentTimeMillis(), 139 mBean.getStartTime()); 140 } 141 142 public CountStatistic getCommittedCount() { 143 Integer count = null; 144 try { 145 count = (Integer )mBean.getAttribute(JTSMonitorMBean.NUM_TRANSACTIONS_COMPLETED); 146 }catch (javax.management.AttributeNotFoundException jmxex) { 147 _logger.log(Level.WARNING,"transaction.monitor.attribute_not_found",jmxex); 148 } 150 return new CountStatisticImpl(count.longValue(), 151 "CommittedCount", 152 CountStatisticImpl.DEFAULT_UNIT, 154 "number of committed transactions", 155 System.currentTimeMillis(), 156 mBean.getStartTime()); 157 } 158 159 public CountStatistic getRolledbackCount() { 160 Integer count = null; 161 try { 162 count = (Integer )mBean.getAttribute(JTSMonitorMBean.NUM_TRANSACTIONS_ROLLEDBACK); 163 }catch (javax.management.AttributeNotFoundException jmxex) { 164 _logger.log(Level.WARNING,"transaction.monitor.attribute_not_found",jmxex); 165 } 167 return new CountStatisticImpl(count.longValue(), 168 "RolledbackCount", 169 CountStatisticImpl.DEFAULT_UNIT, 171 "number of rolled-back transactions", 172 System.currentTimeMillis(), 173 mBean.getStartTime()); 174 } 175 176 public void freeze() { 177 mBean.freeze(); 178 } 179 180 public void unfreeze() { 181 mBean.unfreeze(); 182 } 183 184 189 public String rollback(String txnId) { 190 String result = (String ) mBean.setRollback(txnId); 191 if (_logger.isLoggable(Level.FINE)) 192 _logger.log(Level.FINE, result); 193 return result; 194 } 195 196 197 202 203 204 public Statistic getStatistic(String statisticName) { 205 return gStatsDelegate.getStatistic(statisticName); 206 } 207 208 public String [] getStatisticNames() { 209 return gStatsDelegate.getStatisticNames(); 210 } 211 212 public Statistic[] getStatistics() { 213 return gStatsDelegate.getStatistics(); 214 } 215 216 public void changeLevel(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType type) { 217 if (from != to) { 218 _logger.log(Level.FINE,"JTAStats Monitoring level changed from " + from + " to " + to); 219 if (to == MonitoringLevel.OFF) { 220 mBean.stopMonitoring(); 221 } 222 else if (to == MonitoringLevel.LOW || to == MonitoringLevel.HIGH) { 223 mBean.startMonitoring(); 224 } 225 } 226 } 227 228 public List <Map <String , String >> listActiveTransactions() { 229 return mBean.listActiveTransactions(); 230 } 231 } 232 | Popular Tags |