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