-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
113 additions
and
9 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
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
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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/org/stellar/sdk/requests/TooManyRequestsException.java
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,22 @@ | ||
package org.stellar.sdk.requests; | ||
|
||
/** | ||
* Exception thrown when too many requests were sent to the Horizon server. | ||
* @see <a href="https://www.stellar.org/developers/horizon/learn/rate-limiting.html" target="_blank">Rate Limiting</a> | ||
*/ | ||
public class TooManyRequestsException extends RuntimeException { | ||
private int retryAfter; | ||
|
||
public TooManyRequestsException(int retryAfter) { | ||
super("The rate limit for the requesting IP address is over its alloted limit."); | ||
this.retryAfter = retryAfter; | ||
} | ||
|
||
/** | ||
* Returns number of seconds a client should wait before sending requests again. | ||
* @return | ||
*/ | ||
public int getRetryAfter() { | ||
return retryAfter; | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.stellar.sdk.responses; | ||
|
||
import org.apache.http.Header; | ||
|
||
public abstract class Response { | ||
protected int rateLimitLimit; | ||
protected int rateLimitRemaining; | ||
protected int rateLimitReset; | ||
|
||
public void setHeaders(Header limit, Header remaining, Header reset) { | ||
this.rateLimitLimit = Integer.parseInt(limit.getValue()); | ||
this.rateLimitRemaining = Integer.parseInt(remaining.getValue()); | ||
this.rateLimitReset = Integer.parseInt(reset.getValue()); | ||
} | ||
|
||
/** | ||
* Returns X-RateLimit-Limit header from the response. | ||
* This number represents the he maximum number of requests that the current client can | ||
* make in one hour. | ||
* @see <a href="https://www.stellar.org/developers/horizon/learn/rate-limiting.html" target="_blank">Rate Limiting</a> | ||
*/ | ||
public int getRateLimitLimit() { | ||
return rateLimitLimit; | ||
} | ||
|
||
/** | ||
* Returns X-RateLimit-Remaining header from the response. | ||
* The number of remaining requests for the current window. | ||
* @see <a href="https://www.stellar.org/developers/horizon/learn/rate-limiting.html" target="_blank">Rate Limiting</a> | ||
*/ | ||
public int getRateLimitRemaining() { | ||
return rateLimitRemaining; | ||
} | ||
|
||
/** | ||
* Returns X-RateLimit-Reset header from the response. Seconds until a new window starts. | ||
* @see <a href="https://www.stellar.org/developers/horizon/learn/rate-limiting.html" target="_blank">Rate Limiting</a> | ||
*/ | ||
public int getRateLimitReset() { | ||
return rateLimitReset; | ||
} | ||
} |
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
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