psdi.util

Class Limit

  • java.lang.Object
    • psdi.util.Limit


  • public class Limit
    extends java.lang.Object
    Enforces a bounded count. This class can be used with the 'synchronized' keyword to limit the number of threads that started for a particular task.
    See Also:
    psdi.mnet.MessageService
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected int count
      Accessed only with inc(), dec() and getCount().
      protected int max
      Note this can be CHANGED after construction.
    • Constructor Summary

      Constructors 
      Constructor and Description
      Limit(int max)
      Construct with the specified limit.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean atMax()
      Returns true when count >= max.
      void dec()
      Decrements the internal count variable.
      int getCount()
      Get's the current count.
      int getMax()
      Get the upper limit.
      void inc()
      Increments the internal count variable.
      void setMax(int value)
      Sets the maximum value that limit will increment to.
      • Methods inherited from class java.lang.Object

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

      • max

        protected int max
        Note this can be CHANGED after construction.
      • count

        protected int count
        Accessed only with inc(), dec() and getCount(). There is no setCount().
    • Constructor Detail

      • Limit

        public Limit(int max)
        Construct with the specified limit.
        Parameters:
        max -
    • Method Detail

      • setMax

        public void setMax(int value)
        Sets the maximum value that limit will increment to. Note: the minimum is 0.
        Parameters:
        value -
      • getMax

        public int getMax()
        Get the upper limit.
      • getCount

        public int getCount()
        Get's the current count.
      • atMax

        public boolean atMax()
        Returns true when count >= max.
      • inc

        public void inc()
        Increments the internal count variable.
      • dec

        public void dec()
        Decrements the internal count variable.