This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.concurrent.DelayQueue; | |
import java.util.concurrent.Delayed; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* A simple throttled blocking-queue that returns elements at a constant rate (M | |
* elements in N time) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Class that throttles requests. Ensures that the StartRequest cannot be called | |
* more than a given amount of time in any given interval. | |
* | |
* StartRequest blocks until this requirement is satisfied. | |
* | |
* TryStartRequest returns 0 if the request was cleared, or a non-0 number of | |
* millisecond to sleep before the next attempt. | |
* | |
* Simple usage, 10 requests per second: |