java.lang.Object
net.i2p.stat.FrequencyStat

public class FrequencyStatextends Object
Coordinates an event frequency over various periods.
  • Field Details

    • _statName

      private final String _statName
      Unique name of the statistic.
    • _groupName

      private final String _groupName
      Grouping under which the stat is kept.
    • _description

      private final String _description
      Describes the stat.
    • _frequencies

      private final Frequency[] _frequencies
      Actual frequency objects for this statistic.
    • NL

      private static final String NL
      Line separator of the persisted file.
  • Constructor Details

    • FrequencyStat

      public FrequencyStat(String name, String description, String group, long[] periods)
      Create a new frequency stat.
      Parameters:
      name - unique name of the statistic
      description - simple description of the statistic
      group - used to group statistics together
      periods - array of period lengths (in milliseconds)
  • Method Details

    • eventOccurred

      public void eventOccurred()
      Updates all of the frequencies for the various periods.
    • coalesceStats

      public void coalesceStats()
      Coalesce all the stats.
    • getName

      public String getName()
      Unique name for this statistic.
      Returns:
      the unique name of this statistic
    • getGroupName

      public String getGroupName()
      Grouping name for this statistic.
      Returns:
      the grouping name under which this statistic is kept
    • getDescription

      public String getDescription()
      Description of what this statistic measures.
      Returns:
      a simple description of this statistic
    • getPeriods

      public long[] getPeriods()
      Tracked periods for this frequency stat.
      Returns:
      the periods this frequency is tracked over, in milliseconds
    • getFrequency

      public Frequency getFrequency(long period)
      Frequency object for the specified period.
      Parameters:
      period - the period in milliseconds
      Returns:
      the Frequency for the given period, or null if not found
    • getEventCount

      public long getEventCount()
      Total number of events recorded.
      Returns:
      the count over the lifetime period, or 0 if no periods are defined
    • getFrequency

      public long getFrequency()
      Lifetime average frequency.
      Returns:
      lifetime average frequency in millisedonds, i.e. the average time between events, or Long.MAX_VALUE if no events ever
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Compares this frequency stat to another object for equality.
      Overrides:
      equals in class Object
    • store

      public void store(OutputStream out, String prefix) throws IOException
      Serializes this FrequencyStat to the provided OutputStream.
      Parameters:
      out - to write to
      prefix - to prepend to the stat
      Throws:
      IOException - if something goes wrong