messif.statistics
Class Statistics<TSelf extends Statistics<TSelf>>

java.lang.Object
  extended by messif.statistics.Statistics<TSelf>
Type Parameters:
TSelf - the type of this statistic
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
StatisticCounter, StatisticMinMaxCounter, StatisticObject, StatisticRefCounter, StatisticSimpleWeakrefCounter, StatisticSlidingAvgCounter, StatisticTimer

public abstract class Statistics<TSelf extends Statistics<TSelf>>
extends java.lang.Object
implements java.io.Serializable

Base class for all statistics.

See Also:
Serialized Form

Field Summary
protected  Statistics<TSelf> replaceWith
          Serialization replacement object
 
Constructor Summary
protected Statistics(java.lang.String name)
          Creates instance of Statistics with filled internal data
 
Method Summary
protected  void addBoundStat(TSelf stat)
          Bind a statistic to this statistic.
 void bindTo(TSelf object)
          Bind this statistic to the given one.
protected  boolean canPerformOperation()
          Check if this statistic can update itself.
protected abstract  TSelf cast()
          Returns this statistics as the type provided typed argument.
static void disableGlobally()
          Disables all statistic counting globally.
static void enableGlobally()
          Enables all statistic counting globally.
static java.util.Iterator<Statistics<?>> getAllStatistics()
          Returns an iterator over all global statistics.
static java.util.Iterator<Statistics<?>> getAllStatistics(java.lang.String regex)
          Returns an iterator over all global statistics with names matching the provided regular expression.
protected  java.util.Set<TSelf> getBoundStats()
          Returns a set of all statistics that are bound to this one.
protected  TSelf getBoundTo()
          Returns the statistic that this stat is bound to.
 java.lang.String getName()
          Returns the registered name of this statistic.
static Statistics<?> getStatistics(java.lang.String statisticName)
          Returns a registered global statistic.
static
<T extends Statistics<? extends T>>
T
getStatistics(java.lang.String statisticName, java.lang.Class<? extends T> statisticClass)
          Returns a registered global statistic.
protected  boolean isBound()
          Returns true if this statistic is bound to another one.
static boolean isEnabledGlobally()
          Returns true if statistics are globally enabled.
protected  boolean isRegisteredGlobally()
          Returns true if this statistic is present in global statistics registry.
static java.lang.String printStatistics()
          Returns a string containing current states of all global statistics.
static java.lang.String printStatistics(java.lang.String regex)
          Returns a string containing current states of global statistics with names matching the provided regular expression.
static java.lang.String printStatistics(java.lang.String regex, java.lang.String statSeparator)
          Returns a string containing current states of global statistics with names matching the provided regular expression and separated by specified separator.
protected  java.lang.Object readResolve()
          Deserialization method to replace the object with a global statistic's one.
protected  void removeBoundStat(TSelf stat)
          Remove a bound statistic from this one.
static boolean removeStatistic(java.lang.String name)
          Remove the statistic from global registry.
abstract  void reset()
          Reset the value of this statistic.
static void resetStatistics()
          Resets all statistics.
static void resetStatistics(java.lang.String regex)
          Resets statistics matching the regular expression.
protected abstract  void setFrom(TSelf sourceStat)
          Set the value of this statistic to the actual value of the given sourceStat.
 void unbind()
          Deregister this statistic from the "parent" statistic it is bound to.
protected abstract  void updateFrom(TSelf sourceStat)
          Updates the value of this statistic from the given sourceStat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

replaceWith

protected transient Statistics<TSelf extends Statistics<TSelf>> replaceWith
Serialization replacement object

Constructor Detail

Statistics

protected Statistics(java.lang.String name)
Creates instance of Statistics with filled internal data

Parameters:
name - the name of this stat
Method Detail

getStatistics

public static <T extends Statistics<? extends T>> T getStatistics(java.lang.String statisticName,
                                                                  java.lang.Class<? extends T> statisticClass)
                                                       throws java.lang.IllegalArgumentException,
                                                              java.lang.ClassCastException
Returns a registered global statistic. If there is not global statistic of the given name, a new instance is created, registered and returned.

Type Parameters:
T - the type of the statistic to get
Parameters:
statisticName - the name of the statistic to get
statisticClass - the type of the statistic to get
Returns:
a registered global statistic instance
Throws:
java.lang.IllegalArgumentException - if the statistics of the given name does not exist and cannot be created
java.lang.ClassCastException - if the statistics of the given name exists, but is not instance of statisticClass

getStatistics

public static Statistics<?> getStatistics(java.lang.String statisticName)
Returns a registered global statistic.

Parameters:
statisticName - the name of the statistic to get
Returns:
a registered global statistic instance or null if no statistic is registered with this name

