com.grandcentral.appstats.impl
Class StatImpl

java.lang.Object
  |
  +--com.grandcentral.appstats.impl.StatImpl
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, Stat
Direct Known Subclasses:
CounterImpl, SynchronizedStatImpl, TimerImpl

public class StatImpl
extends java.lang.Object
implements Stat

Base Stat implementation

Copyright: Copyright (c) 2002

Company: Grand Central Communications

Version:
1.0
Author:
Adrian Dorsman, Taras Shkvarchuk
See Also:
Serialized Form

Field Summary
protected  double m_aDouble
           
protected  int m_aggr
           
protected  long m_aLong
           
protected  java.lang.String m_name
           
protected  java.lang.Object m_obj
           
protected  int m_type
           
 
Fields inherited from interface com.grandcentral.appstats.Stat
AGGREGATE_AVG, AGGREGATE_EXPAVG, AGGREGATE_MAX, AGGREGATE_MIN, AGGREGATE_REPLACE, AGGREGATE_SUM, DELIM_STATNAME, DELIM_STATPREFIX, DELIM_TASKPARENT, DONT_AGGREGATE, TYPE_DOUBLE, TYPE_HEIRARCH, TYPE_HIDDEN, TYPE_LONG, TYPE_OBJECT, TYPE_UNDEFINED
 
Constructor Summary
StatImpl()
           
 
Method Summary
 void addAggregationMethod(int agMethod)
          add an aggregationMethod to this stat
 void addType(int type)
          add a type to this stat
 java.lang.Object clone()
           
 boolean containsAggregationMethod(int agMethod)
          returns true if this Stat is configured with param agMethod
 boolean containsType(int type)
          returns true if this Stat is configured with param type
static java.lang.String createFullName(java.lang.String taskHierarchy, java.lang.String statName)
          creates a fullname from the different components.
static java.lang.String createFullName(java.lang.String taskHierarchy, java.lang.String prefix, java.lang.String suffix)
          creates a fullname from the different components.
static java.lang.String createStatName(java.lang.String prefix, java.lang.String suffix)
          creates a statName from the different components.
 void fromStringAbbr(java.lang.String s)
          parses what it can from abbreviated form.
 int getAggregationMethod()
          Returns the aggregation method for this stat.
 double getDouble()
           
 java.lang.String getFullName()
          A Stat's full name is composed of two distinct parts: a task hierarchy and a statName.
 long getLong()
           
 java.lang.Object getObject()
           
 java.lang.String getStatName()
          A statName can be further broken down into a prefix and a suffix, as:
static java.lang.String getStatName(java.lang.String fullname)
           
 java.lang.String getStatPrefix()
           
static java.lang.String getStatPrefix(java.lang.String statname)
           
 java.lang.String getStatSuffix()
           
static java.lang.String getStatSuffix(java.lang.String statname)
           
 java.lang.String getTaskHierarchy()
          returns the task hierarchy from the full name of this stat
static java.lang.String getTaskHierarchy(java.lang.String fullname)
           
 int getType()
          Returns the type for this stat.
static boolean isValidPrefix(java.lang.String name)
          validates a prefix for a statName -- the name must not contain the DELIM_STATNAME character and must not be null
static boolean isValidStatName(java.lang.String name)
          validates a name for use for a Stat -- the name must not contain the DELIM_STATNAME character and must not be null
static boolean isValidSuffix(java.lang.String suffix)
          validates a suffix for a statName -- the suffix must not contain any DELIM_STATNAME or DELIM_STATPREFIX characters and must not be null
static boolean isValidTaskName(java.lang.String taskname)
          validates a taskname.
 void prependTaskName(java.lang.String taskname)
          prepends taskname + StatSource.DELIM_PARENT to the fullname of this stat
