1 23 24 28 29 34 35 package com.sun.enterprise.admin.monitor.util; 36 import javax.management.j2ee.statistics.*; 37 import java.lang.reflect.*; 38 import java.util.logging.*; 39 46 public class S1ASJVMStatsImplMock implements S1ASJVMStatsMock { 47 private long initTime; 48 public static final String LOGGER_NAME="this.is.console"; 49 final Logger logger; 50 51 52 public S1ASJVMStatsImplMock() { 53 initTime = System.currentTimeMillis(); 54 logger = Logger.getLogger(LOGGER_NAME); 55 } 56 57 public javax.management.j2ee.statistics.Statistic getStatistic(String statisticName) { 58 if(statisticName != null){ 59 try{ 60 return (Statistic)(this.getClass().getMethod("get"+statisticName, null)).invoke(this,null); 61 } 62 catch(Exception e){ 63 e.printStackTrace(); 64 } 65 } 66 throw new NullPointerException ("Cannot find Statistic as Statistic Name is not provided"); 67 } 68 69 70 public String [] getStatisticNames() { 71 return new String []{"HeapSize","MaxMemory","UpTime", "AvailableProcessors"}; 72 } 73 74 public javax.management.j2ee.statistics.Statistic [] getStatistics() { 75 Statistic[] stats = new Statistic[]{}; 76 for(int i=0;i<getStatisticNames().length;i++){ 77 stats[i]=getStatistic(getStatisticNames()[i]); 78 } 79 return stats; 80 } 81 82 public CountStatistic getAvailableProcessors(){ 83 int availProcs = Runtime.getRuntime().availableProcessors(); 84 return StatisticFactory.getCountStatistic(availProcs, "AvailableProcessors", 85 "Numbers", "Processors Available to the JVM", 86 System.currentTimeMillis(), initTime); 87 } 88 89 public javax.management.j2ee.statistics.BoundedRangeStatistic getHeapSize() { 90 long heapSize = Runtime.getRuntime().totalMemory(); 91 long upper = Runtime.getRuntime().maxMemory(); 92 return StatisticFactory.getBoundedRangeStatistic(heapSize, heapSize, heapSize, 93 upper, 0, "HeapSize", "bytes", 94 "JVM Heap Size", initTime, 95 System.currentTimeMillis()); 96 } 97 98 public CountStatistic getMaxMemory() { 99 long maxMem = Runtime.getRuntime().maxMemory(); 100 return StatisticFactory.getCountStatistic(maxMem, "MaxMemory", 101 "bytes", "Memory Available to the JVM", 102 System.currentTimeMillis(), initTime); 103 } 104 105 public CountStatistic getUpTime() { 106 long curTime = System.currentTimeMillis(); 107 long upTime = curTime - initTime; 108 return StatisticFactory.getCountStatistic(upTime, "UpTime", "milliseconds", 109 "Amount of time the JVM has been running", 110 curTime, initTime); 111 } 112 } 113 | Popular Tags |