FileDocCategorySizeDatePackage
S1ASJVMStatsImplMock.javaAPI DocGlassfish v2 API5614Fri May 04 22:25:54 BST 2007com.sun.enterprise.admin.monitor.registry.spi

S1ASJVMStatsImplMock

public class S1ASJVMStatsImplMock extends Object implements S1ASJVMStatsMock
Mock class for using JVMStats as a component that will register and unregister with a MonitoringRegistration object which in turn created a dynamic MBean that will be registered with the MBeanServer using an ObjectName that has a unique identifier.
author
sg112326

Fields Summary
private long
initTime
public static final String
LOGGER_NAME
final Logger
logger
Constructors Summary
public S1ASJVMStatsImplMock()
Creates a new instance of JVMStatsImpl

 

           
      
        initTime = System.currentTimeMillis();
        logger = Logger.getLogger(LOGGER_NAME);
    
Methods Summary
public CountStatisticgetAvailableProcessors()

        int availProcs = Runtime.getRuntime().availableProcessors();
        return StatisticFactory.getCountStatistic(availProcs, "AvailableProcessors", 
                                                   "Numbers", "Processors Available to the JVM",
                                                   System.currentTimeMillis(), initTime);
    
public javax.management.j2ee.statistics.BoundedRangeStatisticgetHeapSize()

        long heapSize = Runtime.getRuntime().totalMemory();
        long upper = Runtime.getRuntime().maxMemory();
        return StatisticFactory.getBoundedRangeStatistic(heapSize, heapSize, heapSize, 
                                                         upper, 0, "HeapSize", "bytes", 
                                                         "JVM Heap Size", initTime, 
                                                         System.currentTimeMillis());
    
public CountStatisticgetMaxMemory()

        long maxMem = Runtime.getRuntime().maxMemory();
        return StatisticFactory.getCountStatistic(maxMem, "MaxMemory", 
                                                   "bytes", "Memory Available to the JVM",
                                                   System.currentTimeMillis(), initTime);
    
public javax.management.j2ee.statistics.StatisticgetStatistic(java.lang.String statisticName)

        if(statisticName != null){
            try{
                return (Statistic)(this.getClass().getMethod("get"+statisticName, null)).invoke(this,null);
            }
            catch(Exception e){
               e.printStackTrace();
            }
        }        
        throw new NullPointerException("Cannot find Statistic as Statistic Name is not provided");
    
public java.lang.String[]getStatisticNames()

        return new String[]{"HeapSize","MaxMemory","UpTime", "AvailableProcessors"};
    
public javax.management.j2ee.statistics.Statistic[]getStatistics()

        Statistic[] stats = new Statistic[]{};
        for(int i=0;i<getStatisticNames().length;i++){
            stats[i]=getStatistic(getStatisticNames()[i]);
        }
        return stats;
    
public CountStatisticgetUpTime()

        long curTime = System.currentTimeMillis();
        long upTime = curTime - initTime;
        return StatisticFactory.getCountStatistic(upTime, "UpTime", "milliseconds", 
                                                  "Amount of time the JVM has been running", 
                                                   curTime, initTime);