Class RateStatistic

  • Direct Known Subclasses:
    AcceptRateLimit.Rate

    public class RateStatistic
    extends java.lang.Object

    Statistics on a time sequence rate.

    Calculates the rate at which the record() method is called over the configured period, retaining also the total count and maximum rate achieved.

    The implementation keeps a Deque of timestamps for all records for the last time period, so this method is not suitable for large rates unless a small time period is used.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long _count  
      private long _max  
      private long _nanoPeriod  
      private java.util.Deque<java.lang.Long> _samples  
      private java.util.concurrent.TimeUnit _units  
    • Constructor Summary

      Constructors 
      Constructor Description
      RateStatistic​(long period, java.util.concurrent.TimeUnit units)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void age​(long period, java.util.concurrent.TimeUnit units)  
      java.lang.String dump()  
      java.lang.String dump​(java.util.concurrent.TimeUnit units)  
      long getCount()  
      long getMax()  
      long getOldest​(java.util.concurrent.TimeUnit units)  
      long getPeriod()  
      int getRate()  
      java.util.concurrent.TimeUnit getUnits()  
      int record()
      Records a sample value.
      void reset()
      Resets the statistics.
      java.lang.String toString()  
      private java.lang.String toString​(long nanoTime)  
      private void update()  
      private void update​(long now)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • _samples

        private final java.util.Deque<java.lang.Long> _samples
      • _nanoPeriod

        private final long _nanoPeriod
      • _units

        private final java.util.concurrent.TimeUnit _units
      • _max

        private long _max
      • _count

        private long _count
    • Constructor Detail

      • RateStatistic

        public RateStatistic​(long period,
                             java.util.concurrent.TimeUnit units)
    • Method Detail

      • getPeriod

        public long getPeriod()
      • getUnits

        public java.util.concurrent.TimeUnit getUnits()
      • reset

        public void reset()
        Resets the statistics.
      • update

        private void update()
      • update

        private void update​(long now)
      • age

        protected void age​(long period,
                           java.util.concurrent.TimeUnit units)
      • record

        public int record()
        Records a sample value.
        Returns:
        the number of records in the current period.
      • getRate

        public int getRate()
        Returns:
        the number of records in the current period
      • getMax

        public long getMax()
        Returns:
        the max number of samples per period.
      • getOldest

        public long getOldest​(java.util.concurrent.TimeUnit units)
        Parameters:
        units - the units of the return
        Returns:
        the age of the oldest sample in the requested units
      • getCount

        public long getCount()
        Returns:
        the number of samples recorded
      • dump

        public java.lang.String dump()
      • dump

        public java.lang.String dump​(java.util.concurrent.TimeUnit units)
      • toString

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

        private java.lang.String toString​(long nanoTime)