-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from sendgrid/rate_limit
Adding optional rate limit support.
- Loading branch information
Showing
4 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.sendgrid; | ||
|
||
/** | ||
* An interface describing a callback mechanism for the | ||
* asynchronous, rate limit aware API connection. | ||
*/ | ||
public interface APICallback { | ||
/** | ||
* Callback method in case of an error. | ||
* @param ex the error that was thrown. | ||
*/ | ||
public void error(Exception ex); | ||
|
||
/** | ||
* Callback method in case of a valid response. | ||
* @param response the valid response. | ||
*/ | ||
public void response(Response response); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.sendgrid; | ||
|
||
/** | ||
* An exception thrown when the maximum number of retries | ||
* have occurred, and the API calls are still rate limited. | ||
*/ | ||
public class RateLimitException extends Exception { | ||
private final Request request; | ||
private final int retryCount; | ||
|
||
/** | ||
* Construct a new exception. | ||
* @param request the originating request object. | ||
* @param retryCount the number of times a retry was attempted. | ||
*/ | ||
public RateLimitException(Request request, int retryCount) { | ||
this.request = request; | ||
this.retryCount = retryCount; | ||
} | ||
|
||
/** | ||
* Get the originating request object. | ||
* @return the request object. | ||
*/ | ||
public Request getRequest() { | ||
return this.request; | ||
} | ||
|
||
/** | ||
* Get the number of times the action was attemted. | ||
* @return the retry count. | ||
*/ | ||
public int getRetryCount() { | ||
return this.retryCount; | ||
} | ||
} |
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
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