static java.lang.String prependTaskName(java.lang.String taskname, java.lang.String fullname)
           
 void removeAggregationMethod(int agMethod)
          remove an aggregationMethod from this stat.
 void removeType(int type)
          remove a type from this stat.
 void setAggregationMethod(int agMethod)
          sets the aggregationMethod for this Stat.
 void setDouble(double num)
           
 void setFullName(java.lang.String name)
          sets the full name of this Stat.
 void setLong(long num)
           
 void setObject(java.lang.Object o)
           
 void setStatName(java.lang.String name)
          sets the stat name.
 void setStatPrefix(java.lang.String name)
          set the statName's prefix.
 void setStatSuffix(java.lang.String suffix)
           
 void setTaskHierarchy(java.lang.String taskHierarchy)
          sets the task hierarchy from the full name of this stat
 void setType(int type)
          sets the type for this stat.
 java.lang.String toString()
           
 java.lang.String toStringAbbr()
          returns statName and values in String representation.
 void toStringAbbr(java.lang.StringBuffer s)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_aLong

protected long m_aLong

m_aDouble

protected double m_aDouble

m_obj

protected java.lang.Object m_obj

m_type

protected int m_type

m_name

protected java.lang.String m_name

m_aggr

protected int m_aggr
Constructor Detail

StatImpl

public StatImpl()
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Specified by:
clone in interface Stat
Overrides:
clone in class java.lang.Object

getFullName

