1 23 24 package com.sun.enterprise.admin.monitor.stats.spi; 25 import java.util.ArrayList ; 26 import java.lang.management.ThreadInfo ; 27 import javax.management.ObjectName ; 28 import javax.management.MBeanServerFactory ; 29 import javax.management.MBeanServer ; 30 import javax.management.j2ee.statistics.Statistic ; 31 import javax.management.j2ee.statistics.CountStatistic ; 32 import com.sun.enterprise.admin.monitor.stats.JVMThreadInfoStats; 33 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 34 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 36 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 37 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.StatisticImpl; 40 import com.sun.enterprise.util.i18n.StringManager; 41 42 public class JVMThreadInfoStatsImpl implements JVMThreadInfoStats { 43 44 private GenericStatsImpl baseStatsImpl; 45 private static final String STATS_INTERFACE_NAME = 46 "com.sun.enterprise.admin.monitor.stats.JVMThreadInfoStats"; 47 private static final StringManager localStrMgr = 48 StringManager.getManager(JVMThreadStatsImpl.class); 49 50 private ThreadInfo info; 51 private long initTime; 52 MutableCountStatistic blockedCount; 53 MutableCountStatistic blockedTime; 54 MutableCountStatistic lockOwnerId; 55 MutableCountStatistic threadId; 56 MutableCountStatistic waitingCount; 57 MutableCountStatistic waitingTime; 58 static String NEWLINE = "\n"; 59 60 61 62 public JVMThreadInfoStatsImpl(ThreadInfo tInfo) { 63 try { 64 baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this); 65 } catch(Exception e) { 66 } 67 initTime = System.currentTimeMillis(); 68 info = tInfo; 69 initializeStatistics(); 71 } 72 73 public CountStatistic getBlockedCount() { 74 long blockCount = info.getBlockedCount(); 75 blockedCount.setCount(blockCount); 76 return (CountStatistic )blockedCount.unmodifiableView (); 77 } 78 79 public CountStatistic getBlockedTime() { 80 long blockTime = info.getBlockedTime(); 81 blockedTime.setCount(blockTime); 82 return (CountStatistic )blockedTime.unmodifiableView (); 83 } 84 85 public StringStatistic getLockName() { 86 87 String lockName = info.getLockName(); 88 if((lockName == null) || ("".equals(lockName))) 89 lockName = localStrMgr.getString("monitor.stats.no_lock"); 90 91 return new StringStatisticImpl(lockName, 92 localStrMgr.getString("monitor.stats.lock_name"), 93 localStrMgr.getString("monitor.stats.string_units"), 94 localStrMgr.getString("monitor.stats.lock_desc"), 95 initTime, 96 System.currentTimeMillis()); 97 98 } 99 100 public CountStatistic getLockOwnerId() { 101 long id = info.getLockOwnerId(); 102 lockOwnerId.setCount(id); 103 return (CountStatistic )lockOwnerId.unmodifiableView (); 104 } 105 106 public StringStatistic getLockOwnerName() { 107 String lockOwnerName = info.getLockOwnerName(); 108 if((lockOwnerName == null) || ( "".equals(lockOwnerName))) 109 lockOwnerName = localStrMgr.getString("monitor.stats.no_owner"); 110 111 return new StringStatisticImpl(lockOwnerName, 112 localStrMgr.getString("monitor.stats.lock_owner_name"), 113 localStrMgr.getString("monitor.stats.string_units"), 114 localStrMgr.getString("monitor.stats.lock_owner_desc"), 115 initTime, 116 System.currentTimeMillis()); 117 } 118 119 public StringStatistic getStackTrace() { 120 StackTraceElement [] trace = info.getStackTrace(); 121 String traceString = new String (); 122 if(trace != null) { 123 for(int i = 0; i < trace.length; i++) { 124 traceString = traceString.concat(trace[i].toString()); 125 traceString = traceString.concat(NEWLINE); 126 } 127 } 128 return new StringStatisticImpl(traceString, 129 localStrMgr.getString("monitor.stats.stack_trace_name"), 130 localStrMgr.getString("monitor.stats.string_units"), 131 localStrMgr.getString("monitor.stats.stack_trace_desc"), 132 initTime, 133 System.currentTimeMillis()); 134 135 136 } 137 138 public CountStatistic getThreadId() { 139 long id = info.getThreadId(); 140 threadId.setCount(id); 141 return (CountStatistic )threadId.unmodifiableView (); 142 } 143 144 public StringStatistic getThreadName() { 145 146 String name = info.getThreadName(); 147 148 return new StringStatisticImpl(name, 149 localStrMgr.getString("monitor.stats.thread_name"), 150 localStrMgr.getString("monitor.stats.string_units"), 151 localStrMgr.getString("monitor.stats.thread_name_desc"), 152 initTime, 153 System.currentTimeMillis()); 154 } 155 156 public StringStatistic getThreadState() { 157 158 return new StringStatisticImpl(info.getThreadState().toString(), 159 localStrMgr.getString("monitor.stats.thread_state"), 160 localStrMgr.getString("monitor.stats.string_units"), 161 localStrMgr.getString("monitor.stats.thread_state_desc"), 162 initTime, 163 System.currentTimeMillis()); 164 } 165 166 public CountStatistic getWaitedCount() { 167 long waitCount = info.getWaitedCount(); 168 waitingCount.setCount(waitCount); 169 return (CountStatistic )waitingCount.unmodifiableView (); 170 } 171 172 public CountStatistic getWaitedTime() { 173 long waitTime = info.getWaitedTime(); 174 waitingTime.setCount(waitTime); 175 return (CountStatistic )waitingTime.unmodifiableView (); 176 } 177 178 183 public Statistic [] getStatistics() { 184 return baseStatsImpl.getStatistics(); 185 } 186 187 191 public Statistic getStatistic(String str) { 192 return baseStatsImpl.getStatistic(str); 193 } 194 195 200 public String [] getStatisticNames() { 201 return baseStatsImpl.getStatisticNames(); 202 } 203 204 private void initializeStatistics() { 205 206 CountStatistic c = new CountStatisticImpl( 208 localStrMgr.getString("monitor.stats.blocked_time"), 209 localStrMgr.getString("monitor.stats.milli_sec_units"), 210 localStrMgr.getString("monitor.stats.blocked_time_desc")); 211 blockedTime = new MutableCountStatisticImpl(c); 212 213 c = new CountStatisticImpl( 215 localStrMgr.getString("monitor.stats.blocked_count"), 216 StatisticImpl.DEFAULT_UNIT, 217 localStrMgr.getString("monitor.stats.blocked_count_desc")); 218 blockedCount = new MutableCountStatisticImpl(c); 219 220 c = new CountStatisticImpl( 222 localStrMgr.getString("monitor.stats.lock_owner_id"), 223 StatisticImpl.DEFAULT_UNIT, 224 localStrMgr.getString("monitor.stats.lock_owner_id_desc")); 225 blockedCount = new MutableCountStatisticImpl(c); 226 lockOwnerId = new MutableCountStatisticImpl(c); 227 228 c = new CountStatisticImpl( 230 localStrMgr.getString("monitor.stats.thread_id"), 231 StatisticImpl.DEFAULT_UNIT, 232 localStrMgr.getString("monitor.stats.thread_id_desc")); 233 threadId = new MutableCountStatisticImpl(c); 234 235 c = new CountStatisticImpl( 237 localStrMgr.getString("monitor.stats.waiting_count"), 238 StatisticImpl.DEFAULT_UNIT, 239 localStrMgr.getString("monitor.stats.waiting_count_desc")); 240 waitingCount = new MutableCountStatisticImpl(c); 241 242 c = new CountStatisticImpl( 244 localStrMgr.getString("monitor.stats.waiting_time"), 245 localStrMgr.getString("monitor.stats.milli_sec_units"), 246 localStrMgr.getString("monitor.stats.waiting_time_desc")); 247 waitingTime = new MutableCountStatisticImpl(c); 248 } 249 } 250 | Popular Tags |