|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nitido.throttle.CountThrottle
public class CountThrottle
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 |
---|
public CountThrottle(int countLimit)
countLimit
- The number of calls allowed to go through the throttle. It must be
larger than 0.Method Detail |
---|
public boolean enterThrottle()
enterThrottle
in interface NonBlockingThrottle
public void exitThrottle()
exitThrottle
in interface NonBlockingThrottle
|
Nitido NiM 2.5 Java API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1999-2009 Nitido Inc. Proprietary and Confidential. All Rights Reserved.