public java.lang.String getFullName()
Description copied from interface: Stat
A Stat's full name is composed of two distinct parts: a task hierarchy and a statName. It is one of two forms:
  • task hierarchy + Stat.DELIM_STATNAME + statName
  • statName, or Stat.DELIM_STATNAME + statName
  • Specified by:
    getFullName in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    See Also:
    Stat.getStatName(), Task.getName()

    setFullName

    public void setFullName(java.lang.String name)
    Description copied from interface: Stat
    sets the full name of this Stat.
    Specified by:
    setFullName in interface Stat
    Throws:
    NullPointerException - if name is null

    getStatName

    public java.lang.String getStatName()
    Description copied from interface: Stat
    A statName can be further broken down into a prefix and a suffix, as:

  • prefix + Stat.DELIM_STATPREFIX + suffix
  • Examples:

  • httpTransactionLatency.min
  • httpTransactionLatency.max
  • httpTransactionLatency.avg
  • In the above, "httpTransactionLatency" is the prefix, and "min," "max," and "avg" are the suffixes.
    Specified by:
    getStatName in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Returns:
    the StatSource name or "" if the statName does not contain a StatSource (i.e., it's missing a DELIM_STATPREFIX character)
    See Also:
    Stat.getFullName()

    getStatName

    public static java.lang.String getStatName(java.lang.String fullname)

    setStatName

    public void setStatName(java.lang.String name)
    Description copied from interface: Stat
    sets the stat name.
    Specified by:
    setStatName in interface Stat
    Throws:
    java.lang.IllegalArgumentException - if name is not valid
    NullPointerException - if name is null

    getTaskHierarchy

    public java.lang.String getTaskHierarchy()
    Description copied from interface: Stat
    returns the task hierarchy from the full name of this stat
    Specified by:
    getTaskHierarchy in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Returns:
    "" if no task hierarchy can be found
    See Also:
    Stat.getFullName()

    getTaskHierarchy

    public static java.lang.String getTaskHierarchy(java.lang.String fullname)

    setTaskHierarchy

    public void setTaskHierarchy(java.lang.String taskHierarchy)
    Description copied from interface: Stat
    sets the task hierarchy from the full name of this stat
    Specified by:
    setTaskHierarchy in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Parameters:
    name - contains the task hierarchy, or can be null to clear this Stat's taskHierarchy
    See Also:
    Stat.getFullName()

    prependTaskName

    public void prependTaskName(java.lang.String taskname)
    Description copied from interface: Stat
    prepends taskname + StatSource.DELIM_PARENT to the fullname of this stat
    Specified by:
    prependTaskName in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Throws:
    java.lang.IllegalArgumentException - if taskname contains StatSource.DELIM_PARENT character
    NullPointerException - if taskname is null

    prependTaskName

    public static java.lang.String prependTaskName(java.lang.String taskname,
                                                   java.lang.String fullname)

    getStatPrefix

    public java.lang.String getStatPrefix()
    Specified by:
    getStatPrefix in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    See Also:
    Stat.getStatName()

    getStatPrefix

    public static java.lang.String getStatPrefix(java.lang.String statname)

    setStatPrefix

    public void setStatPrefix(java.lang.String name)
    Description copied from interface: Stat
    set the statName's prefix. This name cannot contain the DELIM_STATPREFIX character, nor the DELIM_STATNAME character.
    Specified by:
    setStatPrefix in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Throws:
    NullPointerException - if you try to set the name to a null value
    java.lang.IllegalArgumentException - if the name is invalid
    See Also:
    Stat.getStatName()

    getStatSuffix

    public java.lang.String getStatSuffix()
    Specified by:
    getStatSuffix in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Returns:
    the statname's suffix or "" if one can't be found (i.e. the statName's missing a DELIM_STATPREFIX character)
    See Also:
    Stat.getStatName(), Stat.getStatPrefix()

    getStatSuffix

    public static java.lang.String getStatSuffix(java.lang.String statname)

    setStatSuffix

    public void setStatSuffix(java.lang.String suffix)
    Specified by:
    setStatSuffix in interface Stat

    createFullName

    public static java.lang.String createFullName(java.lang.String taskHierarchy,
                                                  java.lang.String statName)
    creates a fullname from the different components. Does not validate any of the components
    Parameters:
    taskHierarchy - can be null
    statName - can not be null
    Throws:
    NullPointerException - if statName is null
    java.lang.IllegalArgumentException - if statName contains illegal characters

    createFullName

    public static java.lang.String createFullName(java.lang.String taskHierarchy,
                                                  java.lang.String prefix,
                                                  java.lang.String suffix)
    creates a fullname from the different components.
    Parameters:
    taskHierarchy - can be null
    prefix - must not be null
    suffix - must not be null
    Throws:
    NullPointerException - if prefix or suffix is null
    java.lang.IllegalArgumentException - if prefix or suffix contains invalid characters

    createStatName

    public static java.lang.String createStatName(java.lang.String prefix,
                                                  java.lang.String suffix)
    creates a statName from the different components.
    Parameters:
    prefix - must not be null
    suffix - must not be null
    Throws:
    NullPointerException - if prefix or suffix is null
    java.lang.IllegalArgumentException - if prefix or suffix contains invalid characters

    isValidStatName

    public static boolean isValidStatName(java.lang.String name)
    validates a name for use for a Stat -- the name must not contain the DELIM_STATNAME character and must not be null

    isValidPrefix

    public static boolean isValidPrefix(java.lang.String name)
    validates a prefix for a statName -- the name must not contain the DELIM_STATNAME character and must not be null

    isValidSuffix

    public static boolean isValidSuffix(java.lang.String suffix)
    validates a suffix for a statName -- the suffix must not contain any DELIM_STATNAME or DELIM_STATPREFIX characters and must not be null

    isValidTaskName

    public static boolean isValidTaskName(java.lang.String taskname)
    validates a taskname. A taskname must not contain the DELIM_TASKPARENT character and must not be null

    getType

    public int getType()
    Description copied from interface: Stat
    Returns the type for this stat. A stat's type is implemented as a bitfield. Thus, a stat implemented with getType()==(TYPE_LONG|TYPE_STRING) will fail the test if(getType()==(TYPE_LONG)). For comparison, it is better to use the containsType() method.

    Using multiple types in a stat allows for numerical comparison of string values, for instance, consider the case of a status Stat where you want the highest priority status of any task to filter down to the root task. You can set a numerical value along with a status String in each status Stat where numerically greater values correspond to more critical statae. Then call Stat.setAggregationMethod(AGGREGATE_MAX) and the status' stat will get filtered down in a task hierarchy so that if any child task has a high priority status the whole application will have that high priority status.

    Specified by:
    getType in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    See Also:
    see also the TYPE_{type} constants

    setType

    public void setType(int type)
    Description copied from interface: Stat
    sets the type for this stat. Doesn't clear any previously stored values associated with the old type
    Specified by:
    setType in interface Stat

    addType

    public void addType(int type)
    Description copied from interface: Stat
    add a type to this stat
    Specified by:
    addType in interface Stat

    removeType

    public void removeType(int type)
    Description copied from interface: Stat
    remove a type from this stat. Doesn't clear any previously stored values associated with the old type
    Specified by:
    removeType in interface Stat

    containsType

    public boolean containsType(int type)
    Description copied from interface: Stat
    returns true if this Stat is configured with param type
    Specified by:
    containsType in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Returns:
    getType()&type

    getAggregationMethod

    public int getAggregationMethod()
    Description copied from interface: Stat
    Returns the aggregation method for this stat. The aggregation method is implemented as a bitfield. Thus, a stat implemented with getAggregationMethod()==(AGGREGATE_MIN|AGGREGATE_MAX) will fail the test if(getAggregationMethod()==(AGGREGATE_MIN)). For comparison, it is better to use the containsAggregationMethod() method.

    AggregationMethods are used by StatAggregators when a Task aggregates Stats from another Task. Using a bitfield allows for multiple calculations to occur when a Stat is aggregated. For instance, when a timer statistic is aggregated, the aggregator will calculate minimum, maximum, and an exponential average value and place it into the destination task, because all Timers by default have aggregation methods of (AGGREGATE_MIN|AGGREGATE_MAX|AGGREGATE_EXPAVG)

    AppStat's standard aggregation methods are stored in this class as AGGREGATE_* public static final ints. These values map to logic inside of the StatAggregatorImpl class. If a user wants to implement their own custom aggregation methods, they may use their own values and their own StatAggregator implementation. The standard aggregation methods are meant to cover 80-90% of the use cases, and that's why they are hardcoded into this class.

    Alternatively, a user may also provide a StatCalculator to calculate further statistics on aggregation. (@see Task#registerStatCalculator)

    Specified by:
    getAggregationMethod in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    See Also:
    see also the AGGREGATE_{method} constants

    setAggregationMethod

    public void setAggregationMethod(int agMethod)
    Description copied from interface: Stat
    sets the aggregationMethod for this Stat. Usually this is done immediately after the Stat is created. However, if you are modifying this after a Stat has been aggregated into a destination task, you should go an remove any Stats that the prior aggregation method might have created in the destination task (otherwise, they'll sit around forever)
    Specified by:
    setAggregationMethod in interface Stat

    addAggregationMethod

    public void addAggregationMethod(int agMethod)
    Description copied from interface: Stat
    add an aggregationMethod to this stat
    Specified by:
    addAggregationMethod in interface Stat

    removeAggregationMethod

    public void removeAggregationMethod(int agMethod)
    Description copied from interface: Stat
    remove an aggregationMethod from this stat. @see #setAggregationMethod for disclaimer
    Specified by:
    removeAggregationMethod in interface Stat

    containsAggregationMethod

    public boolean containsAggregationMethod(int agMethod)
    Description copied from interface: Stat
    returns true if this Stat is configured with param agMethod
    Specified by:
    containsAggregationMethod in interface Stat
    Following copied from interface: com.grandcentral.appstats.Stat
    Returns:
    getAggregationMethod()&agMethod

    setLong

    public void setLong(long num)
    Specified by:
    setLong in interface Stat

    getLong

    public long getLong()
    Specified by:
    getLong in interface Stat

    setDouble

    public void setDouble(double num)
    Specified by:
    setDouble in interface Stat

    getDouble

    public double getDouble()
    Specified by:
    getDouble in interface Stat

    setObject

    public void setObject(java.lang.Object o)
    Specified by:
    setObject in interface Stat

    getObject

    public java.lang.Object getObject()
    Specified by:
    getObject in interface Stat

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object

    toStringAbbr

    public java.lang.String toStringAbbr()
    returns statName and values in String representation. Does not serialize aggregationMethod or dataType or taskHierarchy information
    Specified by:
    toStringAbbr in interface Stat

    toStringAbbr

    public void toStringAbbr(java.lang.StringBuffer s)
    Specified by:
    toStringAbbr in interface Stat

    fromStringAbbr

    public void fromStringAbbr(java.lang.String s)
    parses what it can from abbreviated form. if it fails to parse numerical value, stores value as an Object of type String
    Specified by:
    fromStringAbbr in interface Stat