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

MutableCountStatisticImpl

public class MutableCountStatisticImpl extends Object implements MutableCountStatistic, javax.management.j2ee.statistics.CountStatistic
An implementation of MutableCountStatistic that provides ways to change the state externally through mutators. Convenience class that is useful for components that gather the statistical data.
author
Kedar Mhaswade
see
CountStatisticImpl for an immutable implementation
since
S1AS8.0
version
1.0

Fields Summary
private final javax.management.j2ee.statistics.CountStatistic
initial
private long
count
private long
lastSampleTime
private long
startTime
Constructors Summary
public MutableCountStatisticImpl(javax.management.j2ee.statistics.CountStatistic initial)
Constructs an instance of MutableCountStatistic that encapsulates the given Statistic. The only parameter denotes the initial state of this statistic. It is guaranteed that the initial state is preserved internally, so that one can reset to the initial state.

param
initial an instance of CountStatistic that represents initial state

        this.initial        = initial;
        this.count          = initial.getCount();
        this.lastSampleTime = initial.getLastSampleTime();
        this.startTime      = lastSampleTime;
    
Methods Summary
public longgetCount()

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

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

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

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

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

	return ( initial.getUnit());
    
public javax.management.j2ee.statistics.StatisticmodifiableView()

	return ( this );
    
public voidreset()
Resets to the initial state. It is guaranteed that following changes occur to the statistic if this method is called:
  • The current value is reset to its initial value.
  • The lastSampleTime is reset to current time in milliseconds.
  • The startTime is reset to lastSampleTime.
The remaining meta data in the statistic is unchanged.

        this.count          = initial.getCount();
        this.lastSampleTime = System.currentTimeMillis();
        this.startTime      = this.lastSampleTime;
    
public voidsetCount(long count)
Changes the value of the encapsulated CountStatistic to the given value. Since this is the only mutator exposed here, here are the other side effects of calling this method:
  • lastSampleTime is set to current time in milliseconds.
In a real-time system with actual probes for measurement, the lastSampleTime could be different from the instant when this method is called, but that is deemed insignificant.

param
count long that represents the current value of the Statistic.

        this.count = count;
        this.lastSampleTime = System.currentTimeMillis();
    
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. It provides the read-only view of encapsulated Statistic. If the clients have to know the Statistic, this is what should be called by actual data collecting component to return the value to them. The principle advantage is from the data collecting component's standpoint, in that it does not have to create instances of CountStatistic when its current value is queried/measured.

see
#reset
see
#setCount
return
instance of CountStatistic

        return ( new CountStatisticImpl(
            this.count,                 // this is the actual changing statistic
            initial.getName(),          // name does not change
            initial.getUnit(),          // unit does not change
            initial.getDescription(),   // description does not change
            this.lastSampleTime,        // changes all the time!
            this.startTime              // changes if reset is called earlier
        ));