getName

public java.lang.String getName()
Returns the registered name of this statistic.

Returns:
the registered name of this statistic

getBoundTo

protected TSelf getBoundTo()
Returns the statistic that this stat is bound to. If this statistic is not bound, null is returned.

Returns:
the statistic that this stat is bound to

isBound

protected boolean isBound()
Returns true if this statistic is bound to another one.

Returns:
true if this statistic is bound to another one

cast

protected abstract TSelf cast()
Returns this statistics as the type provided typed argument. This is a convenience method to avoid unchecked casts.

Returns:
this statistics

updateFrom

protected abstract void updateFrom(TSelf sourceStat)
Updates the value of this statistic from the given sourceStat. Specifically, this method merges the value of the sourceStat with this statistic.

The actual implementation depends on the type of the statistic.

Parameters:
sourceStat - the statistic from which to update this stat

setFrom

protected abstract void setFrom(TSelf sourceStat)
Set the value of this statistic to the actual value of the given sourceStat.

Parameters:
sourceStat - the statistic from which to set this stat

reset

public abstract void reset()
Reset the value of this statistic.


addBoundStat

protected void addBoundStat(TSelf stat)
Bind a statistic to this statistic. That is, register the stat to receive notifications when the value of this statistic is updated.

Parameters:
stat - the statistic to register

removeBoundStat

protected void removeBoundStat(TSelf stat)
Remove a bound statistic from this one.

Parameters:
stat - the statistic to unbind

getBoundStats

protected final java.util.Set<TSelf> getBoundStats()
Returns a set of all statistics that are bound to this one.

Returns:
a set of all statistics that are bound to this one

unbind

public void unbind()
Deregister this statistic from the "parent" statistic it is bound to. If this statistic is not bound, nothing happens.


bindTo

public void bindTo(TSelf object)
            throws java.lang.IllegalArgumentException
Bind this statistic to the given one. This statistic will then be updated wheneve the given statistic is updated using the same values. Note that since the initial values of this and the other statistic can differ, they can maintain a different value.

Parameters:
object - the statistic to which this statistic should be bound to
Throws:
java.lang.IllegalArgumentException - if this statistic is already bound to another stat

canPerformOperation

protected final boolean canPerformOperation()
Check if this statistic can update itself.

Returns:
true if updates are enabled or false if not

isEnabledGlobally

public static final boolean isEnabledGlobally()
Returns true if statistics are globally enabled.

Returns:
true if statistics are globally enabled

disableGlobally

public static void disableGlobally()
Disables all statistic counting globally.


enableGlobally

public static void enableGlobally()
Enables all statistic counting globally.


readResolve

protected java.lang.Object readResolve()
                                throws java.io.ObjectStreamException
Deserialization method to replace the object with a global statistic's one.

Returns:
the object to use as replacement
Throws:
java.io.ObjectStreamException - if there was an error (not thrown by this implementation)

isRegisteredGlobally

protected boolean isRegisteredGlobally()
Returns true if this statistic is present in global statistics registry.

Returns:
true if this statistic is present in global statistics registry

removeStatistic

public static boolean removeStatistic(java.lang.String name)
Remove the statistic from global registry.

Parameters:
name - name of the statistic
Returns:
true if the statistic existed and was removed

resetStatistics

public static void resetStatistics()
Resets all statistics.


resetStatistics

public static void resetStatistics(java.lang.String regex)
Resets statistics matching the regular expression.

Parameters:
regex - the regular expression that matches the names of statistics to reset

printStatistics

public static java.lang.String printStatistics(java.lang.String regex,
                                               java.lang.String statSeparator)
Returns a string containing current states of global statistics with names matching the provided regular expression and separated by specified separator.

Parameters:
regex - the regular expression that matches the names of statistics to use
statSeparator - the string that separates the respective statistics (can be newline)
Returns:
a string with all the statistics that were printed

printStatistics

public static java.lang.String printStatistics(java.lang.String regex)
Returns a string containing current states of global statistics with names matching the provided regular expression. New-line is used as separator.

Parameters:
regex - the regular expression that matches the names of statistics to use
Returns:
a string with all the statistics that were printed

printStatistics

public static java.lang.String printStatistics()
Returns a string containing current states of all global statistics.

Returns:
a string with all the statistics

getAllStatistics

public static java.util.Iterator<Statistics<?>> getAllStatistics()
Returns an iterator over all global statistics.

Returns:
an iterator over all global statistics

getAllStatistics

public static java.util.Iterator<Statistics<?>> getAllStatistics(java.lang.String regex)
Returns an iterator over all global statistics with names matching the provided regular expression.

Parameters:
regex - the regular expression that matches the names of statistics to use
Returns:
an iterator over all global statistics