Nitido Inc.

com.nitido.throttle
Class BlockingCountThrottle

java.lang.Object
  extended by com.nitido.throttle.BlockingCountThrottle
All Implemented Interfaces:
BlockingThrottle

public class BlockingCountThrottle
extends java.lang.Object
implements BlockingThrottle

Provides throttling that will block the requesting threads if the limit has been reached (and will continue to block the thread until it can enter the throttle or the wait time expires).


Constructor Summary
BlockingCountThrottle(int allowCount)
          Default constructor.
 
Method Summary
 boolean enterThrottle(long maxWaitTime)
          Method to call when entering the throttle.
 void exitThrottle()
          Method to be called when exiting the code block that was throttle controlled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingCountThrottle

public BlockingCountThrottle(int allowCount)
Default constructor.

Parameters:
allowCount - The number of requests that can go through this throttle at the same time
Method Detail

enterThrottle

public boolean enterThrottle(long maxWaitTime)
Method to call when entering the throttle. If the throttle's limit is exceeded, the calling thread will be blocked until it can enter the throttle or the specified maxWaitTime expired.

This method is designed intentionally to force the caller to specify the maxWaitTime. It does not allow a thread to be block forever until the resource is available. It is because we need to ensure the calling thread will eventually return and continue processing.

Specified by:
enterThrottle in interface BlockingThrottle
Parameters:
maxWaitTime - The maximum time to wait for entering the throttle. It must be a long integer larger than 0. If it is smaller than that, this throttle will fail the request.
Returns:
true if the request can enter the throttle, false if it cannot enter the throttle for the specified time

exitThrottle

public void exitThrottle()
Method to be called when exiting the code block that was throttle controlled

Specified by:
exitThrottle in interface BlockingThrottle

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.