FileDocCategorySizeDatePackage
MutableTimeStatisticImpl.javaAPI DocGlassfish v2 API6188Fri May 04 22:25:48 BST 2007com.sun.enterprise.admin.monitor.stats

MutableTimeStatisticImpl

public class MutableTimeStatisticImpl extends Object implements MutableTimeStatistic, javax.management.j2ee.statistics.TimeStatistic
An implementation of {@link MutableTimeStatistic} that eases the various statistical calculations.
author
Kedar Mhaswade
since
S1AS8.0
version
$Revision: 1.3 $

Fields Summary
private final javax.management.j2ee.statistics.TimeStatistic
initial
private long
methodCount
private long
min
private long
max
private long
total
private long
lastSampleTime
Constructors Summary
public MutableTimeStatisticImpl(javax.management.j2ee.statistics.TimeStatistic initial)
Constructs an instance of this class from its immutable equivalent. Note that there are some constraints on the parameter passed:
  • The maxTime, minTime and totTime of param must be same

param
instance of (immutable) {@link TimeStatistic}

		this.initial        = initial;
		methodCount         = initial.getCount();
		min    = initial.getMinTime();
		max    = initial.getMaxTime();
		total  = initial.getTotalTime();
		final boolean minMax = min == max;
		final boolean minTot = min == total;
		if (! (minMax && minTot))
			throw new IllegalArgumentException("Invalid initial values: " + min + ", " + max + ", " + total);
		lastSampleTime = initial.getLastSampleTime();
	
Methods Summary
public longgetCount()

		return ( this.methodCount);
	
public java.lang.StringgetDescription()

		return ( initial.getDescription() );
	
public longgetLastSampleTime()

		return ( this.lastSampleTime );
	
public longgetMaxTime()

		return ( this.max );
	
public longgetMinTime()

		return ( this.min );
	
public java.lang.StringgetName()

		return ( initial.getName() );
	
public longgetStartTime()

		return ( initial.getStartTime() );
	
public longgetTotalTime()

		return ( this.total );
	
public java.lang.StringgetUnit()

		return ( initial.getUnit() );
	
public voidincrementCount(long current)
Increments the count of operation execution by 1 and also increases the time consumed. A successful execution of method will have all the data updated as:
  • method count ++
  • max time, min time and total time are accordingly adjusted

param
current long indicating time in whatever unit this statistic is calculated

        if (methodCount == 0) {
            total = max = min = current;
        } else {
            total += current;
            max = current >= max ? current : max;
            min = current >= min ? min : current;
        }
		methodCount++;
		lastSampleTime = System.currentTimeMillis();
	
public javax.management.j2ee.statistics.StatisticmodifiableView()

		return ( this );
	
public voidreset()
Resets the Statistic. Calling this method has following effect:
  • Initial state of this Statistic is restored as far as Count, Minimum/Maximum and Total time of execution is considered.

		methodCount         = initial.getCount();
		min                 = initial.getMinTime();
		max                 = initial.getMaxTime();
		total               = initial.getTotalTime();
		lastSampleTime	    = initial.getLastSampleTime();
	
public voidsetDescription(java.lang.String s)

        try {
            ((StatisticImpl)this.initial).setDescription(s);
        }
        catch(final Exception e) {
        }
    
public javax.management.j2ee.statistics.StatisticunmodifiableView()
This method is the essence of this class. Returns the unmodifiable view of this instance.

return
an instance of {@link TimeStatistic}

		return ( new TimeStatisticImpl(
		this.methodCount,
		this.max,
		this.min,
		this.total,
		initial.getName(),
		initial.getUnit(),
		initial.getDescription(),
		initial.getStartTime(),
		this.lastSampleTime )
		);