|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nitido.throttle.CountPerTimeThrottle
public class CountPerTimeThrottle
Provides throttling that controls the number of calls within a specific time duration. This throttle remembers when the successful request happens. As a result, it can control the total number of requests can be processed within a period of time (such as 100 requests per minute). If you simply want to control the number of threads that can access the protected resource at the same time, you should use CountThrottle instead (which is faster and uses less memory).
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) and the duration (let's say T). 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 per T milliseconds). Otherwise, it will return false.
Although the exitThrottle() method does not do anything, developers should still call it after they finish their own processing. In other words, the code should be in the format:
CountPerTimeThrottle _throttle = new CounterPerTimeThrottle( N, T ); 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 | |
---|---|
CountPerTimeThrottle(int countLimit,
long duration)
Default constructor. |
Method Summary | |
---|---|
boolean |
enterThrottle()
Check if the current call can enter the throttle sucessfully. |
void |
exitThrottle()
Leaving the throttle. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CountPerTimeThrottle(int countLimit, long duration)
countLimit
- The number of calls allowed within the duration. It must be larger
than 0.duration
- The duration time in milliseconds. 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.