Nitido Inc.

com.nitido.throttle
Class CountThrottle

java.lang.Object
  extended by com.nitido.throttle.CountThrottle
All Implemented Interfaces:
NonBlockingThrottle

public class CountThrottle
extends java.lang.Object
implements NonBlockingThrottle

Provides throttling that controls the number of calls at the same time. This throttle does not remember when is the previous request. As a result, it can allow large number of requests going through if the code within the throttle is executed quickly. If you want to control the total number of requests can be processed within a period of time (such as 100 requests per minute), you should use the CountPerTimeThrottle instead.

This throttle is non-blocking and the result will be returned quickly. (i.e. if the throttle limit is exceeded, the enterThrottle() method will return false immediately.)

This object is designed to be thread-safe and can be accessed by multiple threads. All operation will happen quickly and should not block the thread for a long time.

The default constructor takes in the countLimit (let's say N). When you call the enterThrottle() method, this object will return true if the request can enter the throttle (i.e. it is within the limit of N request). Otherwise, it will return false.

The code should be in the format:

     CountThrottle _throttle = new CounterThrottle( N );
     public void myMethod( )
     {
         if( !_throttle.enterThrottle() )
         {
             throw new Excpetion("Exceed throttle limit.");
         }
         
         try {
             // Start of your operation
             // ....
             // End of your operation
         } finally {
             _throttle.exitThrottle();
         }
     }
 


Constructor Summary
CountThrottle(int countLimit)
          Default constructor.
 
Method Summary
 boolean enterThrottle()
          The method to call when entering the throttle.
 void exitThrottle()
          The method to call when leaving the throttle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CountThrottle

public CountThrottle(int countLimit)
Default constructor.

Parameters:
countLimit - The number of calls allowed to go through the throttle. It must be larger than 0.
Method Detail

enterThrottle

public boolean enterThrottle()
The method to call when entering the throttle.

Specified by:
enterThrottle in interface NonBlockingThrottle
Returns:
true if pass the throttle control successfully, false if otherwise.

exitThrottle

public void exitThrottle()
The method to call when leaving the throttle.

Specified by:
exitThrottle in interface NonBlockingThrottle

Nitido NiM 2.5 Java API

These JavaDoc pages are generated for release/nim_2_5-2.5.44

Copyright © 1999-2009 Nitido Inc.    Proprietary and Confidential.    All Rights Reserved.